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

new lint: infallible TryFrom #13576

Open
andrewbanchich opened this issue Oct 21, 2024 · 0 comments
Open

new lint: infallible TryFrom #13576

andrewbanchich opened this issue Oct 21, 2024 · 0 comments
Labels
A-lint Area: New lints

Comments

@andrewbanchich
Copy link
Contributor

What it does

look for

impl TryFrom<TypeA> for TypeB {
  type Error = Infallible;

this is already a blanket implementation for impl From<TypeA> for TypeB, so it would be better to just implement From.

Advantage

  • From is simpler and more obvious that it's infallible
  • can be used in code which requires From impl

Drawbacks

No response

Example

impl TryFrom<TypeA> for TypeB {
  type Error = Infallible;

  fn try_from(value: TypeA) -> Result<Self, Self::Error> {
    ...
  }
}

Could be written as:

impl From<TypeA> for TypeB {
  fn from(value: bool) -> Self {
    ...
  }
}
@andrewbanchich andrewbanchich added the A-lint Area: New lints label Oct 21, 2024
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

No branches or pull requests

1 participant