forked from rust-lang/rust
-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of rust-lang#12070 - roife:fix/issue-12034, r=Centri3
Fix issue rust-lang#12034: add autofixes for unnecessary_fallible_conversions fixes rust-lang#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
- Loading branch information
Showing
4 changed files
with
293 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,43 @@ | ||
#![warn(clippy::unnecessary_fallible_conversions)] | ||
|
||
fn main() { | ||
// --- TryFromMethod `T::try_from(u)` --- | ||
|
||
let _: i64 = 0i32.into(); | ||
//~^ ERROR: use of a fallible conversion when an infallible one could be used | ||
|
||
let _: i64 = 0i32.into(); | ||
//~^ ERROR: use of a fallible conversion when an infallible one could be used | ||
|
||
// --- TryFromFunction `T::try_from(U)` --- | ||
|
||
let _ = i64::from(0i32); | ||
//~^ ERROR: use of a fallible conversion when an infallible one could be used | ||
|
||
let _ = i64::from(0i32); | ||
//~^ ERROR: use of a fallible conversion when an infallible one could be used | ||
|
||
// --- TryIntoFunction `U::try_into(t)` --- | ||
|
||
let _: i64 = i32::into(0); | ||
//~^ ERROR: use of a fallible conversion when an infallible one could be used | ||
|
||
let _: i64 = i32::into(0i32); | ||
//~^ ERROR: use of a fallible conversion when an infallible one could be used | ||
|
||
// --- TryFromFunction `<T as TryFrom<U>>::try_from(U)` --- | ||
|
||
let _ = <i64 as From<i32>>::from(0); | ||
//~^ ERROR: use of a fallible conversion when an infallible one could be used | ||
|
||
let _ = <i64 as From<i32>>::from(0); | ||
//~^ ERROR: use of a fallible conversion when an infallible one could be used | ||
|
||
// --- TryIntoFunction `<U as TryInto<_>>::try_into(U)` --- | ||
|
||
let _: i64 = <i32 as Into<_>>::into(0); | ||
//~^ ERROR: use of a fallible conversion when an infallible one could be used | ||
|
||
let _: i64 = <i32 as Into<_>>::into(0); | ||
//~^ ERROR: use of a fallible conversion when an infallible one could be used | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,43 @@ | ||
#![warn(clippy::unnecessary_fallible_conversions)] | ||
|
||
fn main() { | ||
// --- TryFromMethod `T::try_from(u)` --- | ||
|
||
let _: i64 = 0i32.try_into().unwrap(); | ||
//~^ ERROR: use of a fallible conversion when an infallible one could be used | ||
|
||
let _: i64 = 0i32.try_into().expect("can't happen"); | ||
//~^ ERROR: use of a fallible conversion when an infallible one could be used | ||
|
||
// --- TryFromFunction `T::try_from(U)` --- | ||
|
||
let _ = i64::try_from(0i32).unwrap(); | ||
//~^ ERROR: use of a fallible conversion when an infallible one could be used | ||
|
||
let _ = i64::try_from(0i32).expect("can't happen"); | ||
//~^ ERROR: use of a fallible conversion when an infallible one could be used | ||
|
||
// --- TryIntoFunction `U::try_into(t)` --- | ||
|
||
let _: i64 = i32::try_into(0).unwrap(); | ||
//~^ ERROR: use of a fallible conversion when an infallible one could be used | ||
|
||
let _: i64 = i32::try_into(0i32).expect("can't happen"); | ||
//~^ ERROR: use of a fallible conversion when an infallible one could be used | ||
|
||
// --- TryFromFunction `<T as TryFrom<U>>::try_from(U)` --- | ||
|
||
let _ = <i64 as TryFrom<i32>>::try_from(0).unwrap(); | ||
//~^ ERROR: use of a fallible conversion when an infallible one could be used | ||
|
||
let _ = <i64 as TryFrom<i32>>::try_from(0).expect("can't happen"); | ||
//~^ ERROR: use of a fallible conversion when an infallible one could be used | ||
|
||
// --- TryIntoFunction `<U as TryInto<_>>::try_into(U)` --- | ||
|
||
let _: i64 = <i32 as TryInto<_>>::try_into(0).unwrap(); | ||
//~^ ERROR: use of a fallible conversion when an infallible one could be used | ||
|
||
let _: i64 = <i32 as TryInto<_>>::try_into(0).expect("can't happen"); | ||
//~^ ERROR: use of a fallible conversion when an infallible one could be used | ||
} |
Oops, something went wrong.