From a3d7698fd95977df3cdd551bc0f078aabcae20f9 Mon Sep 17 00:00:00 2001 From: Michael Wright Date: Tue, 7 Aug 2018 05:37:11 +0200 Subject: [PATCH] Fix #2971 --- clippy_lints/src/identity_conversion.rs | 2 +- tests/ui/identity_conversion.rs | 1 + tests/ui/identity_conversion.stderr | 14 ++++++++++---- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/clippy_lints/src/identity_conversion.rs b/clippy_lints/src/identity_conversion.rs index cf05583d85e..1909f2f8ff4 100644 --- a/clippy_lints/src/identity_conversion.rs +++ b/clippy_lints/src/identity_conversion.rs @@ -85,7 +85,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for IdentityConversion { let a = cx.tables.expr_ty(e); let b = cx.tables.expr_ty(&args[0]); if same_tys(cx, a, b) { - let sugg = snippet(cx, args[0].span, "").into_owned(); + let sugg = snippet(cx, args[0].span.source_callsite(), "").into_owned(); let sugg_msg = format!("consider removing `{}()`", snippet(cx, path.span, "From::from")); span_lint_and_then(cx, IDENTITY_CONVERSION, e.span, "identical conversion", |db| { db.span_suggestion(e.span, &sugg_msg, sugg); diff --git a/tests/ui/identity_conversion.rs b/tests/ui/identity_conversion.rs index 9ab81f1b1cb..8f5bd12bc9f 100644 --- a/tests/ui/identity_conversion.rs +++ b/tests/ui/identity_conversion.rs @@ -38,6 +38,7 @@ fn main() { let _: String = "foo".to_string().into(); let _: String = From::from("foo".to_string()); let _ = String::from("foo".to_string()); + let _ = String::from(format!("A: {:04}", 123)); let _ = "".lines().into_iter(); let _ = vec![1, 2, 3].into_iter().into_iter(); } diff --git a/tests/ui/identity_conversion.stderr b/tests/ui/identity_conversion.stderr index f7993d69c50..7083b96e16f 100644 --- a/tests/ui/identity_conversion.stderr +++ b/tests/ui/identity_conversion.stderr @@ -43,14 +43,20 @@ error: identical conversion error: identical conversion --> $DIR/identity_conversion.rs:41:13 | -41 | let _ = "".lines().into_iter(); - | ^^^^^^^^^^^^^^^^^^^^^^ help: consider removing `.into_iter()`: `"".lines()` +41 | let _ = String::from(format!("A: {:04}", 123)); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider removing `String::from()`: `format!("A: {:04}", 123)` error: identical conversion --> $DIR/identity_conversion.rs:42:13 | -42 | let _ = vec![1, 2, 3].into_iter().into_iter(); +42 | let _ = "".lines().into_iter(); + | ^^^^^^^^^^^^^^^^^^^^^^ help: consider removing `.into_iter()`: `"".lines()` + +error: identical conversion + --> $DIR/identity_conversion.rs:43:13 + | +43 | let _ = vec![1, 2, 3].into_iter().into_iter(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider removing `.into_iter()`: `vec![1, 2, 3].into_iter()` -error: aborting due to 8 previous errors +error: aborting due to 9 previous errors