diff --git a/clippy_lints/src/identity_conversion.rs b/clippy_lints/src/identity_conversion.rs index cf05583d8..1909f2f8f 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 9ab81f1b1..8f5bd12bc 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 f7993d69c..7083b96e1 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