Skip to content

clippy does not fire warning for ok_or usage  #12517

Closed
@aliciawyy

Description

@aliciawyy

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: Clippy is not doing the correct thing

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions