rust-lang / rust-clippy

A bunch of lints to catch common mistakes and improve your Rust code. Book: https://doc.rust-lang.org/clippy/
https://rust-lang.github.io/rust-clippy/
Other
10.89k stars 1.45k forks source link

`io::Error::new(io::ErrorKind::Other, ..)` #12717

Open JarredAllen opened 2 weeks ago

JarredAllen commented 2 weeks ago

What it does

Lint on code calling io::Error::new with io::ErrorKind::Other as the kind argument, because you can replace it with a call to io::Error::other.

Advantage

More concise

Drawbacks

Adding this lint would require people to change their code, adding work (though this should be machine-applicable) and adding diff churn to repository histories.

Example

fn f() -> std::io::Result<()> {
    fallible_function().map_err(|e| std::io::Error::new(std::io::ErrorKind::Other, e))?;
    Ok(())
}

Could be written as:

fn f() -> std::io::Result<()> {
    fallible_function().map_err(|e| std::io::Error::other(e))?;
    Ok(())
}

(which then gets another lint to also cut out the closure, so the code is even simpler).