Skip to content

Commit 5bfdf18

Browse files
committed
Make shadow_reuse suggestion less verbose
1 parent 11492c7 commit 5bfdf18

File tree

3 files changed

+42
-29
lines changed

3 files changed

+42
-29
lines changed

clippy_lints/src/shadow.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -162,11 +162,7 @@ fn lint_shadow(cx: &LateContext<'_>, pat: &Pat<'_>, shadowed: HirId, span: Span)
162162
(SHADOW_SAME, msg)
163163
},
164164
Some(expr) if is_local_used(cx, expr, shadowed) => {
165-
let msg = format!(
166-
"`{}` is shadowed by `{}` which reuses the original value",
167-
snippet(cx, pat.span, "_"),
168-
snippet(cx, expr.span, "..")
169-
);
165+
let msg = format!("`{}` is shadowed", snippet(cx, pat.span, "_"),);
170166
(SHADOW_REUSE, msg)
171167
},
172168
_ => {

tests/ui/shadow.rs

+5
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ fn shadow_reuse() -> Option<()> {
1717
let x = foo(x);
1818
let x = || x;
1919
let x = Some(1).map(|_| x)?;
20+
let y = 1;
21+
let y = match y {
22+
1 => 2,
23+
_ => 3,
24+
};
2025
None
2126
}
2227

tests/ui/shadow.stderr

+36-24
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ note: previous binding is here
4747
LL | let x = &mut x;
4848
| ^
4949

50-
error: `x` is shadowed by `x.0` which reuses the original value
50+
error: `x` is shadowed
5151
--> $DIR/shadow.rs:13:9
5252
|
5353
LL | let x = x.0;
@@ -60,7 +60,7 @@ note: previous binding is here
6060
LL | let x = ([[0]], ());
6161
| ^
6262

63-
error: `x` is shadowed by `x[0]` which reuses the original value
63+
error: `x` is shadowed
6464
--> $DIR/shadow.rs:14:9
6565
|
6666
LL | let x = x[0];
@@ -72,7 +72,7 @@ note: previous binding is here
7272
LL | let x = x.0;
7373
| ^
7474

75-
error: `x` is shadowed by `x` which reuses the original value
75+
error: `x` is shadowed
7676
--> $DIR/shadow.rs:15:10
7777
|
7878
LL | let [x] = x;
@@ -84,7 +84,7 @@ note: previous binding is here
8484
LL | let x = x[0];
8585
| ^
8686

87-
error: `x` is shadowed by `Some(x)` which reuses the original value
87+
error: `x` is shadowed
8888
--> $DIR/shadow.rs:16:9
8989
|
9090
LL | let x = Some(x);
@@ -96,7 +96,7 @@ note: previous binding is here
9696
LL | let [x] = x;
9797
| ^
9898

99-
error: `x` is shadowed by `foo(x)` which reuses the original value
99+
error: `x` is shadowed
100100
--> $DIR/shadow.rs:17:9
101101
|
102102
LL | let x = foo(x);
@@ -108,7 +108,7 @@ note: previous binding is here
108108
LL | let x = Some(x);
109109
| ^
110110

111-
error: `x` is shadowed by `|| x` which reuses the original value
111+
error: `x` is shadowed
112112
--> $DIR/shadow.rs:18:9
113113
|
114114
LL | let x = || x;
@@ -120,7 +120,7 @@ note: previous binding is here
120120
LL | let x = foo(x);
121121
| ^
122122

123-
error: `x` is shadowed by `Some(1).map(|_| x)?` which reuses the original value
123+
error: `x` is shadowed
124124
--> $DIR/shadow.rs:19:9
125125
|
126126
LL | let x = Some(1).map(|_| x)?;
@@ -132,102 +132,114 @@ note: previous binding is here
132132
LL | let x = || x;
133133
| ^
134134

135+
error: `y` is shadowed
136+
--> $DIR/shadow.rs:21:9
137+
|
138+
LL | let y = match y {
139+
| ^
140+
|
141+
note: previous binding is here
142+
--> $DIR/shadow.rs:20:9
143+
|
144+
LL | let y = 1;
145+
| ^
146+
135147
error: `x` shadows a previous, unrelated binding
136-
--> $DIR/shadow.rs:25:9
148+
--> $DIR/shadow.rs:30:9
137149
|
138150
LL | let x = 2;
139151
| ^
140152
|
141153
= note: `-D clippy::shadow-unrelated` implied by `-D warnings`
142154
note: previous binding is here
143-
--> $DIR/shadow.rs:24:9
155+
--> $DIR/shadow.rs:29:9
144156
|
145157
LL | let x = 1;
146158
| ^
147159

148160
error: `x` shadows a previous, unrelated binding
149-
--> $DIR/shadow.rs:30:13
161+
--> $DIR/shadow.rs:35:13
150162
|
151163
LL | let x = 1;
152164
| ^
153165
|
154166
note: previous binding is here
155-
--> $DIR/shadow.rs:29:10
167+
--> $DIR/shadow.rs:34:10
156168
|
157169
LL | fn f(x: u32) {
158170
| ^
159171

160172
error: `x` shadows a previous, unrelated binding
161-
--> $DIR/shadow.rs:35:14
173+
--> $DIR/shadow.rs:40:14
162174
|
163175
LL | Some(x) => {
164176
| ^
165177
|
166178
note: previous binding is here
167-
--> $DIR/shadow.rs:32:9
179+
--> $DIR/shadow.rs:37:9
168180
|
169181
LL | let x = 1;
170182
| ^
171183

172184
error: `x` shadows a previous, unrelated binding
173-
--> $DIR/shadow.rs:36:17
185+
--> $DIR/shadow.rs:41:17
174186
|
175187
LL | let x = 1;
176188
| ^
177189
|
178190
note: previous binding is here
179-
--> $DIR/shadow.rs:35:14
191+
--> $DIR/shadow.rs:40:14
180192
|
181193
LL | Some(x) => {
182194
| ^
183195

184196
error: `x` shadows a previous, unrelated binding
185-
--> $DIR/shadow.rs:40:17
197+
--> $DIR/shadow.rs:45:17
186198
|
187199
LL | if let Some(x) = Some(1) {}
188200
| ^
189201
|
190202
note: previous binding is here
191-
--> $DIR/shadow.rs:32:9
203+
--> $DIR/shadow.rs:37:9
192204
|
193205
LL | let x = 1;
194206
| ^
195207

196208
error: `x` shadows a previous, unrelated binding
197-
--> $DIR/shadow.rs:41:20
209+
--> $DIR/shadow.rs:46:20
198210
|
199211
LL | while let Some(x) = Some(1) {}
200212
| ^
201213
|
202214
note: previous binding is here
203-
--> $DIR/shadow.rs:32:9
215+
--> $DIR/shadow.rs:37:9
204216
|
205217
LL | let x = 1;
206218
| ^
207219

208220
error: `x` shadows a previous, unrelated binding
209-
--> $DIR/shadow.rs:42:15
221+
--> $DIR/shadow.rs:47:15
210222
|
211223
LL | let _ = |[x]: [u32; 1]| {
212224
| ^
213225
|
214226
note: previous binding is here
215-
--> $DIR/shadow.rs:32:9
227+
--> $DIR/shadow.rs:37:9
216228
|
217229
LL | let x = 1;
218230
| ^
219231

220232
error: `x` shadows a previous, unrelated binding
221-
--> $DIR/shadow.rs:43:13
233+
--> $DIR/shadow.rs:48:13
222234
|
223235
LL | let x = 1;
224236
| ^
225237
|
226238
note: previous binding is here
227-
--> $DIR/shadow.rs:42:15
239+
--> $DIR/shadow.rs:47:15
228240
|
229241
LL | let _ = |[x]: [u32; 1]| {
230242
| ^
231243

232-
error: aborting due to 19 previous errors
244+
error: aborting due to 20 previous errors
233245

0 commit comments

Comments
 (0)