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

unnecessary_fallible_conversions should be fixable with cargo fix #12034

Closed
jyn514 opened this issue Dec 28, 2023 · 2 comments · Fixed by #12070
Closed

unnecessary_fallible_conversions should be fixable with cargo fix #12034

jyn514 opened this issue Dec 28, 2023 · 2 comments · Fixed by #12070
Assignees
Labels
C-enhancement Category: Enhancement of lints, like adding more cases or adding help messages good-first-issue These issues are a good way to get started with Clippy

Comments

@jyn514
Copy link
Member

jyn514 commented Dec 28, 2023

Description

The warnings generated by unnecessary_fallible_conversions are trivial to fix; they even have a suggestion already. it would be nice for it to be machine applicable.

error: use of a fallible conversion when an infallible one could be used
   --> src/main.rs:651:30
    |
651 |             Some(val) => u64::try_from(val).expect("Failed to convert val into u64"),
    |                               ^^^^^^^^^^^^^ help: use: `From::from`

Version

clippy 0.1.75 (82e1608d 2023-12-21)
rustc 1.75.0 (82e1608df 2023-12-21)
binary: rustc
commit-hash: 82e1608dfa6e0b5569232559e3d385fea5a93112
commit-date: 2023-12-21
host: aarch64-apple-darwin
release: 1.75.0
LLVM version: 17.0.6

Additional Labels

No response

@m-rph
Copy link
Contributor

m-rph commented Dec 29, 2023

@rustbot label +good-first-issue

@rustbot rustbot added good-first-issue These issues are a good way to get started with Clippy C-enhancement Category: Enhancement of lints, like adding more cases or adding help messages labels Dec 29, 2023
@roife
Copy link
Contributor

roife commented Jan 1, 2024

@rustbot claim

bors added a commit that referenced this issue Feb 9, 2024
Fix issue #12034: add autofixes for unnecessary_fallible_conversions

fixes #12034

Currently, the `unnecessary_fallible_conversions` lint was capable of autofixing expressions like `0i32.try_into().unwrap()`. However, it couldn't autofix expressions in the form of `i64::try_from(0i32).unwrap()` or `<i64 as TryFrom<i32>>::try_from(0).unwrap()`.

This pull request extends the functionality to correctly autofix these latter forms as well.

changelog: [`unnecessary_fallible_conversions`]: Add autofixes for more forms
@bors bors closed this as completed in 28443e6 Feb 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-enhancement Category: Enhancement of lints, like adding more cases or adding help messages good-first-issue These issues are a good way to get started with Clippy
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants