about summary refs log tree commit diff
diff options
context:
space:
mode:
authordswij <dswijj@gmail.com>2021-10-07 16:39:13 +0800
committerdswij <dswijj@gmail.com>2021-10-07 16:50:13 +0800
commit64f8b9d0eac0b3c25c74462bfbe5086feb4264e8 (patch)
tree73ce3249889b050901f55a6039199e3b6314cace
parent2a8d7bd0dd69ab1fe2a2af0f2984959f62b5631c (diff)
downloadrust-64f8b9d0eac0b3c25c74462bfbe5086feb4264e8.tar.gz
rust-64f8b9d0eac0b3c25c74462bfbe5086feb4264e8.zip
Make `shadow_reuse` suggestion less verbose
-rw-r--r--clippy_lints/src/shadow.rs6
-rw-r--r--tests/ui/shadow.rs5
-rw-r--r--tests/ui/shadow.stderr60
3 files changed, 42 insertions, 29 deletions
diff --git a/clippy_lints/src/shadow.rs b/clippy_lints/src/shadow.rs
index 2ca7c18800e..64841f33cc3 100644
--- a/clippy_lints/src/shadow.rs
+++ b/clippy_lints/src/shadow.rs
@@ -162,11 +162,7 @@ fn lint_shadow(cx: &LateContext<'_>, pat: &Pat<'_>, shadowed: HirId, span: Span)
             (SHADOW_SAME, msg)
         },
         Some(expr) if is_local_used(cx, expr, shadowed) => {
-            let msg = format!(
-                "`{}` is shadowed by `{}` which reuses the original value",
-                snippet(cx, pat.span, "_"),
-                snippet(cx, expr.span, "..")
-            );
+            let msg = format!("`{}` is shadowed", snippet(cx, pat.span, "_"));
             (SHADOW_REUSE, msg)
         },
         _ => {
diff --git a/tests/ui/shadow.rs b/tests/ui/shadow.rs
index 02e838456d0..55caef59f7f 100644
--- a/tests/ui/shadow.rs
+++ b/tests/ui/shadow.rs
@@ -17,6 +17,11 @@ fn shadow_reuse() -> Option<()> {
     let x = foo(x);
     let x = || x;
     let x = Some(1).map(|_| x)?;
+    let y = 1;
+    let y = match y {
+        1 => 2,
+        _ => 3,
+    };
     None
 }
 
diff --git a/tests/ui/shadow.stderr b/tests/ui/shadow.stderr
index 8b60e072c93..feed6e1ba8b 100644
--- a/tests/ui/shadow.stderr
+++ b/tests/ui/shadow.stderr
@@ -47,7 +47,7 @@ note: previous binding is here
 LL |     let x = &mut x;
    |         ^
 
-error: `x` is shadowed by `x.0` which reuses the original value
+error: `x` is shadowed
   --> $DIR/shadow.rs:13:9
    |
 LL |     let x = x.0;
@@ -60,7 +60,7 @@ note: previous binding is here
 LL |     let x = ([[0]], ());
    |         ^
 
-error: `x` is shadowed by `x[0]` which reuses the original value
+error: `x` is shadowed
   --> $DIR/shadow.rs:14:9
    |
 LL |     let x = x[0];
@@ -72,7 +72,7 @@ note: previous binding is here
 LL |     let x = x.0;
    |         ^
 
-error: `x` is shadowed by `x` which reuses the original value
+error: `x` is shadowed
   --> $DIR/shadow.rs:15:10
    |
 LL |     let [x] = x;
@@ -84,7 +84,7 @@ note: previous binding is here
 LL |     let x = x[0];
    |         ^
 
-error: `x` is shadowed by `Some(x)` which reuses the original value
+error: `x` is shadowed
   --> $DIR/shadow.rs:16:9
    |
 LL |     let x = Some(x);
@@ -96,7 +96,7 @@ note: previous binding is here
 LL |     let [x] = x;
    |          ^
 
-error: `x` is shadowed by `foo(x)` which reuses the original value
+error: `x` is shadowed
   --> $DIR/shadow.rs:17:9
    |
 LL |     let x = foo(x);
@@ -108,7 +108,7 @@ note: previous binding is here
 LL |     let x = Some(x);
    |         ^
 
-error: `x` is shadowed by `|| x` which reuses the original value
+error: `x` is shadowed
   --> $DIR/shadow.rs:18:9
    |
 LL |     let x = || x;
@@ -120,7 +120,7 @@ note: previous binding is here
 LL |     let x = foo(x);
    |         ^
 
-error: `x` is shadowed by `Some(1).map(|_| x)?` which reuses the original value
+error: `x` is shadowed
   --> $DIR/shadow.rs:19:9
    |
 LL |     let x = Some(1).map(|_| x)?;
@@ -132,102 +132,114 @@ note: previous binding is here
 LL |     let x = || x;
    |         ^
 
+error: `y` is shadowed
+  --> $DIR/shadow.rs:21:9
+   |
+LL |     let y = match y {
+   |         ^
+   |
+note: previous binding is here
+  --> $DIR/shadow.rs:20:9
+   |
+LL |     let y = 1;
+   |         ^
+
 error: `x` shadows a previous, unrelated binding
-  --> $DIR/shadow.rs:25:9
+  --> $DIR/shadow.rs:30:9
    |
 LL |     let x = 2;
    |         ^
    |
    = note: `-D clippy::shadow-unrelated` implied by `-D warnings`
 note: previous binding is here
-  --> $DIR/shadow.rs:24:9
+  --> $DIR/shadow.rs:29:9
    |
 LL |     let x = 1;
    |         ^
 
 error: `x` shadows a previous, unrelated binding
-  --> $DIR/shadow.rs:30:13
+  --> $DIR/shadow.rs:35:13
    |
 LL |         let x = 1;
    |             ^
    |
 note: previous binding is here
-  --> $DIR/shadow.rs:29:10
+  --> $DIR/shadow.rs:34:10
    |
 LL |     fn f(x: u32) {
    |          ^
 
 error: `x` shadows a previous, unrelated binding
-  --> $DIR/shadow.rs:35:14
+  --> $DIR/shadow.rs:40:14
    |
 LL |         Some(x) => {
    |              ^
    |
 note: previous binding is here
-  --> $DIR/shadow.rs:32:9
+  --> $DIR/shadow.rs:37:9
    |
 LL |     let x = 1;
    |         ^
 
 error: `x` shadows a previous, unrelated binding
-  --> $DIR/shadow.rs:36:17
+  --> $DIR/shadow.rs:41:17
    |
 LL |             let x = 1;
    |                 ^
    |
 note: previous binding is here
-  --> $DIR/shadow.rs:35:14
+  --> $DIR/shadow.rs:40:14
    |
 LL |         Some(x) => {
    |              ^
 
 error: `x` shadows a previous, unrelated binding
-  --> $DIR/shadow.rs:40:17
+  --> $DIR/shadow.rs:45:17
    |
 LL |     if let Some(x) = Some(1) {}
    |                 ^
    |
 note: previous binding is here
-  --> $DIR/shadow.rs:32:9
+  --> $DIR/shadow.rs:37:9
    |
 LL |     let x = 1;
    |         ^
 
 error: `x` shadows a previous, unrelated binding
-  --> $DIR/shadow.rs:41:20
+  --> $DIR/shadow.rs:46:20
    |
 LL |     while let Some(x) = Some(1) {}
    |                    ^
    |
 note: previous binding is here
-  --> $DIR/shadow.rs:32:9
+  --> $DIR/shadow.rs:37:9
    |
 LL |     let x = 1;
    |         ^
 
 error: `x` shadows a previous, unrelated binding
-  --> $DIR/shadow.rs:42:15
+  --> $DIR/shadow.rs:47:15
    |
 LL |     let _ = |[x]: [u32; 1]| {
    |               ^
    |
 note: previous binding is here
-  --> $DIR/shadow.rs:32:9
+  --> $DIR/shadow.rs:37:9
    |
 LL |     let x = 1;
    |         ^
 
 error: `x` shadows a previous, unrelated binding
-  --> $DIR/shadow.rs:43:13
+  --> $DIR/shadow.rs:48:13
    |
 LL |         let x = 1;
    |             ^
    |
 note: previous binding is here
-  --> $DIR/shadow.rs:42:15
+  --> $DIR/shadow.rs:47:15
    |
 LL |     let _ = |[x]: [u32; 1]| {
    |               ^
 
-error: aborting due to 19 previous errors
+error: aborting due to 20 previous errors