Skip to content

False Positive on or_fun_call lint with enum constructor. #1338

Closed
@CryZe

Description

@CryZe

or_fn_call shouldn't warn in case the function is just an enum constructor wrapping over local variables.

Here's the code:

pub enum Error<'a> {
    Path(&'a str),
}

pub fn question_mark(path: &str) -> Result<(), Error> {
    None.ok_or(Error::Path(path))?;
    
    Ok(())
}

pub fn try(path: &str) -> Result<(), Error> {
    try!(None.ok_or(Error::Path(path)));
    
    Ok(())
}

Warning:

Compiling playground v0.0.1 (file:///playground)
warning: use of `ok_or` followed by a function call, #[warn(or_fun_call)] on by default
 --> src/main.rs:6:5
  |
6 |     None.ok_or(Error::Path(path))?;
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
help: try this
  |     None.ok_or_else(|| Error::Path(path))?;
  = help: for further information visit https://github.com/Manishearth/rust-clippy/wiki#or_fun_call

Here's the link to the code in the custom playground: Playground

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: Clippy is not doing the correct thingE-mediumCall for participation: Medium difficulty level problem and requires some initial experience.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions