]>
git.proxmox.com Git - rustc.git/blob - src/test/ui-fulldeps/session-diagnostic/subdiagnostic-derive.rs
2 // Tests error conditions for specifying subdiagnostics using #[derive(Subdiagnostic)]
4 // The proc_macro2 crate handles spans differently when on beta/stable release rather than nightly,
5 // changing the output of this test. Since Subdiagnostic is strictly internal to the compiler
6 // the test is just ignored on stable and beta:
10 #![feature(rustc_private)]
11 #![crate_type = "lib"]
13 extern crate rustc_errors
;
14 extern crate rustc_session
;
15 extern crate rustc_span
;
16 extern crate rustc_macros
;
18 use rustc_errors
::Applicability
;
20 use rustc_macros
::Subdiagnostic
;
22 #[derive(Subdiagnostic)]
23 #[label(parser_add_paren)]
30 #[derive(Subdiagnostic)]
32 #[label(parser_add_paren)]
38 #[label(parser_add_paren)]
46 #[derive(Subdiagnostic)]
47 #[label(parser_add_paren)]
48 //~^ ERROR label without `#[primary_span]` field
53 #[derive(Subdiagnostic)]
55 //~^ ERROR diagnostic slug must be first argument
62 #[derive(Subdiagnostic)]
64 //~^ ERROR `#[foo]` is not a valid attribute
65 //~^^ ERROR cannot find attribute `foo` in this scope
72 #[derive(Subdiagnostic)]
74 //~^ ERROR `#[label = ...]` is not a valid attribute
81 #[derive(Subdiagnostic)]
83 //~^ ERROR `#[label(bug = ...)]` is not a valid attribute
84 //~| ERROR diagnostic slug must be first argument
91 #[derive(Subdiagnostic)]
93 //~^ ERROR `#[label("...")]` is not a valid attribute
94 //~| ERROR diagnostic slug must be first argument
101 #[derive(Subdiagnostic)]
103 //~^ ERROR `#[label(slug = ...)]` is not a valid attribute
104 //~| ERROR diagnostic slug must be first argument
111 #[derive(Subdiagnostic)]
112 #[label(slug("..."))]
113 //~^ ERROR `#[label(slug(...))]` is not a valid attribute
114 //~| ERROR diagnostic slug must be first argument
121 #[derive(Subdiagnostic)]
123 //~^ ERROR cannot find value `slug` in module `rustc_errors::fluent`
124 //~^^ NOTE not found in `rustc_errors::fluent`
131 #[derive(Subdiagnostic)]
133 //~^ ERROR diagnostic slug must be first argument of a `#[label(...)]` attribute
140 #[derive(Subdiagnostic)]
141 #[label(parser_add_paren, code = "...")]
142 //~^ ERROR `#[label(code = ...)]` is not a valid attribute
149 #[derive(Subdiagnostic)]
150 #[label(parser_add_paren, applicability = "machine-applicable")]
151 //~^ ERROR `#[label(applicability = ...)]` is not a valid attribute
158 #[derive(Subdiagnostic)]
160 //~^ ERROR cannot find attribute `foo` in this scope
161 //~^^ ERROR unsupported type attribute for subdiagnostic enum
163 #[label(parser_add_paren)]
171 #[derive(Subdiagnostic)]
174 //~^ ERROR `#[bar]` is not a valid attribute
175 //~^^ ERROR cannot find attribute `bar` in this scope
183 #[derive(Subdiagnostic)]
186 //~^ ERROR `#[bar = ...]` is not a valid attribute
187 //~^^ ERROR cannot find attribute `bar` in this scope
195 #[derive(Subdiagnostic)]
198 //~^ ERROR `#[bar = ...]` is not a valid attribute
199 //~^^ ERROR cannot find attribute `bar` in this scope
207 #[derive(Subdiagnostic)]
210 //~^ ERROR `#[bar(...)]` is not a valid attribute
211 //~^^ ERROR cannot find attribute `bar` in this scope
219 #[derive(Subdiagnostic)]
221 #[label(code = "...")]
222 //~^ ERROR diagnostic slug must be first argument of a `#[label(...)]` attribute
223 //~| ERROR `#[label(code = ...)]` is not a valid attribute
231 #[derive(Subdiagnostic)]
233 #[label(parser_add_paren)]
246 #[derive(Subdiagnostic)]
247 #[label(parser_add_paren)]
248 //~^ ERROR label without `#[primary_span]` field
251 //~^ ERROR the `#[primary_span]` attribute can only be applied to fields of type `Span` or `MultiSpan`
255 #[derive(Subdiagnostic)]
256 #[label(parser_add_paren)]
261 //~^ ERROR `#[applicability]` is only valid on suggestions
262 applicability
: Applicability
,
265 #[derive(Subdiagnostic)]
266 #[label(parser_add_paren)]
271 //~^ ERROR `#[bar]` is not a valid attribute
272 //~^^ ERROR cannot find attribute `bar` in this scope
276 #[derive(Subdiagnostic)]
277 #[label(parser_add_paren)]
282 //~^ ERROR `#[bar = ...]` is not a valid attribute
283 //~^^ ERROR cannot find attribute `bar` in this scope
287 #[derive(Subdiagnostic)]
288 #[label(parser_add_paren)]
293 //~^ ERROR `#[bar(...)]` is not a valid attribute
294 //~^^ ERROR cannot find attribute `bar` in this scope
298 #[derive(Subdiagnostic)]
299 #[label(parser_add_paren)]
307 #[derive(Subdiagnostic)]
309 //~^ ERROR unexpected unsupported untagged union
314 #[derive(Subdiagnostic)]
315 #[label(parser_add_paren)]
316 #[label(parser_add_paren)]
322 #[derive(Subdiagnostic)]
323 #[label(parser_add_paren, parser_add_paren)]
324 //~^ ERROR `#[label(parser_add_paren)]` is not a valid attribute
330 #[derive(Subdiagnostic)]
331 #[label(parser_add_paren)]
334 //~^ NOTE previously specified here
337 //~^ ERROR specified multiple times
341 #[derive(Subdiagnostic)]
343 //~^ ERROR subdiagnostic kind not specified
348 #[derive(Subdiagnostic)]
349 #[suggestion(parser_add_paren, code = "...")]
354 applicability
: Applicability
,
358 #[derive(Subdiagnostic)]
360 #[suggestion(parser_add_paren, code = "...")]
365 applicability
: Applicability
,
368 #[suggestion(parser_add_paren, code = "...")]
373 applicability
: Applicability
,
378 #[derive(Subdiagnostic)]
379 #[suggestion(parser_add_paren, code = "...", code = "...")]
380 //~^ ERROR specified multiple times
381 //~^^ NOTE previously specified here
386 applicability
: Applicability
,
389 #[derive(Subdiagnostic)]
390 #[suggestion(parser_add_paren, code = "...")]
395 //~^ NOTE previously specified here
396 applicability_a
: Applicability
,
398 //~^ ERROR specified multiple times
399 applicability_b
: Applicability
,
402 #[derive(Subdiagnostic)]
403 #[suggestion(parser_add_paren, code = "...")]
408 //~^ ERROR the `#[applicability]` attribute can only be applied to fields of type `Applicability`
412 #[derive(Subdiagnostic)]
413 #[suggestion(parser_add_paren, code = "...")]
419 #[derive(Subdiagnostic)]
420 #[suggestion(parser_add_paren)]
421 //~^ ERROR suggestion without `code = "..."`
426 applicability
: Applicability
,
429 #[derive(Subdiagnostic)]
430 #[suggestion(parser_add_paren, code ="...", applicability = "foo")]
431 //~^ ERROR invalid applicability
437 #[derive(Subdiagnostic)]
438 #[help(parser_add_paren)]
443 #[derive(Subdiagnostic)]
444 #[note(parser_add_paren)]
447 #[derive(Subdiagnostic)]
448 #[suggestion(parser_add_paren, code = "...")]
449 //~^ ERROR suggestion without `#[primary_span]` field
454 #[derive(Subdiagnostic)]
455 #[suggestion(parser_add_paren, code ="...", applicability = "machine-applicable")]
461 #[derive(Subdiagnostic)]
463 //~^ ERROR unsupported type attribute for subdiagnostic enum
465 #[label(parser_add_paren)]
473 #[derive(Subdiagnostic)]
474 #[suggestion(parser_add_paren, code ="{var}", applicability = "machine-applicable")]
481 #[derive(Subdiagnostic)]
482 #[suggestion(parser_add_paren, code ="{var}", applicability = "machine-applicable")]
483 //~^ ERROR `var` doesn't refer to a field on this type
489 #[derive(Subdiagnostic)]
491 #[suggestion(parser_add_paren, code ="{var}", applicability = "machine-applicable")]
499 #[derive(Subdiagnostic)]
501 #[suggestion(parser_add_paren, code ="{var}", applicability = "machine-applicable")]
502 //~^ ERROR `var` doesn't refer to a field on this type
509 #[derive(Subdiagnostic)]
510 #[warning(parser_add_paren)]
513 #[derive(Subdiagnostic)]
514 #[warning(parser_add_paren)]
520 #[derive(Subdiagnostic)]
521 #[suggestion(parser_add_paren, code = "...")]
522 //~^ ERROR suggestion without `#[primary_span]` field
525 //~^ ERROR `#[suggestion_part]` is not a valid attribute
527 #[suggestion_part(code = "...")]
528 //~^ ERROR `#[suggestion_part(...)]` is not a valid attribute
531 applicability
: Applicability
,
535 #[derive(Subdiagnostic)]
536 #[multipart_suggestion(parser_add_paren, code = "...", applicability = "machine-applicable")]
537 //~^ ERROR multipart suggestion without any `#[suggestion_part(...)]` fields
538 //~| ERROR `#[multipart_suggestion(code = ...)]` is not a valid attribute
543 #[derive(Subdiagnostic)]
544 #[multipart_suggestion(parser_add_paren, applicability = "machine-applicable")]
547 //~^ ERROR `#[suggestion_part(...)]` attribute without `code = "..."`
551 #[derive(Subdiagnostic)]
552 #[multipart_suggestion(parser_add_paren, applicability = "machine-applicable")]
555 //~^ ERROR `#[suggestion_part(...)]` attribute without `code = "..."`
559 #[derive(Subdiagnostic)]
560 #[multipart_suggestion(parser_add_paren)]
561 //~^ ERROR multipart suggestion without any `#[suggestion_part(...)]` fields
564 //~^ ERROR `#[primary_span]` is not a valid attribute
568 #[derive(Subdiagnostic)]
569 #[multipart_suggestion(parser_add_paren)]
572 //~^ ERROR `#[suggestion_part(...)]` attribute without `code = "..."`
575 //~^ ERROR `#[suggestion_part(...)]` attribute without `code = "..."`
577 #[suggestion_part(foo = "bar")]
578 //~^ ERROR `#[suggestion_part(foo = ...)]` is not a valid attribute
580 #[suggestion_part(code = "...")]
581 //~^ ERROR the `#[suggestion_part(...)]` attribute can only be applied to fields of type `Span` or `MultiSpan`
584 //~^ ERROR the `#[suggestion_part(...)]` attribute can only be applied to fields of type `Span` or `MultiSpan`
588 #[derive(Subdiagnostic)]
589 #[multipart_suggestion(parser_add_paren, applicability = "machine-applicable")]
591 #[suggestion_part(code = "...", code = ",,,")]
592 //~^ ERROR specified multiple times
593 //~| NOTE previously specified here
597 #[derive(Subdiagnostic)]
598 #[multipart_suggestion(parser_add_paren, applicability = "machine-applicable")]
600 #[suggestion_part(code = "(")]
602 #[suggestion_part(code = ")")]
606 #[derive(Subdiagnostic)]
607 #[multipart_suggestion(parser_add_paren)]
611 #[suggestion_part(code = "(")]
613 #[suggestion_part(code = ")")]
617 #[derive(Subdiagnostic)]
618 #[multipart_suggestion(parser_add_paren, applicability = "machine-applicable")]
621 //~^ ERROR `#[applicability]` has no effect
623 #[suggestion_part(code = "(")]
625 #[suggestion_part(code = ")")]
629 #[derive(Subdiagnostic)]
630 #[multipart_suggestion(parser_add_paren, applicability = "machine-applicable")]
632 #[suggestion_part(code = "")]
636 #[derive(Subdiagnostic)]
637 #[label(parser_add_paren)]
644 /// with a doc comment on the type..
645 #[derive(Subdiagnostic)]
646 #[label(parser_add_paren)]
653 /// with a doc comment on the type..
654 #[derive(Subdiagnostic)]
656 /// ..and the variant..
657 #[label(parser_add_paren)]
665 #[derive(Subdiagnostic)]
666 #[multipart_suggestion(parser_add_paren)]
668 #[suggestion_part(code("foo"))]
669 //~^ ERROR expected exactly one string literal for `code = ...`
674 #[derive(Subdiagnostic)]
675 #[multipart_suggestion(parser_add_paren)]
677 #[suggestion_part(code("foo", "bar"))]
678 //~^ ERROR expected exactly one string literal for `code = ...`
683 #[derive(Subdiagnostic)]
684 #[multipart_suggestion(parser_add_paren)]
686 #[suggestion_part(code(3))]
687 //~^ ERROR expected exactly one string literal for `code = ...`
692 #[derive(Subdiagnostic)]
693 #[multipart_suggestion(parser_add_paren)]
695 #[suggestion_part(code())]
696 //~^ ERROR expected exactly one string literal for `code = ...`
701 #[derive(Subdiagnostic)]
702 #[multipart_suggestion(parser_add_paren)]
704 #[suggestion_part(code = 3)]
705 //~^ ERROR `code = "..."`/`code(...)` must contain only string literals