about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--clippy_lints/src/methods/unnecessary_fallible_conversions.rs1
-rw-r--r--tests/ui/unnecessary_fallible_conversions.rs6
-rw-r--r--tests/ui/unnecessary_fallible_conversions.stderr22
3 files changed, 12 insertions, 17 deletions
diff --git a/clippy_lints/src/methods/unnecessary_fallible_conversions.rs b/clippy_lints/src/methods/unnecessary_fallible_conversions.rs
index b646c5953e4..53069391633 100644
--- a/clippy_lints/src/methods/unnecessary_fallible_conversions.rs
+++ b/clippy_lints/src/methods/unnecessary_fallible_conversions.rs
@@ -63,6 +63,7 @@ fn check<'tcx>(
             }
         });
 
+        // If there is an unwrap/expect call, extend the span to include the call
         let span = if let Some(unwrap_call) = parent_unwrap_call {
             primary_span.with_hi(unwrap_call.hi())
         } else {
diff --git a/tests/ui/unnecessary_fallible_conversions.rs b/tests/ui/unnecessary_fallible_conversions.rs
index f9df782c4e2..9e4fd3b3f90 100644
--- a/tests/ui/unnecessary_fallible_conversions.rs
+++ b/tests/ui/unnecessary_fallible_conversions.rs
@@ -10,10 +10,8 @@ fn main() {
     let _: i64 = i32::try_into(0).unwrap();
     let _: i64 = i32::try_into(0i32).expect("can't happen");
 
-    let _ = <i64 as TryFrom<i32>>::try_from(0)
-        .unwrap();
-    let _ = <i64 as TryFrom<i32>>::try_from(0).
-        expect("can't happen");
+    let _ = <i64 as TryFrom<i32>>::try_from(0).unwrap();
+    let _ = <i64 as TryFrom<i32>>::try_from(0).expect("can't happen");
 
     let _: i64 = <i32 as TryInto<_>>::try_into(0).unwrap();
     let _: i64 = <i32 as TryInto<_>>::try_into(0).expect("can't happen");
diff --git a/tests/ui/unnecessary_fallible_conversions.stderr b/tests/ui/unnecessary_fallible_conversions.stderr
index 603c079bc0e..c16dd239a8b 100644
--- a/tests/ui/unnecessary_fallible_conversions.stderr
+++ b/tests/ui/unnecessary_fallible_conversions.stderr
@@ -81,35 +81,31 @@ 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
    |
-LL |       let _ = <i64 as TryFrom<i32>>::try_from(0)
-   |  _____________^
-LL | |         .unwrap();
-   | |_________________^
+LL |     let _ = <i64 as TryFrom<i32>>::try_from(0).unwrap();
+   |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |
    = note: converting `i32` to `i64` cannot fail
 help: use
    |
-LL -     let _ = <i64 as TryFrom<i32>>::try_from(0)
+LL -     let _ = <i64 as TryFrom<i32>>::try_from(0).unwrap();
 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:15:13
+  --> $DIR/unnecessary_fallible_conversions.rs:14:13
    |
-LL |       let _ = <i64 as TryFrom<i32>>::try_from(0).
-   |  _____________^
-LL | |         expect("can't happen");
-   | |______________________________^
+LL |     let _ = <i64 as TryFrom<i32>>::try_from(0).expect("can't happen");
+   |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |
    = note: converting `i32` to `i64` cannot fail
 help: use
    |
-LL -     let _ = <i64 as TryFrom<i32>>::try_from(0).
+LL -     let _ = <i64 as TryFrom<i32>>::try_from(0).expect("can't happen");
 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:18:18
+  --> $DIR/unnecessary_fallible_conversions.rs:16:18
    |
 LL |     let _: i64 = <i32 as TryInto<_>>::try_into(0).unwrap();
    |                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -122,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:19:18
+  --> $DIR/unnecessary_fallible_conversions.rs:17:18
    |
 LL |     let _: i64 = <i32 as TryInto<_>>::try_into(0).expect("can't happen");
    |                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^