Skip to content

Commit 1cce757

Browse files
committed
Add error-annotations in tests for unnecessary_fallible_conversions
1 parent 094ce3d commit 1cce757

File tree

3 files changed

+60
-10
lines changed

3 files changed

+60
-10
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,43 @@
11
#![warn(clippy::unnecessary_fallible_conversions)]
22

33
fn main() {
4+
// --- TryFromMethod `T::try_from(u)` ---
5+
46
let _: i64 = 0i32.into();
7+
//~^ ERROR: use of a fallible conversion when an infallible one could be used
8+
59
let _: i64 = 0i32.into();
10+
//~^ ERROR: use of a fallible conversion when an infallible one could be used
11+
12+
// --- TryFromFunction `T::try_from(U)` ---
613

714
let _ = i64::from(0i32);
15+
//~^ ERROR: use of a fallible conversion when an infallible one could be used
16+
817
let _ = i64::from(0i32);
18+
//~^ ERROR: use of a fallible conversion when an infallible one could be used
19+
20+
// --- TryIntoFunction `U::try_into(t)` ---
921

1022
let _: i64 = i32::into(0);
23+
//~^ ERROR: use of a fallible conversion when an infallible one could be used
24+
1125
let _: i64 = i32::into(0i32);
26+
//~^ ERROR: use of a fallible conversion when an infallible one could be used
27+
28+
// --- TryFromFunction `<T as TryFrom<U>>::try_from(U)` ---
1229

1330
let _ = <i64 as From<i32>>::from(0);
31+
//~^ ERROR: use of a fallible conversion when an infallible one could be used
32+
1433
let _ = <i64 as From<i32>>::from(0);
34+
//~^ ERROR: use of a fallible conversion when an infallible one could be used
35+
36+
// --- TryIntoFunction `<U as TryInto<_>>::try_into(U)` ---
1537

1638
let _: i64 = <i32 as Into<_>>::into(0);
39+
//~^ ERROR: use of a fallible conversion when an infallible one could be used
40+
1741
let _: i64 = <i32 as Into<_>>::into(0);
42+
//~^ ERROR: use of a fallible conversion when an infallible one could be used
1843
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,43 @@
11
#![warn(clippy::unnecessary_fallible_conversions)]
22

33
fn main() {
4+
// --- TryFromMethod `T::try_from(u)` ---
5+
46
let _: i64 = 0i32.try_into().unwrap();
7+
//~^ ERROR: use of a fallible conversion when an infallible one could be used
8+
59
let _: i64 = 0i32.try_into().expect("can't happen");
10+
//~^ ERROR: use of a fallible conversion when an infallible one could be used
11+
12+
// --- TryFromFunction `T::try_from(U)` ---
613

714
let _ = i64::try_from(0i32).unwrap();
15+
//~^ ERROR: use of a fallible conversion when an infallible one could be used
16+
817
let _ = i64::try_from(0i32).expect("can't happen");
18+
//~^ ERROR: use of a fallible conversion when an infallible one could be used
19+
20+
// --- TryIntoFunction `U::try_into(t)` ---
921

1022
let _: i64 = i32::try_into(0).unwrap();
23+
//~^ ERROR: use of a fallible conversion when an infallible one could be used
24+
1125
let _: i64 = i32::try_into(0i32).expect("can't happen");
26+
//~^ ERROR: use of a fallible conversion when an infallible one could be used
27+
28+
// --- TryFromFunction `<T as TryFrom<U>>::try_from(U)` ---
1229

1330
let _ = <i64 as TryFrom<i32>>::try_from(0).unwrap();
31+
//~^ ERROR: use of a fallible conversion when an infallible one could be used
32+
1433
let _ = <i64 as TryFrom<i32>>::try_from(0).expect("can't happen");
34+
//~^ ERROR: use of a fallible conversion when an infallible one could be used
35+
36+
// --- TryIntoFunction `<U as TryInto<_>>::try_into(U)` ---
1537

1638
let _: i64 = <i32 as TryInto<_>>::try_into(0).unwrap();
39+
//~^ ERROR: use of a fallible conversion when an infallible one could be used
40+
1741
let _: i64 = <i32 as TryInto<_>>::try_into(0).expect("can't happen");
42+
//~^ ERROR: use of a fallible conversion when an infallible one could be used
1843
}

tests/ui/unnecessary_fallible_conversions.stderr

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: use of a fallible conversion when an infallible one could be used
2-
--> $DIR/unnecessary_fallible_conversions.rs:4:23
2+
--> $DIR/unnecessary_fallible_conversions.rs:6:23
33
|
44
LL | let _: i64 = 0i32.try_into().unwrap();
55
| ^^^^^^^^^^^^^^^^^^^
@@ -14,7 +14,7 @@ LL + let _: i64 = 0i32.into();
1414
|
1515

1616
error: use of a fallible conversion when an infallible one could be used
17-
--> $DIR/unnecessary_fallible_conversions.rs:5:23
17+
--> $DIR/unnecessary_fallible_conversions.rs:9:23
1818
|
1919
LL | let _: i64 = 0i32.try_into().expect("can't happen");
2020
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -27,7 +27,7 @@ LL + let _: i64 = 0i32.into();
2727
|
2828

2929
error: use of a fallible conversion when an infallible one could be used
30-
--> $DIR/unnecessary_fallible_conversions.rs:7:13
30+
--> $DIR/unnecessary_fallible_conversions.rs:14:13
3131
|
3232
LL | let _ = i64::try_from(0i32).unwrap();
3333
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -40,7 +40,7 @@ LL + let _ = i64::from(0i32);
4040
|
4141

4242
error: use of a fallible conversion when an infallible one could be used
43-
--> $DIR/unnecessary_fallible_conversions.rs:8:13
43+
--> $DIR/unnecessary_fallible_conversions.rs:17:13
4444
|
4545
LL | let _ = i64::try_from(0i32).expect("can't happen");
4646
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -53,7 +53,7 @@ LL + let _ = i64::from(0i32);
5353
|
5454

5555
error: use of a fallible conversion when an infallible one could be used
56-
--> $DIR/unnecessary_fallible_conversions.rs:10:18
56+
--> $DIR/unnecessary_fallible_conversions.rs:22:18
5757
|
5858
LL | let _: i64 = i32::try_into(0).unwrap();
5959
| ^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -66,7 +66,7 @@ LL + let _: i64 = i32::into(0);
6666
|
6767

6868
error: use of a fallible conversion when an infallible one could be used
69-
--> $DIR/unnecessary_fallible_conversions.rs:11:18
69+
--> $DIR/unnecessary_fallible_conversions.rs:25:18
7070
|
7171
LL | let _: i64 = i32::try_into(0i32).expect("can't happen");
7272
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -79,7 +79,7 @@ LL + let _: i64 = i32::into(0i32);
7979
|
8080

8181
error: use of a fallible conversion when an infallible one could be used
82-
--> $DIR/unnecessary_fallible_conversions.rs:13:13
82+
--> $DIR/unnecessary_fallible_conversions.rs:30:13
8383
|
8484
LL | let _ = <i64 as TryFrom<i32>>::try_from(0).unwrap();
8585
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -92,7 +92,7 @@ LL + let _ = <i64 as From<i32>>::from(0);
9292
|
9393

9494
error: use of a fallible conversion when an infallible one could be used
95-
--> $DIR/unnecessary_fallible_conversions.rs:14:13
95+
--> $DIR/unnecessary_fallible_conversions.rs:33:13
9696
|
9797
LL | let _ = <i64 as TryFrom<i32>>::try_from(0).expect("can't happen");
9898
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -105,7 +105,7 @@ LL + let _ = <i64 as From<i32>>::from(0);
105105
|
106106

107107
error: use of a fallible conversion when an infallible one could be used
108-
--> $DIR/unnecessary_fallible_conversions.rs:16:18
108+
--> $DIR/unnecessary_fallible_conversions.rs:38:18
109109
|
110110
LL | let _: i64 = <i32 as TryInto<_>>::try_into(0).unwrap();
111111
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -118,7 +118,7 @@ LL + let _: i64 = <i32 as Into<_>>::into(0);
118118
|
119119

120120
error: use of a fallible conversion when an infallible one could be used
121-
--> $DIR/unnecessary_fallible_conversions.rs:17:18
121+
--> $DIR/unnecessary_fallible_conversions.rs:41:18
122122
|
123123
LL | let _: i64 = <i32 as TryInto<_>>::try_into(0).expect("can't happen");
124124
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

0 commit comments

Comments
 (0)