rust-clippy
rust-clippy copied to clipboard
`io::Error::new(io::ErrorKind::Other, ..)`
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).