Skip to content

Commit 7217c0f

Browse files
committed
Auto merge of rust-lang#11628 - koka831:fix/11625, r=blyxyas
Improve `redundant_locals` help message Fixes rust-lang#11625 AFAIK, `span_lint_and_help` points the beginning of spans when we pass multiple spans to the second argument, so This PR I also modified its help span and its message. lint result of the given example in the issue will be: ```console error: redundant redefinition of a binding `apple` --> src/main.rs:5:5 | 5 | let apple = apple; | ^^^^^^^^^^^^^^^^^^ | help: `apple` is initially defined here --> src/main.rs:4:9 | 4 | let apple = 42; | ^^^^^ = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#redundant_locals ``` I hope that this change might help reduce user confusion, but I'd appreciate alternative suggestions:) changelog: [`redundant_locals`]: Now points at the rebinding of the variable
2 parents 279127c + 48d2770 commit 7217c0f

File tree

2 files changed

+86
-62
lines changed

2 files changed

+86
-62
lines changed

clippy_lints/src/redundant_locals.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,10 @@ impl<'tcx> LateLintPass<'tcx> for RedundantLocals {
7474
span_lint_and_help(
7575
cx,
7676
REDUNDANT_LOCALS,
77-
vec![binding_pat.span, local.span],
78-
"redundant redefinition of a binding",
79-
None,
80-
&format!("remove the redefinition of `{ident}`"),
77+
local.span,
78+
&format!("redundant redefinition of a binding `{ident}`"),
79+
Some(binding_pat.span),
80+
&format!("`{ident}` is initially defined here"),
8181
);
8282
}
8383
}

tests/ui/redundant_locals.stderr

Lines changed: 82 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,148 +1,172 @@
1-
error: redundant redefinition of a binding
2-
--> $DIR/redundant_locals.rs:11:9
1+
error: redundant redefinition of a binding `x`
2+
--> $DIR/redundant_locals.rs:12:5
33
|
4-
LL | let x = 1;
5-
| ^
64
LL | let x = x;
75
| ^^^^^^^^^^
86
|
9-
= help: remove the redefinition of `x`
7+
help: `x` is initially defined here
8+
--> $DIR/redundant_locals.rs:11:9
9+
|
10+
LL | let x = 1;
11+
| ^
1012
= note: `-D clippy::redundant-locals` implied by `-D warnings`
1113
= help: to override `-D warnings` add `#[allow(clippy::redundant_locals)]`
1214

13-
error: redundant redefinition of a binding
14-
--> $DIR/redundant_locals.rs:16:9
15+
error: redundant redefinition of a binding `x`
16+
--> $DIR/redundant_locals.rs:17:5
1517
|
16-
LL | let mut x = 1;
17-
| ^^^^^
1818
LL | let mut x = x;
1919
| ^^^^^^^^^^^^^^
2020
|
21-
= help: remove the redefinition of `x`
21+
help: `x` is initially defined here
22+
--> $DIR/redundant_locals.rs:16:9
23+
|
24+
LL | let mut x = 1;
25+
| ^^^^^
2226

