Skip to content

clippy does not fire warning for ok_or usage #12517

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
aliciawyy opened this issue Mar 21, 2024 · 2 comments
Closed

clippy does not fire warning for ok_or usage #12517

aliciawyy opened this issue Mar 21, 2024 · 2 comments
Labels
C-bug Category: Clippy is not doing the correct thing

Comments

@aliciawyy
Copy link

Summary

When running the provided code in the Rust Playground, the expectation was for Clippy to produce a warning related to the usage of ok_or in accordance with the or_fun_call lint. However, Clippy did not generate any warning, contrary to the expected behavior.

Reproducer

I tried this code:

fn foo() -> String {
    println!("Called foo");
    "foo".to_string()
}

fn bar(x: bool) -> Option<i32> {
    if x {
        Some(1)
    } else {
        None
    }
}

fn main() {
  let v = bar(true).ok_or(foo());
  println!("v {:?}", v)
}

Playground demo: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=1cc70f21798932cb2cae892524e8cb20

I expected to see this happen:
I expect clippy to fire a warning for the ok_or usage as per or_fun_call.

Instead, this happened:
Clippy doesn't fire any warning

Version

No response

Additional Labels

No response

@aliciawyy aliciawyy added the C-bug Category: Clippy is not doing the correct thing label Mar 21, 2024
@y21
Copy link
Member

y21 commented Mar 24, 2024

The lint is in the nursery category since #9829, so it is allow-by-default and needs to be opted into.

If you put #![warn(clippy::or_fun_call)] at the crate root, then you'll see the warning that you are expecting.

@aliciawyy
Copy link
Author

I see. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: Clippy is not doing the correct thing
Projects
None yet
Development

No branches or pull requests

2 participants