Skip to content

Commit 5be3f9f

Browse files
committed
Auto merge of rust-lang#79620 - JohnTitor:label-name-sugg, r=davidtwco
Tweak diagnostics on shadowing lifetimes/labels Fixes rust-lang#79610 Skip adding a new test assuming we have already sufficient tests.
2 parents 1f95c91 + cdcce11 commit 5be3f9f

13 files changed

+95
-95
lines changed

compiler/rustc_resolve/src/late/lifetimes.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1098,7 +1098,7 @@ fn signal_shadowing_problem(tcx: TyCtxt<'_>, name: Symbol, orig: Original, shado
10981098
)
10991099
};
11001100
err.span_label(orig.span, "first declared here");
1101-
err.span_label(shadower.span, format!("lifetime {} already in scope", name));
1101+
err.span_label(shadower.span, format!("{} `{}` already in scope", orig.kind.desc(), name));
11021102
err.emit();
11031103
}
11041104

src/test/ui/error-codes/E0496.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ error[E0496]: lifetime name `'a` shadows a lifetime name that is already in scop
44
LL | impl<'a> Foo<'a> {
55
| -- first declared here
66
LL | fn f<'a>(x: &'a i32) {
7-
| ^^ lifetime 'a already in scope
7+
| ^^ lifetime `'a` already in scope
88

99
error: aborting due to previous error
1010

src/test/ui/generic-associated-types/shadowing.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,15 @@ error[E0496]: lifetime name `'a` shadows a lifetime name that is already in scop
2020
LL | trait Shadow<'a> {
2121
| -- first declared here
2222
LL | type Bar<'a>;
23-
| ^^ lifetime 'a already in scope
23+
| ^^ lifetime `'a` already in scope
2424

2525
error[E0496]: lifetime name `'a` shadows a lifetime name that is already in scope
2626
--> $DIR/shadowing.rs:14:14
2727
|
2828
LL | impl<'a> NoShadow<'a> for &'a u32 {
2929
| -- first declared here
3030
LL | type Bar<'a> = i32;
31-
| ^^ lifetime 'a already in scope
31+
| ^^ lifetime `'a` already in scope
3232

3333
error: aborting due to 4 previous errors
3434

src/test/ui/hygiene/hygienic-labels-in-let.stderr

+28-28
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ warning: label name `'x` shadows a label name that is already in scope
22
--> $DIR/hygienic-labels-in-let.rs:16:9
33
|
44
LL | 'x: loop { $e }
5-
| ^^ lifetime 'x already in scope
5+
| ^^ label `'x` already in scope
66
...
77
LL | 'x: loop {
88
| -- first declared here
@@ -19,7 +19,7 @@ LL | 'x: loop {
1919
| -- first declared here
2020
...
2121
LL | 'x: for _ in 0..1 {
22-
| ^^ lifetime 'x already in scope
22+
| ^^ label `'x` already in scope
2323

2424
warning: label name `'x` shadows a label name that is already in scope
2525
--> $DIR/hygienic-labels-in-let.rs:64:9
@@ -28,13 +28,13 @@ LL | 'x: loop { $e }
2828
| -- first declared here
2929
...
3030
LL | 'x: for _ in 0..1 {
31-
| ^^ lifetime 'x already in scope
31+
| ^^ label `'x` already in scope
3232

3333
warning: label name `'x` shadows a label name that is already in scope
3434
--> $DIR/hygienic-labels-in-let.rs:16:9
3535
|
3636
LL | 'x: loop { $e }
37-
| ^^ lifetime 'x already in scope
37+
| ^^ label `'x` already in scope
3838
...
3939
LL | 'x: loop {
4040
| -- first declared here
@@ -51,7 +51,7 @@ LL | 'x: loop { $e }
5151
| ^^
5252
| |
5353
| first declared here
54-
| lifetime 'x already in scope
54+
| label `'x` already in scope
5555
...
5656
LL | loop_x!(break 'x);
5757
| ------------------ in this macro invocation
@@ -62,7 +62,7 @@ warning: label name `'x` shadows a label name that is already in scope
6262
--> $DIR/hygienic-labels-in-let.rs:16:9
6363
|
6464
LL | 'x: loop { $e }
65-
| ^^ lifetime 'x already in scope
65+
| ^^ label `'x` already in scope
6666
...
6767
LL | 'x: for _ in 0..1 {
6868
| -- first declared here
@@ -79,7 +79,7 @@ LL | 'x: loop {
7979
| -- first declared here
8080
...
8181
LL | 'x: for _ in 0..1 {
82-
| ^^ lifetime 'x already in scope
82+
| ^^ label `'x` already in scope
8383

8484
warning: label name `'x` shadows a label name that is already in scope
8585
--> $DIR/hygienic-labels-in-let.rs:76:9
@@ -88,7 +88,7 @@ LL | 'x: loop { $e }
8888
| -- first declared here
8989
...
9090
LL | 'x: for _ in 0..1 {
91-
| ^^ lifetime 'x already in scope
91+
| ^^ label `'x` already in scope
9292

9393
warning: label name `'x` shadows a label name that is already in scope
9494
--> $DIR/hygienic-labels-in-let.rs:76:9
@@ -97,7 +97,7 @@ LL | 'x: for _ in 0..1 {
9797
| -- first declared here
9898
...
9999
LL | 'x: for _ in 0..1 {
100-
| ^^ lifetime 'x already in scope
100+
| ^^ label `'x` already in scope
101101

102102
warning: label name `'x` shadows a label name that is already in scope
103103
--> $DIR/hygienic-labels-in-let.rs:76:9
@@ -106,13 +106,13 @@ LL | 'x: loop { $e }
106106
| -- first declared here
107107
...
108108
LL | 'x: for _ in 0..1 {
109-
| ^^ lifetime 'x already in scope
109+
| ^^ label `'x` already in scope
110110

111111
warning: label name `'x` shadows a label name that is already in scope
112112
--> $DIR/hygienic-labels-in-let.rs:27:9
113113
|
114114
LL | 'x: while 1 + 1 == 2 { $e }
115-
| ^^ lifetime 'x already in scope
115+
| ^^ label `'x` already in scope
116116
...
117117
LL | 'x: loop {
118118
| -- first declared here
@@ -129,7 +129,7 @@ LL | 'x: loop { $e }
129129
| -- first declared here
130130
...
131131
LL | 'x: while 1 + 1 == 2 { $e }
132-
| ^^ lifetime 'x already in scope
132+
| ^^ label `'x` already in scope
133133
...
134134
LL | while_true!(break 'x);
135135
| ---------------------- in this macro invocation
@@ -140,7 +140,7 @@ warning: label name `'x` shadows a label name that is already in scope
140140
--> $DIR/hygienic-labels-in-let.rs:27:9
141141
|
142142
LL | 'x: while 1 + 1 == 2 { $e }
143-
| ^^ lifetime 'x already in scope
143+
| ^^ label `'x` already in scope
144144
...
145145
LL | 'x: for _ in 0..1 {
146146
| -- first declared here
@@ -157,7 +157,7 @@ LL | 'x: loop { $e }
157157
| -- first declared here
158158
...
159159
LL | 'x: while 1 + 1 == 2 { $e }
160-
| ^^ lifetime 'x already in scope
160+
| ^^ label `'x` already in scope
161161
...
162162
LL | while_true!(break 'x);
163163
| ---------------------- in this macro invocation
@@ -168,7 +168,7 @@ warning: label name `'x` shadows a label name that is already in scope
168168
--> $DIR/hygienic-labels-in-let.rs:27:9
169169
|
170170
LL | 'x: while 1 + 1 == 2 { $e }
171-
| ^^ lifetime 'x already in scope
171+
| ^^ label `'x` already in scope
172172
...
173173
LL | 'x: for _ in 0..1 {
174174
| -- first declared here
@@ -185,7 +185,7 @@ LL | 'x: loop {
185185
| -- first declared here
186186
...
187187
LL | 'x: for _ in 0..1 {
188-
| ^^ lifetime 'x already in scope
188+
| ^^ label `'x` already in scope
189189

190190
warning: label name `'x` shadows a label name that is already in scope
191191
--> $DIR/hygienic-labels-in-let.rs:90:9
@@ -194,7 +194,7 @@ LL | 'x: loop { $e }
194194
| -- first declared here
195195
...
196196
LL | 'x: for _ in 0..1 {
197-
| ^^ lifetime 'x already in scope
197+
| ^^ label `'x` already in scope
198198

199199
warning: label name `'x` shadows a label name that is already in scope
200200
--> $DIR/hygienic-labels-in-let.rs:90:9
@@ -203,7 +203,7 @@ LL | 'x: for _ in 0..1 {
203203
| -- first declared here
204204
...
205205
LL | 'x: for _ in 0..1 {
206-
| ^^ lifetime 'x already in scope
206+
| ^^ label `'x` already in scope
207207

208208
warning: label name `'x` shadows a label name that is already in scope
209209
--> $DIR/hygienic-labels-in-let.rs:90:9
@@ -212,7 +212,7 @@ LL | 'x: loop { $e }
212212
| -- first declared here
213213
...
214214
LL | 'x: for _ in 0..1 {
215-
| ^^ lifetime 'x already in scope
215+
| ^^ label `'x` already in scope
216216

217217
warning: label name `'x` shadows a label name that is already in scope
218218
--> $DIR/hygienic-labels-in-let.rs:90:9
@@ -221,7 +221,7 @@ LL | 'x: for _ in 0..1 {
221221
| -- first declared here
222222
...
223223
LL | 'x: for _ in 0..1 {
224-
| ^^ lifetime 'x already in scope
224+
| ^^ label `'x` already in scope
225225

226226
warning: label name `'x` shadows a label name that is already in scope
227227
--> $DIR/hygienic-labels-in-let.rs:90:9
@@ -230,13 +230,13 @@ LL | 'x: while 1 + 1 == 2 { $e }
230230
| -- first declared here
231231
...
232232
LL | 'x: for _ in 0..1 {
233-
| ^^ lifetime 'x already in scope
233+
| ^^ label `'x` already in scope
234234

235235
warning: label name `'x` shadows a label name that is already in scope
236236
--> $DIR/hygienic-labels-in-let.rs:39:9
237237
|
238238
LL | 'x: for _ in 0..1 { $e }
239-
| ^^ lifetime 'x already in scope
239+
| ^^ label `'x` already in scope
240240
...
241241
LL | 'x: loop {
242242
| -- first declared here
@@ -253,7 +253,7 @@ LL | 'x: loop { $e }
253253
| -- first declared here
254254
...
255255
LL | 'x: for _ in 0..1 { $e }
256-
| ^^ lifetime 'x already in scope
256+
| ^^ label `'x` already in scope
257257
...
258258
LL | run_once!(continue 'x);
259259
| ----------------------- in this macro invocation
@@ -264,7 +264,7 @@ warning: label name `'x` shadows a label name that is already in scope
264264
--> $DIR/hygienic-labels-in-let.rs:39:9
265265
|
266266
LL | 'x: for _ in 0..1 { $e }
267-
| ^^ lifetime 'x already in scope
267+
| ^^ label `'x` already in scope
268268
...
269269
LL | 'x: for _ in 0..1 {
270270
| -- first declared here
@@ -281,7 +281,7 @@ LL | 'x: loop { $e }
281281
| -- first declared here
282282
...
283283
LL | 'x: for _ in 0..1 { $e }
284-
| ^^ lifetime 'x already in scope
284+
| ^^ label `'x` already in scope
285285
...
286286
LL | run_once!(continue 'x);
287287
| ----------------------- in this macro invocation
@@ -292,7 +292,7 @@ warning: label name `'x` shadows a label name that is already in scope
292292
--> $DIR/hygienic-labels-in-let.rs:39:9
293293
|
294294
LL | 'x: for _ in 0..1 { $e }
295-
| ^^ lifetime 'x already in scope
295+
| ^^ label `'x` already in scope
296296
...
297297
LL | 'x: for _ in 0..1 {
298298
| -- first declared here
@@ -309,7 +309,7 @@ LL | 'x: while 1 + 1 == 2 { $e }
309309
| -- first declared here
310310
...
311311
LL | 'x: for _ in 0..1 { $e }
312-
| ^^ lifetime 'x already in scope
312+
| ^^ label `'x` already in scope
313313
...
314314
LL | run_once!(continue 'x);
315315
| ----------------------- in this macro invocation
@@ -320,7 +320,7 @@ warning: label name `'x` shadows a label name that is already in scope
320320
--> $DIR/hygienic-labels-in-let.rs:39:9
321321
|
322322
LL | 'x: for _ in 0..1 { $e }
323-
| ^^ lifetime 'x already in scope
323+
| ^^ label `'x` already in scope
324324
...
325325
LL | 'x: for _ in 0..1 {
326326
| -- first declared here

0 commit comments

Comments
 (0)