Skip to content

Commit ef43cde

Browse files
authored
Rollup merge of #70428 - Centril:move-to-mod, r=petrochenkov
`error_bad_item_kind`: add help text For example, this adds: ``` = help: consider moving the `use` import out to a nearby module scope ``` r? @petrochenkov @estebank Fixes #37205.
2 parents c640b95 + 91c68c5 commit ef43cde

5 files changed

+93
-2
lines changed

src/librustc_parse/parser/item.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -908,8 +908,10 @@ impl<'a> Parser<'a> {
908908

909909
fn error_bad_item_kind<T>(&self, span: Span, kind: &ItemKind, ctx: &str) -> Option<T> {
910910
let span = self.sess.source_map().guess_head_span(span);
911-
let msg = format!("{} is not supported in {}", kind.descr(), ctx);
912-
self.struct_span_err(span, &msg).emit();
911+
let descr = kind.descr();
912+
self.struct_span_err(span, &format!("{} is not supported in {}", descr, ctx))
913+
.help(&format!("consider moving the {} out to a nearby module scope", descr))
914+
.emit();
913915
None
914916
}
915917

src/test/ui/parser/default-on-wrong-item-kind.stderr

+72
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,8 @@ error: extern crate is not supported in `extern` blocks
123123
|
124124
LL | default extern crate foo;
125125
| ^^^^^^^^^^^^^^^^^^^^^^^^^
126+
|
127+
= help: consider moving the extern crate out to a nearby module scope
126128

127129
error: a `use` import cannot be `default`
128130
--> $DIR/default-on-wrong-item-kind.rs:35:5
@@ -137,6 +139,8 @@ error: `use` import is not supported in `extern` blocks
137139
|
138140
LL | default use foo;
139141
| ^^^^^^^^^^^^^^^^
142+
|
143+
= help: consider moving the `use` import out to a nearby module scope
140144

141145
error: a static item cannot be `default`
142146
--> $DIR/default-on-wrong-item-kind.rs:37:5
@@ -169,6 +173,8 @@ error: module is not supported in `extern` blocks
169173
|
170174
LL | default mod foo {}
171175
| ^^^^^^^^^^^^^^^
176+
|
177+
= help: consider moving the module out to a nearby module scope
172178

173179
error: an extern block cannot be `default`
174180
--> $DIR/default-on-wrong-item-kind.rs:43:5
@@ -183,6 +189,8 @@ error: extern block is not supported in `extern` blocks
183189
|
184190
LL | default extern "C" {}
185191
| ^^^^^^^^^^^^^^^^^^
192+
|
193+
= help: consider moving the extern block out to a nearby module scope
186194

187195
error: an enum cannot be `default`
188196
--> $DIR/default-on-wrong-item-kind.rs:46:5
@@ -197,6 +205,8 @@ error: enum is not supported in `extern` blocks
197205
|
198206
LL | default enum foo {}
199207
| ^^^^^^^^^^^^^^^^
208+
|
209+
= help: consider moving the enum out to a nearby module scope
200210

201211
error: a struct cannot be `default`
202212
--> $DIR/default-on-wrong-item-kind.rs:48:5
@@ -211,6 +221,8 @@ error: struct is not supported in `extern` blocks
211221
|
212222
LL | default struct foo {}
213223
| ^^^^^^^^^^^^^^^^^^
224+
|
225+
= help: consider moving the struct out to a nearby module scope
214226

215227
error: a union cannot be `default`
216228
--> $DIR/default-on-wrong-item-kind.rs:50:5
@@ -225,6 +237,8 @@ error: union is not supported in `extern` blocks
225237
|
226238
LL | default union foo {}
227239
| ^^^^^^^^^^^^^^^^^
240+
|
241+
= help: consider moving the union out to a nearby module scope
228242

229243
error: a trait cannot be `default`
230244
--> $DIR/default-on-wrong-item-kind.rs:52:5
@@ -239,6 +253,8 @@ error: trait is not supported in `extern` blocks
239253
|
240254
LL | default trait foo {}
241255
| ^^^^^^^^^^^^^^^^^
256+
|
257+
= help: consider moving the trait out to a nearby module scope
242258

243259
error: a trait alias cannot be `default`
244260
--> $DIR/default-on-wrong-item-kind.rs:54:5
@@ -253,12 +269,16 @@ error: trait alias is not supported in `extern` blocks
253269
|
254270
LL | default trait foo = Ord;
255271
| ^^^^^^^^^^^^^^^^^^^^^^^^
272+
|
273+
= help: consider moving the trait alias out to a nearby module scope
256274

257275
error: implementation is not supported in `extern` blocks
258276
--> $DIR/default-on-wrong-item-kind.rs:56:5
259277
|
260278
LL | default impl foo {}
261279
| ^^^^^^^^^^^^^^^^
280+
|
281+
= help: consider moving the implementation out to a nearby module scope
262282

263283
error: an item macro invocation cannot be `default`
264284
--> $DIR/default-on-wrong-item-kind.rs:60:5
@@ -289,6 +309,8 @@ error: macro definition is not supported in `extern` blocks
289309
|
290310
LL | default macro foo {}
291311
| ^^^^^^^^^^^^^^^^^
312+
|
313+
= help: consider moving the macro definition out to a nearby module scope
292314

293315
error: a macro definition cannot be `default`
294316
--> $DIR/default-on-wrong-item-kind.rs:64:5
@@ -303,6 +325,8 @@ error: macro definition is not supported in `extern` blocks
303325
|
304326
LL | default macro_rules! foo {}
305327
| ^^^^^^^^^^^^^^^^^^^^^^^^
328+
|
329+
= help: consider moving the macro definition out to a nearby module scope
306330

307331
error: an extern crate cannot be `default`
308332
--> $DIR/default-on-wrong-item-kind.rs:70:5
@@ -317,6 +341,8 @@ error: extern crate is not supported in `trait`s or `impl`s
317341
|
318342
LL | default extern crate foo;
319343
| ^^^^^^^^^^^^^^^^^^^^^^^^^
344+
|
345+
= help: consider moving the extern crate out to a nearby module scope
320346

321347
error: a `use` import cannot be `default`
322348
--> $DIR/default-on-wrong-item-kind.rs:72:5
@@ -331,6 +357,8 @@ error: `use` import is not supported in `trait`s or `impl`s
331357
|
332358
LL | default use foo;
333359
| ^^^^^^^^^^^^^^^^
360+
|
361+
= help: consider moving the `use` import out to a nearby module scope
334362

335363
error: a static item cannot be `default`
336364
--> $DIR/default-on-wrong-item-kind.rs:74:5
@@ -359,6 +387,8 @@ error: module is not supported in `trait`s or `impl`s
359387
|
360388
LL | default mod foo {}
361389
| ^^^^^^^^^^^^^^^
390+
|
391+
= help: consider moving the module out to a nearby module scope
362392

363393
error: an extern block cannot be `default`
364394
--> $DIR/default-on-wrong-item-kind.rs:80:5
@@ -373,6 +403,8 @@ error: extern block is not supported in `trait`s or `impl`s
373403
|
374404
LL | default extern "C" {}
375405
| ^^^^^^^^^^^^^^^^^^
406+
|
407+
= help: consider moving the extern block out to a nearby module scope
376408

377409
error: an enum cannot be `default`
378410
--> $DIR/default-on-wrong-item-kind.rs:83:5
@@ -387,6 +419,8 @@ error: enum is not supported in `trait`s or `impl`s
387419
|
388420
LL | default enum foo {}
389421
| ^^^^^^^^^^^^^^^^
422+
|
423+
= help: consider moving the enum out to a nearby module scope
390424

391425
error: a struct cannot be `default`
392426
--> $DIR/default-on-wrong-item-kind.rs:85:5
@@ -401,6 +435,8 @@ error: struct is not supported in `trait`s or `impl`s
401435
|
402436
LL | default struct foo {}
403437
| ^^^^^^^^^^^^^^^^^^
438+
|
439+
= help: consider moving the struct out to a nearby module scope
404440

405441
error: a union cannot be `default`
406442
--> $DIR/default-on-wrong-item-kind.rs:87:5
@@ -415,6 +451,8 @@ error: union is not supported in `trait`s or `impl`s
415451
|
416452
LL | default union foo {}
417453
| ^^^^^^^^^^^^^^^^^
454+
|
455+
= help: consider moving the union out to a nearby module scope
418456

419457
error: a trait cannot be `default`
420458
--> $DIR/default-on-wrong-item-kind.rs:89:5
@@ -429,6 +467,8 @@ error: trait is not supported in `trait`s or `impl`s
429467
|
430468
LL | default trait foo {}
431469
| ^^^^^^^^^^^^^^^^^
470+
|
471+
= help: consider moving the trait out to a nearby module scope
432472

433473
error: a trait alias cannot be `default`
434474
--> $DIR/default-on-wrong-item-kind.rs:91:5
@@ -443,12 +483,16 @@ error: trait alias is not supported in `trait`s or `impl`s
443483
|
444484
LL | default trait foo = Ord;
445485
| ^^^^^^^^^^^^^^^^^^^^^^^^
486+
|
487+
= help: consider moving the trait alias out to a nearby module scope
446488

447489
error: implementation is not supported in `trait`s or `impl`s
448490
--> $DIR/default-on-wrong-item-kind.rs:93:5
449491
|
450492
LL | default impl foo {}
451493
| ^^^^^^^^^^^^^^^^
494+
|
495+
= help: consider moving the implementation out to a nearby module scope
452496

453497
error: an item macro invocation cannot be `default`
454498
--> $DIR/default-on-wrong-item-kind.rs:97:5
@@ -479,6 +523,8 @@ error: macro definition is not supported in `trait`s or `impl`s
479523
|
480524
LL | default macro foo {}
481525
| ^^^^^^^^^^^^^^^^^
526+
|
527+
= help: consider moving the macro definition out to a nearby module scope
482528

483529
error: a macro definition cannot be `default`
484530
--> $DIR/default-on-wrong-item-kind.rs:101:5
@@ -493,6 +539,8 @@ error: macro definition is not supported in `trait`s or `impl`s
493539
|
494540
LL | default macro_rules! foo {}
495541
| ^^^^^^^^^^^^^^^^^^^^^^^^
542+
|
543+
= help: consider moving the macro definition out to a nearby module scope
496544

497545
error: an extern crate cannot be `default`
498546
--> $DIR/default-on-wrong-item-kind.rs:107:5
@@ -507,6 +555,8 @@ error: extern crate is not supported in `trait`s or `impl`s
507555
|
508556
LL | default extern crate foo;
509557
| ^^^^^^^^^^^^^^^^^^^^^^^^^
558+
|
559+
= help: consider moving the extern crate out to a nearby module scope
510560

511561
error: a `use` import cannot be `default`
512562
--> $DIR/default-on-wrong-item-kind.rs:109:5
@@ -521,6 +571,8 @@ error: `use` import is not supported in `trait`s or `impl`s
521571
|
522572
LL | default use foo;
523573
| ^^^^^^^^^^^^^^^^
574+
|
575+
= help: consider moving the `use` import out to a nearby module scope
524576

525577
error: a static item cannot be `default`
526578
--> $DIR/default-on-wrong-item-kind.rs:111:5
@@ -549,6 +601,8 @@ error: module is not supported in `trait`s or `impl`s
549601
|
550602
LL | default mod foo {}
551603
| ^^^^^^^^^^^^^^^
604+
|
605+
= help: consider moving the module out to a nearby module scope
552606

553607
error: an extern block cannot be `default`
554608
--> $DIR/default-on-wrong-item-kind.rs:117:5
@@ -563,6 +617,8 @@ error: extern block is not supported in `trait`s or `impl`s
563617
|
564618
LL | default extern "C" {}
565619
| ^^^^^^^^^^^^^^^^^^
620+
|
621+
= help: consider moving the extern block out to a nearby module scope
566622

567623
error: an enum cannot be `default`
568624
--> $DIR/default-on-wrong-item-kind.rs:120:5
@@ -577,6 +633,8 @@ error: enum is not supported in `trait`s or `impl`s
577633
|
578634
LL | default enum foo {}
579635
| ^^^^^^^^^^^^^^^^
636+
|
637+
= help: consider moving the enum out to a nearby module scope
580638

581639
error: a struct cannot be `default`
582640
--> $DIR/default-on-wrong-item-kind.rs:122:5
@@ -591,6 +649,8 @@ error: struct is not supported in `trait`s or `impl`s
591649
|
592650
LL | default struct foo {}
593651
| ^^^^^^^^^^^^^^^^^^
652+
|
653+
= help: consider moving the struct out to a nearby module scope
594654

595655
error: a union cannot be `default`
596656
--> $DIR/default-on-wrong-item-kind.rs:124:5
@@ -605,6 +665,8 @@ error: union is not supported in `trait`s or `impl`s
605665
|
606666
LL | default union foo {}
607667
| ^^^^^^^^^^^^^^^^^
668+
|
669+
= help: consider moving the union out to a nearby module scope
608670

609671
error: a trait cannot be `default`
610672
--> $DIR/default-on-wrong-item-kind.rs:126:5
@@ -619,6 +681,8 @@ error: trait is not supported in `trait`s or `impl`s
619681
|
620682
LL | default trait foo {}
621683
| ^^^^^^^^^^^^^^^^^
684+
|
685+
= help: consider moving the trait out to a nearby module scope
622686

623687
error: a trait alias cannot be `default`
624688
--> $DIR/default-on-wrong-item-kind.rs:128:5
@@ -633,12 +697,16 @@ error: trait alias is not supported in `trait`s or `impl`s
633697
|
634698
LL | default trait foo = Ord;
635699
| ^^^^^^^^^^^^^^^^^^^^^^^^
700+
|
701+
= help: consider moving the trait alias out to a nearby module scope
636702

637703
error: implementation is not supported in `trait`s or `impl`s
638704
--> $DIR/default-on-wrong-item-kind.rs:130:5
639705
|
640706
LL | default impl foo {}
641707
| ^^^^^^^^^^^^^^^^
708+
|
709+
= help: consider moving the implementation out to a nearby module scope
642710

643711
error: an item macro invocation cannot be `default`
644712
--> $DIR/default-on-wrong-item-kind.rs:134:5
@@ -669,6 +737,8 @@ error: macro definition is not supported in `trait`s or `impl`s
669737
|
670738
LL | default macro foo {}
671739
| ^^^^^^^^^^^^^^^^^
740+
|
741+
= help: consider moving the macro definition out to a nearby module scope
672742

673743
error: a macro definition cannot be `default`
674744
--> $DIR/default-on-wrong-item-kind.rs:138:5
@@ -683,6 +753,8 @@ error: macro definition is not supported in `trait`s or `impl`s
683753
|
684754
LL | default macro_rules! foo {}
685755
| ^^^^^^^^^^^^^^^^^^^^^^^^
756+
|
757+
= help: consider moving the macro definition out to a nearby module scope
686758

687759
error: aborting due to 95 previous errors
688760

src/test/ui/parser/issue-48137-macros-cannot-interpolate-impl-items-bad-variants.stderr

+9
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ error: struct is not supported in `trait`s or `impl`s
33
|
44
LL | struct BadS;
55
| ^^^^^^^^^^^^
6+
|
7+
= help: consider moving the struct out to a nearby module scope
68

79
error: enum is not supported in `trait`s or `impl`s
810
--> $DIR/issue-48137-macros-cannot-interpolate-impl-items-bad-variants.rs:5:9
@@ -13,13 +15,16 @@ LL | enum BadE {}
1315
LL | expand_to_enum!();
1416
| ------------------ in this macro invocation
1517
|
18+
= help: consider moving the enum out to a nearby module scope
1619
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
1720

1821
error: struct is not supported in `trait`s or `impl`s
1922
--> $DIR/issue-48137-macros-cannot-interpolate-impl-items-bad-variants.rs:31:5
2023
|
2124
LL | struct BadS;
2225
| ^^^^^^^^^^^^
26+
|
27+
= help: consider moving the struct out to a nearby module scope
2328

2429
error: enum is not supported in `trait`s or `impl`s
2530
--> $DIR/issue-48137-macros-cannot-interpolate-impl-items-bad-variants.rs:5:9
@@ -30,13 +35,16 @@ LL | enum BadE {}
3035
LL | expand_to_enum!();
3136
| ------------------ in this macro invocation
3237
|
38+
= help: consider moving the enum out to a nearby module scope
3339
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
3440

3541
error: struct is not supported in `extern` blocks
3642
--> $DIR/issue-48137-macros-cannot-interpolate-impl-items-bad-variants.rs:42:5
3743
|
3844
LL | struct BadS;
3945
| ^^^^^^^^^^^^
46+
|
47+
= help: consider moving the struct out to a nearby module scope
4048

4149
error: enum is not supported in `extern` blocks
4250
--> $DIR/issue-48137-macros-cannot-interpolate-impl-items-bad-variants.rs:5:9
@@ -47,6 +55,7 @@ LL | enum BadE {}
4755
LL | expand_to_enum!();
4856
| ------------------ in this macro invocation
4957
|
58+
= help: consider moving the enum out to a nearby module scope
5059
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
5160

5261
error: aborting due to 6 previous errors

0 commit comments

Comments
 (0)