rust-clippy icon indicating copy to clipboard operation
rust-clippy copied to clipboard

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

Open JarredAllen opened this issue 9 months ago • 0 comments

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).

JarredAllen avatar Apr 25 '24 23:04 JarredAllen