Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
JarredAllen opened this issue Apr 25, 2024 · 1 comment · May be fixed by #14022
Open

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

JarredAllen opened this issue Apr 25, 2024 · 1 comment · May be fixed by #14022
Assignees
Labels
A-lint Area: New lints

Comments

@JarredAllen
Copy link
Contributor

JarredAllen commented Apr 25, 2024

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 JarredAllen added the A-lint Area: New lints label Apr 25, 2024
@llogiq
Copy link
Contributor

llogiq commented Jan 18, 2025

@rustbot claim

@llogiq llogiq linked a pull request Jan 18, 2025 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lint Area: New lints
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants