diff options
| author | roife <roifewu@gmail.com> | 2024-01-02 01:23:44 +0800 |
|---|---|---|
| committer | roife <roifewu@gmail.com> | 2024-01-02 01:29:20 +0800 |
| commit | 1cce757672d9a7ec5fd19628fa4e5f00b31c8f8a (patch) | |
| tree | 9ea597d84aae5e34e8064309b14e5fbfe488a5de | |
| parent | 094ce3de3ee98842c9a2ffc74934959973da5d1b (diff) | |
| download | rust-1cce757672d9a7ec5fd19628fa4e5f00b31c8f8a.tar.gz rust-1cce757672d9a7ec5fd19628fa4e5f00b31c8f8a.zip | |
Add error-annotations in tests for unnecessary_fallible_conversions
| -rw-r--r-- | tests/ui/unnecessary_fallible_conversions.fixed | 25 | ||||
| -rw-r--r-- | tests/ui/unnecessary_fallible_conversions.rs | 25 | ||||
| -rw-r--r-- | tests/ui/unnecessary_fallible_conversions.stderr | 20 |
3 files changed, 60 insertions, 10 deletions
diff --git a/tests/ui/unnecessary_fallible_conversions.fixed b/tests/ui/unnecessary_fallible_conversions.fixed index f6027fbfa6a..b6dd1f26774 100644 --- a/tests/ui/unnecessary_fallible_conversions.fixed +++ b/tests/ui/unnecessary_fallible_conversions.fixed @@ -1,18 +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 } diff --git a/tests/ui/unnecessary_fallible_conversions.rs b/tests/ui/unnecessary_fallible_conversions.rs index 9e4fd3b3f90..6f8df7365e8 100644 --- a/tests/ui/unnecessary_fallible_conversions.rs +++ b/tests/ui/unnecessary_fallible_conversions.rs @@ -1,18 +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 } diff --git a/tests/ui/unnecessary_fallible_conversions.stderr b/tests/ui/unnecessary_fallible_conversions.stderr index c16dd239a8b..598f4ba91b3 100644 --- a/tests/ui/unnecessary_fallible_conversions.stderr +++ b/tests/ui/unnecessary_fallible_conversions.stderr @@ -1,5 +1,5 @@ error: use of a fallible conversion when an infallible one could be used - --> $DIR/unnecessary_fallible_conversions.rs:4:23 + --> $DIR/unnecessary_fallible_conversions.rs:6:23 | LL | let _: i64 = 0i32.try_into().unwrap(); | ^^^^^^^^^^^^^^^^^^^ @@ -14,7 +14,7 @@ LL + let _: i64 = 0i32.into(); | error: use of a fallible conversion when an infallible one could be used - --> $DIR/unnecessary_fallible_conversions.rs:5:23 + --> $DIR/unnecessary_fallible_conversions.rs:9:23 | LL | let _: i64 = 0i32.try_into().expect("can't happen"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -27,7 +27,7 @@ LL + let _: i64 = 0i32.into(); | error: use of a fallible conversion when an infallible one could be used - --> $DIR/unnecessary_fallible_conversions.rs:7:13 + --> $DIR/unnecessary_fallible_conversions.rs:14:13 | LL | let _ = i64::try_from(0i32).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -40,7 +40,7 @@ LL + let _ = i64::from(0i32); | error: use of a fallible conversion when an infallible one could be used - --> $DIR/unnecessary_fallible_conversions.rs:8:13 + --> $DIR/unnecessary_fallible_conversions.rs:17:13 | LL | let _ = i64::try_from(0i32).expect("can't happen"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -53,7 +53,7 @@ LL + let _ = i64::from(0i32); | error: use of a fallible conversion when an infallible one could be used - --> $DIR/unnecessary_fallible_conversions.rs:10:18 + --> $DIR/unnecessary_fallible_conversions.rs:22:18 | LL | let _: i64 = i32::try_into(0).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -66,7 +66,7 @@ LL + let _: i64 = i32::into(0); | error: use of a fallible conversion when an infallible one could be used - --> $DIR/unnecessary_fallible_conversions.rs:11:18 + --> $DIR/unnecessary_fallible_conversions.rs:25:18 | LL | let _: i64 = i32::try_into(0i32).expect("can't happen"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -79,7 +79,7 @@ LL + let _: i64 = i32::into(0i32); | error: use of a fallible conversion when an infallible one could be used - --> $DIR/unnecessary_fallible_conversions.rs:13:13 + --> $DIR/unnecessary_fallible_conversions.rs:30:13 | LL | let _ = <i64 as TryFrom<i32>>::try_from(0).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -92,7 +92,7 @@ LL + let _ = <i64 as From<i32>>::from(0); | error: use of a fallible conversion when an infallible one could be used - --> $DIR/unnecessary_fallible_conversions.rs:14:13 + --> $DIR/unnecessary_fallible_conversions.rs:33:13 | LL | let _ = <i64 as TryFrom<i32>>::try_from(0).expect("can't happen"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -105,7 +105,7 @@ LL + let _ = <i64 as From<i32>>::from(0); | error: use of a fallible conversion when an infallible one could be used - --> $DIR/unnecessary_fallible_conversions.rs:16:18 + --> $DIR/unnecessary_fallible_conversions.rs:38:18 | LL | let _: i64 = <i32 as TryInto<_>>::try_into(0).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -118,7 +118,7 @@ LL + let _: i64 = <i32 as Into<_>>::into(0); | error: use of a fallible conversion when an infallible one could be used - --> $DIR/unnecessary_fallible_conversions.rs:17:18 + --> $DIR/unnecessary_fallible_conversions.rs:41:18 | LL | let _: i64 = <i32 as TryInto<_>>::try_into(0).expect("can't happen"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
