Skip to content

Commit 094ce3d

Browse files
committed
Add comments for unnecessary_fallible_conversions
1 parent 69cc983 commit 094ce3d

File tree

3 files changed

+12
-17
lines changed

3 files changed

+12
-17
lines changed

clippy_lints/src/methods/unnecessary_fallible_conversions.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ fn check<'tcx>(
6363
}
6464
});
6565

66+
// If there is an unwrap/expect call, extend the span to include the call
6667
let span = if let Some(unwrap_call) = parent_unwrap_call {
6768
primary_span.with_hi(unwrap_call.hi())
6869
} else {

tests/ui/unnecessary_fallible_conversions.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,8 @@ fn main() {
1010
let _: i64 = i32::try_into(0).unwrap();
1111
let _: i64 = i32::try_into(0i32).expect("can't happen");
1212

13-
let _ = <i64 as TryFrom<i32>>::try_from(0)
14-
.unwrap();
15-
let _ = <i64 as TryFrom<i32>>::try_from(0).
16-
expect("can't happen");
13+
let _ = <i64 as TryFrom<i32>>::try_from(0).unwrap();
14+
let _ = <i64 as TryFrom<i32>>::try_from(0).expect("can't happen");
1715

1816
let _: i64 = <i32 as TryInto<_>>::try_into(0).unwrap();
1917
let _: i64 = <i32 as TryInto<_>>::try_into(0).expect("can't happen");

tests/ui/unnecessary_fallible_conversions.stderr

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -81,35 +81,31 @@ LL + let _: i64 = i32::into(0i32);
8181
error: use of a fallible conversion when an infallible one could be used
8282
--> $DIR/unnecessary_fallible_conversions.rs:13:13
8383
|
84-
LL | let _ = <i64 as TryFrom<i32>>::try_from(0)
85-
| _____________^
86-
LL | | .unwrap();
87-
| |_________________^
84+
LL | let _ = <i64 as TryFrom<i32>>::try_from(0).unwrap();
85+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8886
|
8987
= note: converting `i32` to `i64` cannot fail
9088
help: use
9189
|
92-
LL - let _ = <i64 as TryFrom<i32>>::try_from(0)
90+
LL - let _ = <i64 as TryFrom<i32>>::try_from(0).unwrap();
9391
LL + let _ = <i64 as From<i32>>::from(0);
9492
|
9593

9694
error: use of a fallible conversion when an infallible one could be used
97-
--> $DIR/unnecessary_fallible_conversions.rs:15:13
95+
--> $DIR/unnecessary_fallible_conversions.rs:14:13
9896
|
99-
LL | let _ = <i64 as TryFrom<i32>>::try_from(0).
100-
| _____________^
101-
LL | | expect("can't happen");
102-
| |______________________________^
97+
LL | let _ = <i64 as TryFrom<i32>>::try_from(0).expect("can't happen");
98+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
10399
|
104100
= note: converting `i32` to `i64` cannot fail
105101
help: use
106102
|
107-
LL - let _ = <i64 as TryFrom<i32>>::try_from(0).
103+
LL - let _ = <i64 as TryFrom<i32>>::try_from(0).expect("can't happen");
108104
LL + let _ = <i64 as From<i32>>::from(0);
109105
|
110106

111107
error: use of a fallible conversion when an infallible one could be used
112-
--> $DIR/unnecessary_fallible_conversions.rs:18:18
108+
--> $DIR/unnecessary_fallible_conversions.rs:16:18
113109
|
114110
LL | let _: i64 = <i32 as TryInto<_>>::try_into(0).unwrap();
115111
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -122,7 +118,7 @@ LL + let _: i64 = <i32 as Into<_>>::into(0);
122118
|
123119

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

0 commit comments

Comments
 (0)