23-
error: redundant redefinition of a binding
27+
error: redundant redefinition of a binding `x`
28+
--> $DIR/redundant_locals.rs:47:5
29+
|
30+
LL | let x = x;
31+
| ^^^^^^^^^^
32+
|
33+
help: `x` is initially defined here
2434
--> $DIR/redundant_locals.rs:46:14
2535
|
2636
LL | fn parameter(x: i32) {
2737
| ^
38+
39+
error: redundant redefinition of a binding `x`
40+
--> $DIR/redundant_locals.rs:52:5
41+
|
2842
LL | let x = x;
2943
| ^^^^^^^^^^
3044
|
31-
= help: remove the redefinition of `x`
32-
33-
error: redundant redefinition of a binding
45+
help: `x` is initially defined here
3446
--> $DIR/redundant_locals.rs:51:9
3547
|
3648
LL | let x = 1;
3749
| ^
50+
51+
error: redundant redefinition of a binding `x`
52+
--> $DIR/redundant_locals.rs:53:5
53+
|
3854
LL | let x = x;
3955
| ^^^^^^^^^^
4056
|
41-
= help: remove the redefinition of `x`
42-
43-
error: redundant redefinition of a binding
57+
help: `x` is initially defined here
4458
--> $DIR/redundant_locals.rs:52:9
4559
|
4660
LL | let x = x;
4761
| ^
62+
63+
error: redundant redefinition of a binding `x`
64+
--> $DIR/redundant_locals.rs:54:5
65+
|
4866
LL | let x = x;
4967
| ^^^^^^^^^^
5068
|
51-
= help: remove the redefinition of `x`
52-
53-
error: redundant redefinition of a binding
69+
help: `x` is initially defined here
5470
--> $DIR/redundant_locals.rs:53:9
5571
|
5672
LL | let x = x;
5773
| ^
74+
75+
error: redundant redefinition of a binding `x`
76+
--> $DIR/redundant_locals.rs:55:5
77+
|
5878
LL | let x = x;
5979
| ^^^^^^^^^^
6080
|
61-
= help: remove the redefinition of `x`
62-
63-
error: redundant redefinition of a binding
81+
help: `x` is initially defined here
6482
--> $DIR/redundant_locals.rs:54:9
6583
|
6684
LL | let x = x;
6785
| ^
68-
LL | let x = x;
86+
87+
error: redundant redefinition of a binding `a`
88+
--> $DIR/redundant_locals.rs:61:5
89+
|
90+
LL | let a = a;
6991
| ^^^^^^^^^^
7092
|
71-
= help: remove the redefinition of `x`
72-
73-
error: redundant redefinition of a binding
93+
help: `a` is initially defined here
7494
--> $DIR/redundant_locals.rs:59:9
7595
|
7696
LL | let a = 1;
7797
| ^
78-
LL | let b = 2;
79-
LL | let a = a;
98+
99+
error: redundant redefinition of a binding `b`
100+
--> $DIR/redundant_locals.rs:62:5
101+
|
102+
LL | let b = b;
80103
| ^^^^^^^^^^
81104
|
82-
= help: remove the redefinition of `a`
83-
84-
error: redundant redefinition of a binding
105+
help: `b` is initially defined here
85106
--> $DIR/redundant_locals.rs:60:9
86107
|
87108
LL | let b = 2;
88109
| ^
89-
LL | let a = a;
90-
LL | let b = b;
91-
| ^^^^^^^^^^
92-
|
93-
= help: remove the redefinition of `b`
94110

95-
error: redundant redefinition of a binding
111+
error: redundant redefinition of a binding `x`
112+
--> $DIR/redundant_locals.rs:68:9
113+
|
114+
LL | let x = x;
115+
| ^^^^^^^^^^
116+
|
117+
help: `x` is initially defined here
96118
--> $DIR/redundant_locals.rs:67:13
97119
|
98120
LL | let x = 1;
99121
| ^
122+
123+
error: redundant redefinition of a binding `x`
124+
--> $DIR/redundant_locals.rs:75:9
125+
|
100126
LL | let x = x;
101127
| ^^^^^^^^^^
102128
|
103-
= help: remove the redefinition of `x`
104-
105-
error: redundant redefinition of a binding
129+
help: `x` is initially defined here
106130
--> $DIR/redundant_locals.rs:74:13
107131
|
108132
LL | let x = 1;
109133
| ^
134+
135+
error: redundant redefinition of a binding `x`
136+
--> $DIR/redundant_locals.rs:78:9
137+
|
110138
LL | let x = x;
111139
| ^^^^^^^^^^
112140
|
113-
= help: remove the redefinition of `x`
114-
115-
error: redundant redefinition of a binding
141+
help: `x` is initially defined here
116142
--> $DIR/redundant_locals.rs:77:6
117143
|
118144
LL | |x: i32| {
119145
| ^
146+
147+
error: redundant redefinition of a binding `x`
148+
--> $DIR/redundant_locals.rs:97:9
149+
|
120150
LL | let x = x;
121151
| ^^^^^^^^^^
122152
|
123-
= help: remove the redefinition of `x`
124-
125-
error: redundant redefinition of a binding
153+
help: `x` is initially defined here
126154
--> $DIR/redundant_locals.rs:94:9
127155
|
128156
LL | let x = 1;
129157
| ^
130-
...
131-
LL | let x = x;
132-
| ^^^^^^^^^^
133-
|
134-
= help: remove the redefinition of `x`
135158

136-
error: redundant redefinition of a binding
137-
--> $DIR/redundant_locals.rs:142:9
159+
error: redundant redefinition of a binding `a`
160+
--> $DIR/redundant_locals.rs:144:5
138161
|
139-
LL | let a = WithoutDrop(1);
140-
| ^
141-
LL | let b = WithoutDrop(2);
142162
LL | let a = a;
143163
| ^^^^^^^^^^
144164
|
145-
= help: remove the redefinition of `a`
165+
help: `a` is initially defined here
166+
--> $DIR/redundant_locals.rs:142:9
167+
|
168+
LL | let a = WithoutDrop(1);
169+
| ^
146170

147171
error: aborting due to 14 previous errors
148172

0 commit comments

Comments
 (0)