Merge pull request #3010 from mikerite/issue2971

Fix #2971
This commit is contained in:
Oliver Schneider 2018-08-07 13:10:26 +02:00 committed by GitHub
commit dc5ee5aa19
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 5 deletions

View File

@ -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, "<expr>").into_owned();
let sugg = snippet(cx, args[0].span.source_callsite(), "<expr>").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);

View File

@ -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();
}

View File

@ -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