]> git.lizzy.rs Git - rust.git/blob - src/test/ui-fulldeps/session-diagnostic/subdiagnostic-derive.rs
Revert parts of "use derive proc macro to impl SessionDiagnostic"
[rust.git] / src / test / ui-fulldeps / session-diagnostic / subdiagnostic-derive.rs
1 // check-fail
2 // Tests error conditions for specifying subdiagnostics using #[derive(SessionSubdiagnostic)]
3
4 // The proc_macro2 crate handles spans differently when on beta/stable release rather than nightly,
5 // changing the output of this test. Since SessionSubdiagnostic is strictly internal to the compiler
6 // the test is just ignored on stable and beta:
7 // ignore-beta
8 // ignore-stable
9
10 #![feature(rustc_private)]
11 #![crate_type = "lib"]
12
13 extern crate rustc_errors;
14 extern crate rustc_session;
15 extern crate rustc_span;
16 extern crate rustc_macros;
17
18 use rustc_errors::Applicability;
19 use rustc_span::Span;
20 use rustc_macros::SessionSubdiagnostic;
21
22 #[derive(SessionSubdiagnostic)]
23 #[label(parser::add_paren)]
24 struct A {
25     #[primary_span]
26     span: Span,
27     var: String,
28 }
29
30 #[derive(SessionSubdiagnostic)]
31 enum B {
32     #[label(parser::add_paren)]
33     A {
34         #[primary_span]
35         span: Span,
36         var: String,
37     },
38     #[label(parser::add_paren)]
39     B {
40         #[primary_span]
41         span: Span,
42         var: String,
43     }
44 }
45
46 #[derive(SessionSubdiagnostic)]
47 #[label(parser::add_paren)]
48 //~^ ERROR label without `#[primary_span]` field
49 struct C {
50     var: String,
51 }
52
53 #[derive(SessionSubdiagnostic)]
54 #[label]
55 //~^ ERROR `#[label]` is not a valid attribute
56 struct D {
57     #[primary_span]
58     span: Span,
59     var: String,
60 }
61
62 #[derive(SessionSubdiagnostic)]
63 #[foo]
64 //~^ ERROR `#[foo]` is not a valid attribute
65 //~^^ ERROR cannot find attribute `foo` in this scope
66 struct E {
67     #[primary_span]
68     span: Span,
69     var: String,
70 }
71
72 #[derive(SessionSubdiagnostic)]
73 #[label = "..."]
74 //~^ ERROR `#[label = ...]` is not a valid attribute
75 struct F {
76     #[primary_span]
77     span: Span,
78     var: String,
79 }
80
81 #[derive(SessionSubdiagnostic)]
82 #[label(bug = "...")]
83 //~^ ERROR `#[label(bug = ...)]` is not a valid attribute
84 struct G {
85     #[primary_span]
86     span: Span,
87     var: String,
88 }
89
90 #[derive(SessionSubdiagnostic)]
91 #[label("...")]
92 //~^ ERROR `#[label("...")]` is not a valid attribute
93 struct H {
94     #[primary_span]
95     span: Span,
96     var: String,
97 }
98
99 #[derive(SessionSubdiagnostic)]
100 #[label(slug = 4)]
101 //~^ ERROR `#[label(slug = ...)]` is not a valid attribute
102 struct J {
103     #[primary_span]
104     span: Span,
105     var: String,
106 }
107
108 #[derive(SessionSubdiagnostic)]
109 #[label(slug("..."))]
110 //~^ ERROR `#[label(slug(...))]` is not a valid attribute
111 struct K {
112     #[primary_span]
113     span: Span,
114     var: String,
115 }
116
117 #[derive(SessionSubdiagnostic)]
118 #[label(slug)]
119 //~^ ERROR cannot find value `slug` in module `rustc_errors::fluent`
120 //~^^ NOTE not found in `rustc_errors::fluent`
121 struct L {
122     #[primary_span]
123     span: Span,
124     var: String,
125 }
126
127 #[derive(SessionSubdiagnostic)]
128 #[label()]
129 //~^ ERROR diagnostic slug must be first argument of a `#[label(...)]` attribute
130 struct M {
131     #[primary_span]
132     span: Span,
133     var: String,
134 }
135
136 #[derive(SessionSubdiagnostic)]
137 #[label(parser::add_paren, code = "...")]
138 //~^ ERROR `code` is not a valid nested attribute of a `label` attribute
139 struct N {
140     #[primary_span]
141     span: Span,
142     var: String,
143 }
144
145 #[derive(SessionSubdiagnostic)]
146 #[label(parser::add_paren, applicability = "machine-applicable")]
147 //~^ ERROR `applicability` is not a valid nested attribute of a `label` attribute
148 struct O {
149     #[primary_span]
150     span: Span,
151     var: String,
152 }
153
154 #[derive(SessionSubdiagnostic)]
155 #[foo]
156 //~^ ERROR cannot find attribute `foo` in this scope
157 //~^^ ERROR unsupported type attribute for subdiagnostic enum
158 enum P {
159     #[label(parser::add_paren)]
160     A {
161         #[primary_span]
162         span: Span,
163         var: String,
164     }
165 }
166
167 #[derive(SessionSubdiagnostic)]
168 enum Q {
169     #[bar]
170     //~^ ERROR `#[bar]` is not a valid attribute
171     //~^^ ERROR cannot find attribute `bar` in this scope
172     A {
173         #[primary_span]
174         span: Span,
175         var: String,
176     }
177 }
178
179 #[derive(SessionSubdiagnostic)]
180 enum R {
181     #[bar = "..."]
182     //~^ ERROR `#[bar = ...]` is not a valid attribute
183     //~^^ ERROR cannot find attribute `bar` in this scope
184     A {
185         #[primary_span]
186         span: Span,
187         var: String,
188     }
189 }
190
191 #[derive(SessionSubdiagnostic)]
192 enum S {
193     #[bar = 4]
194     //~^ ERROR `#[bar = ...]` is not a valid attribute
195     //~^^ ERROR cannot find attribute `bar` in this scope
196     A {
197         #[primary_span]
198         span: Span,
199         var: String,
200     }
201 }
202
203 #[derive(SessionSubdiagnostic)]
204 enum T {
205     #[bar("...")]
206     //~^ ERROR `#[bar(...)]` is not a valid attribute
207     //~^^ ERROR cannot find attribute `bar` in this scope
208     A {
209         #[primary_span]
210         span: Span,
211         var: String,
212     }
213 }
214
215 #[derive(SessionSubdiagnostic)]
216 enum U {
217     #[label(code = "...")]
218     //~^ ERROR diagnostic slug must be first argument of a `#[label(...)]` attribute
219     A {
220         #[primary_span]
221         span: Span,
222         var: String,
223     }
224 }
225
226 #[derive(SessionSubdiagnostic)]
227 enum V {
228     #[label(parser::add_paren)]
229     A {
230         #[primary_span]
231         span: Span,
232         var: String,
233     },
234     B {
235     //~^ ERROR subdiagnostic kind not specified
236         #[primary_span]
237         span: Span,
238         var: String,
239     }
240 }
241
242 #[derive(SessionSubdiagnostic)]
243 #[label(parser::add_paren)]
244 //~^ ERROR label without `#[primary_span]` field
245 struct W {
246     #[primary_span]
247     //~^ ERROR the `#[primary_span]` attribute can only be applied to fields of type `Span` or `MultiSpan`
248     span: String,
249 }
250
251 #[derive(SessionSubdiagnostic)]
252 #[label(parser::add_paren)]
253 struct X {
254     #[primary_span]
255     span: Span,
256     #[applicability]
257     //~^ ERROR `#[applicability]` is only valid on suggestions
258     applicability: Applicability,
259 }
260
261 #[derive(SessionSubdiagnostic)]
262 #[label(parser::add_paren)]
263 struct Y {
264     #[primary_span]
265     span: Span,
266     #[bar]
267     //~^ ERROR `#[bar]` is not a valid attribute
268     //~^^ ERROR cannot find attribute `bar` in this scope
269     bar: String,
270 }
271
272 #[derive(SessionSubdiagnostic)]
273 #[label(parser::add_paren)]
274 struct Z {
275     #[primary_span]
276     span: Span,
277     #[bar = "..."]
278     //~^ ERROR `#[bar = ...]` is not a valid attribute
279     //~^^ ERROR cannot find attribute `bar` in this scope
280     bar: String,
281 }
282
283 #[derive(SessionSubdiagnostic)]
284 #[label(parser::add_paren)]
285 struct AA {
286     #[primary_span]
287     span: Span,
288     #[bar("...")]
289     //~^ ERROR `#[bar(...)]` is not a valid attribute
290     //~^^ ERROR cannot find attribute `bar` in this scope
291     bar: String,
292 }
293
294 #[derive(SessionSubdiagnostic)]
295 #[label(parser::add_paren)]
296 struct AB {
297     #[primary_span]
298     span: Span,
299     #[skip_arg]
300     z: Z
301 }
302
303 #[derive(SessionSubdiagnostic)]
304 union AC {
305 //~^ ERROR unexpected unsupported untagged union
306     span: u32,
307     b: u64
308 }
309
310 #[derive(SessionSubdiagnostic)]
311 #[label(parser::add_paren)]
312 //~^ NOTE previously specified here
313 #[label(parser::add_paren)]
314 //~^ ERROR specified multiple times
315 struct AD {
316     #[primary_span]
317     span: Span,
318 }
319
320 #[derive(SessionSubdiagnostic)]
321 #[label(parser::add_paren, parser::add_paren)]
322 //~^ ERROR `#[label(parser::add_paren)]` is not a valid attribute
323 struct AE {
324     #[primary_span]
325     span: Span,
326 }
327
328 #[derive(SessionSubdiagnostic)]
329 #[label(parser::add_paren)]
330 struct AF {
331     #[primary_span]
332     //~^ NOTE previously specified here
333     span_a: Span,
334     #[primary_span]
335     //~^ ERROR specified multiple times
336     span_b: Span,
337 }
338
339 #[derive(SessionSubdiagnostic)]
340 struct AG {
341     //~^ ERROR subdiagnostic kind not specified
342     #[primary_span]
343     span: Span,
344 }
345
346 #[derive(SessionSubdiagnostic)]
347 #[suggestion(parser::add_paren, code = "...")]
348 struct AH {
349     #[primary_span]
350     span: Span,
351     #[applicability]
352     applicability: Applicability,
353     var: String,
354 }
355
356 #[derive(SessionSubdiagnostic)]
357 enum AI {
358     #[suggestion(parser::add_paren, code = "...")]
359     A {
360         #[primary_span]
361         span: Span,
362         #[applicability]
363         applicability: Applicability,
364         var: String,
365     },
366     #[suggestion(parser::add_paren, code = "...")]
367     B {
368         #[primary_span]
369         span: Span,
370         #[applicability]
371         applicability: Applicability,
372         var: String,
373     }
374 }
375
376 #[derive(SessionSubdiagnostic)]
377 #[suggestion(parser::add_paren, code = "...", code = "...")]
378 //~^ ERROR specified multiple times
379 //~^^ NOTE previously specified here
380 struct AJ {
381     #[primary_span]
382     span: Span,
383     #[applicability]
384     applicability: Applicability,
385 }
386
387 #[derive(SessionSubdiagnostic)]
388 #[suggestion(parser::add_paren, code = "...")]
389 struct AK {
390     #[primary_span]
391     span: Span,
392     #[applicability]
393     //~^ NOTE previously specified here
394     applicability_a: Applicability,
395     #[applicability]
396     //~^ ERROR specified multiple times
397     applicability_b: Applicability,
398 }
399
400 #[derive(SessionSubdiagnostic)]
401 #[suggestion(parser::add_paren, code = "...")]
402 struct AL {
403     #[primary_span]
404     span: Span,
405     #[applicability]
406     //~^ ERROR the `#[applicability]` attribute can only be applied to fields of type `Applicability`
407     applicability: Span,
408 }
409
410 #[derive(SessionSubdiagnostic)]
411 #[suggestion(parser::add_paren, code = "...")]
412 struct AM {
413     #[primary_span]
414     span: Span,
415 }
416
417 #[derive(SessionSubdiagnostic)]
418 #[suggestion(parser::add_paren)]
419 //~^ ERROR suggestion without `code = "..."`
420 struct AN {
421     #[primary_span]
422     span: Span,
423     #[applicability]
424     applicability: Applicability,
425 }
426
427 #[derive(SessionSubdiagnostic)]
428 #[suggestion(parser::add_paren, code ="...", applicability = "foo")]
429 //~^ ERROR invalid applicability
430 struct AO {
431     #[primary_span]
432     span: Span,
433 }
434
435 #[derive(SessionSubdiagnostic)]
436 #[help(parser::add_paren)]
437 struct AP {
438     var: String
439 }
440
441 #[derive(SessionSubdiagnostic)]
442 #[note(parser::add_paren)]
443 struct AQ;
444
445 #[derive(SessionSubdiagnostic)]
446 #[suggestion(parser::add_paren, code = "...")]
447 //~^ ERROR suggestion without `#[primary_span]` field
448 struct AR {
449     var: String,
450 }
451
452 #[derive(SessionSubdiagnostic)]
453 #[suggestion(parser::add_paren, code ="...", applicability = "machine-applicable")]
454 struct AS {
455     #[primary_span]
456     span: Span,
457 }
458
459 #[derive(SessionSubdiagnostic)]
460 #[label]
461 //~^ ERROR unsupported type attribute for subdiagnostic enum
462 enum AT {
463     #[label(parser::add_paren)]
464     A {
465         #[primary_span]
466         span: Span,
467         var: String,
468     }
469 }
470
471 #[derive(SessionSubdiagnostic)]
472 #[suggestion(parser::add_paren, code ="{var}", applicability = "machine-applicable")]
473 struct AU {
474     #[primary_span]
475     span: Span,
476     var: String,
477 }
478
479 #[derive(SessionSubdiagnostic)]
480 #[suggestion(parser::add_paren, code ="{var}", applicability = "machine-applicable")]
481 //~^ ERROR `var` doesn't refer to a field on this type
482 struct AV {
483     #[primary_span]
484     span: Span,
485 }
486
487 #[derive(SessionSubdiagnostic)]
488 enum AW {
489     #[suggestion(parser::add_paren, code ="{var}", applicability = "machine-applicable")]
490     A {
491         #[primary_span]
492         span: Span,
493         var: String,
494     }
495 }
496
497 #[derive(SessionSubdiagnostic)]
498 enum AX {
499     #[suggestion(parser::add_paren, code ="{var}", applicability = "machine-applicable")]
500 //~^ ERROR `var` doesn't refer to a field on this type
501     A {
502         #[primary_span]
503         span: Span,
504     }
505 }
506
507 #[derive(SessionSubdiagnostic)]
508 #[warning(parser::add_paren)]
509 struct AY {}
510
511 #[derive(SessionSubdiagnostic)]
512 #[warning(parser::add_paren)]
513 struct AZ {
514     #[primary_span]
515     span: Span,
516 }
517
518 #[derive(SessionSubdiagnostic)]
519 #[suggestion(parser::add_paren, code = "...")]
520 //~^ ERROR suggestion without `#[primary_span]` field
521 struct BA {
522     #[suggestion_part]
523     //~^ ERROR `#[suggestion_part]` is not a valid attribute
524     span: Span,
525     #[suggestion_part(code = "...")]
526     //~^ ERROR `#[suggestion_part(...)]` is not a valid attribute
527     span2: Span,
528     #[applicability]
529     applicability: Applicability,
530     var: String,
531 }
532
533 #[derive(SessionSubdiagnostic)]
534 #[multipart_suggestion(parser::add_paren, code = "...", applicability = "machine-applicable")]
535 //~^ ERROR multipart suggestion without any `#[suggestion_part(...)]` fields
536 //~| ERROR `code` is not a valid nested attribute of a `multipart_suggestion` attribute
537 struct BBa {
538     var: String,
539 }
540
541 #[derive(SessionSubdiagnostic)]
542 #[multipart_suggestion(parser::add_paren, applicability = "machine-applicable")]
543 struct BBb {
544     #[suggestion_part]
545     //~^ ERROR `#[suggestion_part(...)]` attribute without `code = "..."`
546     span1: Span,
547 }
548
549 #[derive(SessionSubdiagnostic)]
550 #[multipart_suggestion(parser::add_paren, applicability = "machine-applicable")]
551 struct BBc {
552     #[suggestion_part()]
553     //~^ ERROR `#[suggestion_part(...)]` attribute without `code = "..."`
554     span1: Span,
555 }
556
557 #[derive(SessionSubdiagnostic)]
558 #[multipart_suggestion(parser::add_paren)]
559 //~^ ERROR multipart suggestion without any `#[suggestion_part(...)]` fields
560 struct BC {
561     #[primary_span]
562     //~^ ERROR `#[primary_span]` is not a valid attribute
563     span: Span,
564 }
565
566 #[derive(SessionSubdiagnostic)]
567 #[multipart_suggestion(parser::add_paren)]
568 struct BD {
569     #[suggestion_part]
570     //~^ ERROR `#[suggestion_part(...)]` attribute without `code = "..."`
571     span1: Span,
572     #[suggestion_part()]
573     //~^ ERROR `#[suggestion_part(...)]` attribute without `code = "..."`
574     span2: Span,
575     #[suggestion_part(foo = "bar")]
576     //~^ ERROR `#[suggestion_part(foo = ...)]` is not a valid attribute
577     span4: Span,
578     #[suggestion_part(code = "...")]
579     //~^ ERROR the `#[suggestion_part(...)]` attribute can only be applied to fields of type `Span` or `MultiSpan`
580     s1: String,
581     #[suggestion_part()]
582     //~^ ERROR the `#[suggestion_part(...)]` attribute can only be applied to fields of type `Span` or `MultiSpan`
583     s2: String,
584 }
585
586 #[derive(SessionSubdiagnostic)]
587 #[multipart_suggestion(parser::add_paren, applicability = "machine-applicable")]
588 struct BE {
589     #[suggestion_part(code = "...", code = ",,,")]
590     //~^ ERROR specified multiple times
591     //~| NOTE previously specified here
592     span: Span,
593 }
594
595 #[derive(SessionSubdiagnostic)]
596 #[multipart_suggestion(parser::add_paren, applicability = "machine-applicable")]
597 struct BF {
598     #[suggestion_part(code = "(")]
599     first: Span,
600     #[suggestion_part(code = ")")]
601     second: Span,
602 }
603
604 #[derive(SessionSubdiagnostic)]
605 #[multipart_suggestion(parser::add_paren)]
606 struct BG {
607     #[applicability]
608     appl: Applicability,
609     #[suggestion_part(code = "(")]
610     first: Span,
611     #[suggestion_part(code = ")")]
612     second: Span,
613 }
614
615 #[derive(SessionSubdiagnostic)]
616 #[multipart_suggestion(parser::add_paren, applicability = "machine-applicable")]
617 //~^ NOTE previously specified here
618 struct BH {
619     #[applicability]
620     //~^ ERROR specified multiple times
621     appl: Applicability,
622     #[suggestion_part(code = "(")]
623     first: Span,
624     #[suggestion_part(code = ")")]
625     second: Span,
626 }
627
628 #[derive(SessionSubdiagnostic)]
629 #[multipart_suggestion(parser::add_paren, applicability = "machine-applicable")]
630 struct BI {
631     #[suggestion_part(code = "")]
632     spans: Vec<Span>,
633 }