Skip to content

Lint simplifyable ok_or_else usage #4676

Open
@oli-cosmian

Description

@oli-cosmian

The following code uses String::from

fn bar() -> Result<i32, String> {
    let x = Some(52.3).ok_or_else(|| String::from("foo"))?;
    Ok(42)
}

but Some(52.3).ok_or("foo")?; would also compile

So if an ok_or_else is followed by a ? and the inner function is calling From::from (or a specific version of it), we should be able to convert it to an ok_or without that call.

Metadata

Metadata

Assignees

Labels

A-lintArea: New lintsL-complexityLint: Belongs in the complexity lint groupL-suggestionLint: Improving, adding or fixing lint suggestions

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions