Skip to content

false positive of or_fun_call for enum #9663

@xxchan

Description

@xxchan

Summary

See Reproducer. Note that in my trials, this only happens when one variant is std::io::Error

Lint Name

or_fun_call

Reproducer

I tried this code:

pub enum E1 {
    A(usize),
    B(std::io::Error),
}

pub fn foo() -> Result<(), E1> {
    None.ok_or(E1::A(1))
}

I saw this happen:

no warning

I expected to see this happen:

warning: use of `ok_or` followed by a function call
  --> src/tmp1/src/main.rs:61:10
   |
61 |     None.ok_or(E1::A(1))
   |          ^^^^^^^^^^^^^^^ help: try this: `ok_or_else(|| E1::A(1))`
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#or_fun_call
   = note: `#[warn(clippy::or_fun_call)]` on by default

Version

rustc 1.66.0-nightly (b8c35ca26 2022-10-15)
binary: rustc
commit-hash: b8c35ca26b191bb9a9ac669a4b3f4d3d52d97fb1
commit-date: 2022-10-15
host: aarch64-apple-darwin
release: 1.66.0-nightly
LLVM version: 15.0.2

Additional Labels

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: Clippy is not doing the correct thingI-false-positiveIssue: The lint was triggered on code it shouldn't have

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions