diff --git a/src/shadow.rs b/src/shadow.rs index cf7de04cb..2a0d36a80 100644 --- a/src/shadow.rs +++ b/src/shadow.rs @@ -208,15 +208,16 @@ fn lint_shadow(cx: &LateContext, name: Name, span: Span, pattern_span: Span, let db = span_lint(cx, SHADOW_SAME, span, - &format!("{} is shadowed by itself in {}", + &format!("`{}` is shadowed by itself in `{}`", snippet(cx, pattern_span, "_"), snippet(cx, expr.span, ".."))); + note_orig(cx, db, SHADOW_SAME, prev_span); } else if contains_self(name, expr) { let db = span_note_and_lint(cx, SHADOW_REUSE, pattern_span, - &format!("{} is shadowed by {} which reuses the original value", + &format!("`{}` is shadowed by `{}` which reuses the original value", snippet(cx, pattern_span, "_"), snippet(cx, expr.span, "..")), expr.span, @@ -226,7 +227,7 @@ fn lint_shadow(cx: &LateContext, name: Name, span: Span, pattern_span: Span, let db = span_note_and_lint(cx, SHADOW_UNRELATED, pattern_span, - &format!("{} is shadowed by {}", + &format!("`{}` is shadowed by `{}`", snippet(cx, pattern_span, "_"), snippet(cx, expr.span, "..")), expr.span, diff --git a/tests/compile-fail/methods.rs b/tests/compile-fail/methods.rs index 9753c0213..f6e4a9a31 100644 --- a/tests/compile-fail/methods.rs +++ b/tests/compile-fail/methods.rs @@ -493,10 +493,8 @@ fn single_char_pattern() { fn temporary_cstring() { use std::ffi::CString; - ( // extra parenthesis to better test spans + CString::new("foo").unwrap().as_ptr(); //~^ ERROR you are getting the inner pointer of a temporary `CString` //~| NOTE that pointer will be invalid outside this expression - CString::new("foo").unwrap() - //~^ HELP assign the `CString` to a variable to extend its lifetime - ).as_ptr(); + //~| HELP assign the `CString` to a variable to extend its lifetime } diff --git a/tests/compile-fail/shadow.rs b/tests/compile-fail/shadow.rs index 0a52a9829..1cfcff74a 100644 --- a/tests/compile-fail/shadow.rs +++ b/tests/compile-fail/shadow.rs @@ -10,15 +10,15 @@ fn first(x: (isize, isize)) -> isize { x.0 } fn main() { let mut x = 1; - let x = &mut x; //~ERROR x is shadowed by itself in &mut x - let x = { x }; //~ERROR x is shadowed by itself in { x } - let x = (&*x); //~ERROR x is shadowed by itself in &*x - let x = { *x + 1 }; //~ERROR x is shadowed by { *x + 1 } which reuses - let x = id(x); //~ERROR x is shadowed by id(x) which reuses - let x = (1, x); //~ERROR x is shadowed by (1, x) which reuses - let x = first(x); //~ERROR x is shadowed by first(x) which reuses + let x = &mut x; //~ERROR `x` is shadowed by itself in `&mut x` + let x = { x }; //~ERROR `x` is shadowed by itself in `{ x }` + let x = (&*x); //~ERROR `x` is shadowed by itself in `(&*x)` + let x = { *x + 1 }; //~ERROR `x` is shadowed by `{ *x + 1 }` which reuses + let x = id(x); //~ERROR `x` is shadowed by `id(x)` which reuses + let x = (1, x); //~ERROR `x` is shadowed by `(1, x)` which reuses + let x = first(x); //~ERROR `x` is shadowed by `first(x)` which reuses let y = 1; - let x = y; //~ERROR x is shadowed by y + let x = y; //~ERROR `x` is shadowed by `y` let o = Some(1u8);