Skip to content

Commit 6ace2b3

Browse files
committed
fix diagnostic derive
1 parent f4f6f8a commit 6ace2b3

File tree

5 files changed

+137
-156
lines changed

5 files changed

+137
-156
lines changed

compiler/rustc_macros/src/diagnostics/subdiagnostic.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ impl<'parent, 'a> SubdiagnosticDeriveVariantBuilder<'parent, 'a> {
202202
(None, None) => {
203203
throw_span_err!(
204204
attr.span().unwrap(),
205-
"diagnostic slug or raw_label must be first argument of a `#[{name}(...)]` attribute"
205+
"diagnostic slug or raw_label must be first argument of a attribute"
206206
);
207207
}
208208
(Some(_), Some(_)) => {

tests/ui-fulldeps/session-diagnostic/diagnostic-derive.rs

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@ struct HelloWarn {}
4444
//~^ ERROR unsupported type attribute for diagnostic derive enum
4545
enum DiagnosticOnEnum {
4646
Foo,
47-
//~^ ERROR diagnostic slug not specified
47+
//~^ ERROR diagnostic slug or label is not specified
4848
Bar,
49-
//~^ ERROR diagnostic slug not specified
49+
//~^ ERROR diagnostic slug or label is not specified
5050
}
5151

5252
#[derive(Diagnostic)]
@@ -58,13 +58,12 @@ struct WrongStructAttrStyle {}
5858
#[derive(Diagnostic)]
5959
#[nonsense(no_crate_example, code = "E0123")]
6060
//~^ ERROR `#[nonsense(...)]` is not a valid attribute
61-
//~^^ ERROR diagnostic slug not specified
61+
//~^^ ERROR diagnostic slug or label is not specified
6262
//~^^^ ERROR cannot find attribute `nonsense` in this scope
6363
struct InvalidStructAttr {}
6464

6565
#[derive(Diagnostic)]
6666
#[diag("E0123")]
67-
//~^ ERROR diagnostic slug not specified
6867
struct InvalidLitNestedAttr {}
6968

7069
#[derive(Diagnostic)]
@@ -74,20 +73,20 @@ struct InvalidNestedStructAttr {}
7473

7574
#[derive(Diagnostic)]
7675
#[diag(nonsense("foo"), code = "E0123", slug = "foo")]
77-
//~^ ERROR diagnostic slug must be the first argument
78-
//~| ERROR diagnostic slug not specified
76+
//~^ ERROR diagnostic slug or label is not specified
77+
//~| ERROR diagnostic slug must be the first argument
7978
struct InvalidNestedStructAttr1 {}
8079

8180
#[derive(Diagnostic)]
8281
#[diag(nonsense = "...", code = "E0123", slug = "foo")]
8382
//~^ ERROR unknown argument
84-
//~| ERROR diagnostic slug not specified
83+
//~| ERROR diagnostic slug or label is not specified
8584
struct InvalidNestedStructAttr2 {}
8685

8786
#[derive(Diagnostic)]
8887
#[diag(nonsense = 4, code = "E0123", slug = "foo")]
8988
//~^ ERROR unknown argument
90-
//~| ERROR diagnostic slug not specified
89+
//~| ERROR diagnostic slug or label is not specified
9190
struct InvalidNestedStructAttr3 {}
9291

9392
#[derive(Diagnostic)]
@@ -121,11 +120,11 @@ struct CodeSpecifiedTwice {}
121120
struct SlugSpecifiedTwice {}
122121

123122
#[derive(Diagnostic)]
124-
struct KindNotProvided {} //~ ERROR diagnostic slug not specified
123+
struct KindNotProvided {} //~ ERROR diagnostic slug or label is not specified
125124

126125
#[derive(Diagnostic)]
127126
#[diag(code = "E0456")]
128-
//~^ ERROR diagnostic slug not specified
127+
//~^ ERROR diagnostic slug or label is not specified
129128
struct SlugNotProvided {}
130129

131130
#[derive(Diagnostic)]
@@ -578,21 +577,21 @@ struct ErrorWithWarn {
578577
#[derive(Diagnostic)]
579578
#[error(no_crate_example, code = "E0123")]
580579
//~^ ERROR `#[error(...)]` is not a valid attribute
581-
//~| ERROR diagnostic slug not specified
580+
//~| ERROR diagnostic slug or label is not specified
582581
//~| ERROR cannot find attribute `error` in this scope
583582
struct ErrorAttribute {}
584583

585584
#[derive(Diagnostic)]
586585
#[warn_(no_crate_example, code = "E0123")]
587586
//~^ ERROR `#[warn_(...)]` is not a valid attribute
588-
//~| ERROR diagnostic slug not specified
587+
//~| ERROR diagnostic slug or label is not specified
589588
//~| ERROR cannot find attribute `warn_` in this scope
590589
struct WarnAttribute {}
591590

592591
#[derive(Diagnostic)]
593592
#[lint(no_crate_example, code = "E0123")]
594593
//~^ ERROR `#[lint(...)]` is not a valid attribute
595-
//~| ERROR diagnostic slug not specified
594+
//~| ERROR diagnostic slug or label is not specified
596595
//~| ERROR cannot find attribute `lint` in this scope
597596
struct LintAttributeOnSessionDiag {}
598597

tests/ui-fulldeps/session-diagnostic/diagnostic-derive.stderr

Lines changed: 26 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -4,30 +4,30 @@ error: unsupported type attribute for diagnostic derive enum
44
LL | #[diag(no_crate_example, code = "E0123")]
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
66

7-
error: diagnostic slug not specified
8-
--> $DIR/diagnostic-derive.rs:46:5
7+
error: diagnostic slug or label is not specified
8+
--> $DIR/diagnostic-derive.rs:47:5
99
|
1010
LL | Foo,
1111
| ^^^
1212
|
13-
= help: specify the slug as the first argument to the `#[diag(...)]` attribute, such as `#[diag(hir_analysis_example_error)]`
13+
= help: specify the slug as the first argument to the `#[diag(...)]` attribute, such as `#[diag(hir_analysis_example_error)]`, or use format #[diag(label = "the message ..")]
1414

15-
error: diagnostic slug not specified
16-
--> $DIR/diagnostic-derive.rs:48:5
15+
error: diagnostic slug or label is not specified
16+
--> $DIR/diagnostic-derive.rs:49:5
1717
|
1818
LL | Bar,
1919
| ^^^
2020
|
21-
= help: specify the slug as the first argument to the `#[diag(...)]` attribute, such as `#[diag(hir_analysis_example_error)]`
21+
= help: specify the slug as the first argument to the `#[diag(...)]` attribute, such as `#[diag(hir_analysis_example_error)]`, or use format #[diag(label = "the message ..")]
2222

2323
error: `#[nonsense(...)]` is not a valid attribute
2424
--> $DIR/diagnostic-derive.rs:59:1
2525
|
2626
LL | #[nonsense(no_crate_example, code = "E0123")]
2727
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2828

29-
error: diagnostic slug not specified
30-
--> $DIR/diagnostic-derive.rs:59:1
29+
error: diagnostic slug or label is not specified
30+
--> $DIR/diagnostic-derive.rs:60:1
3131
|
3232
LL | / #[nonsense(no_crate_example, code = "E0123")]
3333
LL | |
@@ -36,25 +36,15 @@ LL | |
3636
LL | | struct InvalidStructAttr {}
3737
| |___________________________^
3838
|
39-
= help: specify the slug as the first argument to the `#[diag(...)]` attribute, such as `#[diag(hir_analysis_example_error)]`
40-
41-
error: diagnostic slug not specified
42-
--> $DIR/diagnostic-derive.rs:66:1
43-
|
44-
LL | / #[diag("E0123")]
45-
LL | |
46-
LL | | struct InvalidLitNestedAttr {}
47-
| |______________________________^
48-
|
49-
= help: specify the slug as the first argument to the `#[diag(...)]` attribute, such as `#[diag(hir_analysis_example_error)]`
39+
= help: specify the slug as the first argument to the `#[diag(...)]` attribute, such as `#[diag(hir_analysis_example_error)]`, or use format #[diag(label = "the message ..")]
5040

5141
error: diagnostic slug must be the first argument
5242
--> $DIR/diagnostic-derive.rs:76:16
5343
|
5444
LL | #[diag(nonsense("foo"), code = "E0123", slug = "foo")]
5545
| ^
5646

57-
error: diagnostic slug not specified
47+
error: diagnostic slug or label is not specified
5848
--> $DIR/diagnostic-derive.rs:76:1
5949
|
6050
LL | / #[diag(nonsense("foo"), code = "E0123", slug = "foo")]
@@ -63,7 +53,7 @@ LL | |
6353
LL | | struct InvalidNestedStructAttr1 {}
6454
| |__________________________________^
6555
|
66-
= help: specify the slug as the first argument to the `#[diag(...)]` attribute, such as `#[diag(hir_analysis_example_error)]`
56+
= help: specify the slug as the first argument to the `#[diag(...)]` attribute, such as `#[diag(hir_analysis_example_error)]`, or use format #[diag(label = "the message ..")]
6757

6858
error: unknown argument
6959
--> $DIR/diagnostic-derive.rs:82:8
@@ -73,7 +63,7 @@ LL | #[diag(nonsense = "...", code = "E0123", slug = "foo")]
7363
|
7464
= note: only the `code` parameter is valid after the slug
7565

76-
error: diagnostic slug not specified
66+
error: diagnostic slug or label is not specified
7767
--> $DIR/diagnostic-derive.rs:82:1
7868
|
7969
LL | / #[diag(nonsense = "...", code = "E0123", slug = "foo")]
@@ -82,7 +72,7 @@ LL | |
8272
LL | | struct InvalidNestedStructAttr2 {}
8373
| |__________________________________^
8474
|
85-
= help: specify the slug as the first argument to the `#[diag(...)]` attribute, such as `#[diag(hir_analysis_example_error)]`
75+
= help: specify the slug as the first argument to the `#[diag(...)]` attribute, such as `#[diag(hir_analysis_example_error)]`, or use format #[diag(label = "the message ..")]
8676

8777
error: unknown argument
8878
--> $DIR/diagnostic-derive.rs:88:8
@@ -92,7 +82,7 @@ LL | #[diag(nonsense = 4, code = "E0123", slug = "foo")]
9282
|
9383
= note: only the `code` parameter is valid after the slug
9484

95-
error: diagnostic slug not specified
85+
error: diagnostic slug or label is not specified
9686
--> $DIR/diagnostic-derive.rs:88:1
9787
|
9888
LL | / #[diag(nonsense = 4, code = "E0123", slug = "foo")]
@@ -101,7 +91,7 @@ LL | |
10191
LL | | struct InvalidNestedStructAttr3 {}
10292
| |__________________________________^
10393
|
104-
= help: specify the slug as the first argument to the `#[diag(...)]` attribute, such as `#[diag(hir_analysis_example_error)]`
94+
= help: specify the slug as the first argument to the `#[diag(...)]` attribute, such as `#[diag(hir_analysis_example_error)]`, or use format #[diag(label = "the message ..")]
10595

10696
error: unknown argument
10797
--> $DIR/diagnostic-derive.rs:94:42
@@ -159,23 +149,23 @@ error: diagnostic slug must be the first argument
159149
LL | #[diag(no_crate_example, no_crate::example, code = "E0456")]
160150
| ^
161151

162-
error: diagnostic slug not specified
152+
error: diagnostic slug or label is not specified
163153
--> $DIR/diagnostic-derive.rs:124:1
164154
|
165155
LL | struct KindNotProvided {}
166156
| ^^^^^^^^^^^^^^^^^^^^^^^^^
167157
|
168-
= help: specify the slug as the first argument to the `#[diag(...)]` attribute, such as `#[diag(hir_analysis_example_error)]`
158+
= help: specify the slug as the first argument to the `#[diag(...)]` attribute, such as `#[diag(hir_analysis_example_error)]`, or use format #[diag(label = "the message ..")]
169159

170-
error: diagnostic slug not specified
160+
error: diagnostic slug or label is not specified
171161
--> $DIR/diagnostic-derive.rs:127:1
172162
|
173163
LL | / #[diag(code = "E0456")]
174164
LL | |
175165
LL | | struct SlugNotProvided {}
176166
| |_________________________^
177167
|
178-
= help: specify the slug as the first argument to the `#[diag(...)]` attribute, such as `#[diag(hir_analysis_example_error)]`
168+
= help: specify the slug as the first argument to the `#[diag(...)]` attribute, such as `#[diag(hir_analysis_example_error)]`, or use format #[diag(label = "the message ..")]
179169

180170
error: the `#[primary_span]` attribute can only be applied to fields of type `Span` or `MultiSpan`
181171
--> $DIR/diagnostic-derive.rs:138:5
@@ -355,7 +345,7 @@ error: `#[error(...)]` is not a valid attribute
355345
LL | #[error(no_crate_example, code = "E0123")]
356346
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
357347

358-
error: diagnostic slug not specified
348+
error: diagnostic slug or label is not specified
359349
--> $DIR/diagnostic-derive.rs:579:1
360350
|
361351
LL | / #[error(no_crate_example, code = "E0123")]
@@ -365,15 +355,15 @@ LL | |
365355
LL | | struct ErrorAttribute {}
366356
| |________________________^
367357
|
368-
= help: specify the slug as the first argument to the `#[diag(...)]` attribute, such as `#[diag(hir_analysis_example_error)]`
358+
= help: specify the slug as the first argument to the `#[diag(...)]` attribute, such as `#[diag(hir_analysis_example_error)]`, or use format #[diag(label = "the message ..")]
369359

370360
error: `#[warn_(...)]` is not a valid attribute
371361
--> $DIR/diagnostic-derive.rs:586:1
372362
|
373363
LL | #[warn_(no_crate_example, code = "E0123")]
374364
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
375365

376-
error: diagnostic slug not specified
366+
error: diagnostic slug or label is not specified
377367
--> $DIR/diagnostic-derive.rs:586:1
378368
|
379369
LL | / #[warn_(no_crate_example, code = "E0123")]
@@ -383,15 +373,15 @@ LL | |
383373
LL | | struct WarnAttribute {}
384374
| |_______________________^
385375
|
386-
= help: specify the slug as the first argument to the `#[diag(...)]` attribute, such as `#[diag(hir_analysis_example_error)]`
376+
= help: specify the slug as the first argument to the `#[diag(...)]` attribute, such as `#[diag(hir_analysis_example_error)]`, or use format #[diag(label = "the message ..")]
387377

388378
error: `#[lint(...)]` is not a valid attribute
389379
--> $DIR/diagnostic-derive.rs:593:1
390380
|
391381
LL | #[lint(no_crate_example, code = "E0123")]
392382
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
393383

394-
error: diagnostic slug not specified
384+
error: diagnostic slug or label is not specified
395385
--> $DIR/diagnostic-derive.rs:593:1
396386
|
397387
LL | / #[lint(no_crate_example, code = "E0123")]
@@ -401,7 +391,7 @@ LL | |
401391
LL | | struct LintAttributeOnSessionDiag {}
402392
| |____________________________________^
403393
|
404-
= help: specify the slug as the first argument to the `#[diag(...)]` attribute, such as `#[diag(hir_analysis_example_error)]`
394+
= help: specify the slug as the first argument to the `#[diag(...)]` attribute, such as `#[diag(hir_analysis_example_error)]`, or use format #[diag(label = "the message ..")]
405395

406396
error: `#[lint(...)]` is not a valid attribute
407397
--> $DIR/diagnostic-derive.rs:600:1
@@ -658,7 +648,7 @@ note: required by a bound in `DiagnosticBuilder::<'a, G>::set_arg`
658648
--> $COMPILER_DIR/rustc_errors/src/diagnostic_builder.rs:LL:CC
659649
= note: this error originates in the macro `forward` (in Nightly builds, run with -Z macro-backtrace for more info)
660650

661-
error: aborting due to 84 previous errors
651+
error: aborting due to 83 previous errors
662652

663653
Some errors have detailed explanations: E0277, E0425, E0433.
664654
For more information about an error, try `rustc --explain E0277`.

tests/ui-fulldeps/session-diagnostic/subdiagnostic-derive.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ struct C {
5656

5757
#[derive(Subdiagnostic)]
5858
#[label]
59-
//~^ ERROR diagnostic slug must be first argument
59+
//~^ ERROR diagnostic slug or raw_label must be first argument of
6060
struct D {
6161
#[primary_span]
6262
span: Span,
@@ -85,7 +85,7 @@ struct F {
8585
#[derive(Subdiagnostic)]
8686
#[label(bug = "...")]
8787
//~^ ERROR only `no_span` is a valid nested attribute
88-
//~| ERROR diagnostic slug must be first argument
88+
//~| ERROR diagnostic slug or raw_label must be first argument of
8989
struct G {
9090
#[primary_span]
9191
span: Span,
@@ -94,8 +94,6 @@ struct G {
9494

9595
#[derive(Subdiagnostic)]
9696
#[label("...")]
97-
//~^ ERROR failed to resolve: maybe a missing crate `core`?
98-
//~| NOTE maybe a missing crate `core`?
9997
struct H {
10098
#[primary_span]
10199
span: Span,
@@ -105,7 +103,7 @@ struct H {
105103
#[derive(Subdiagnostic)]
106104
#[label(slug = 4)]
107105
//~^ ERROR only `no_span` is a valid nested attribute
108-
//~| ERROR diagnostic slug must be first argument
106+
//~| ERROR diagnostic slug or raw_label must be first argument of
109107
struct J {
110108
#[primary_span]
111109
span: Span,
@@ -115,7 +113,7 @@ struct J {
115113
#[derive(Subdiagnostic)]
116114
#[label(slug("..."))]
117115
//~^ ERROR only `no_span` is a valid nested attribute
118-
//~| ERROR diagnostic slug must be first argument
116+
//~| ERROR diagnostic slug or raw_label must be first argument of
119117
struct K {
120118
#[primary_span]
121119
span: Span,
@@ -134,7 +132,7 @@ struct L {
134132

135133
#[derive(Subdiagnostic)]
136134
#[label()]
137-
//~^ ERROR diagnostic slug must be first argument of a `#[label(...)]` attribute
135+
//~^ ERROR diagnostic slug or raw_label must be first argument of a attribute
138136
struct M {
139137
#[primary_span]
140138
span: Span,
@@ -223,7 +221,7 @@ enum T {
223221
#[derive(Subdiagnostic)]
224222
enum U {
225223
#[label(code = "...")]
226-
//~^ ERROR diagnostic slug must be first argument of a `#[label(...)]` attribute
224+
//~^ ERROR diagnostic slug or raw_label must be first argument of a attribute
227225
//~| ERROR only `no_span` is a valid nested attribute
228226
A {
229227
#[primary_span]

0 commit comments

Comments
 (0)