2 // Tests error conditions for specifying subdiagnostics using #[derive(SessionSubdiagnostic)]
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:
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::SessionSubdiagnostic;
22 #[derive(SessionSubdiagnostic)]
23 #[label(parser::add_paren)]
30 #[derive(SessionSubdiagnostic)]
32 #[label(parser::add_paren)]
38 #[label(parser::add_paren)]
46 #[derive(SessionSubdiagnostic)]
47 #[label(parser::add_paren)]
48 //~^ ERROR label without `#[primary_span]` field
53 #[derive(SessionSubdiagnostic)]
55 //~^ ERROR `#[label]` is not a valid attribute
62 #[derive(SessionSubdiagnostic)]
64 //~^ ERROR `#[foo]` is not a valid attribute
65 //~^^ ERROR cannot find attribute `foo` in this scope
72 #[derive(SessionSubdiagnostic)]
74 //~^ ERROR `#[label = ...]` is not a valid attribute
81 #[derive(SessionSubdiagnostic)]
83 //~^ ERROR `#[label(bug = ...)]` is not a valid attribute
90 #[derive(SessionSubdiagnostic)]
92 //~^ ERROR `#[label("...")]` is not a valid attribute
99 #[derive(SessionSubdiagnostic)]
101 //~^ ERROR `#[label(slug = ...)]` is not a valid attribute
108 #[derive(SessionSubdiagnostic)]
109 #[label(slug("..."))]
110 //~^ ERROR `#[label(slug(...))]` is not a valid attribute
117 #[derive(SessionSubdiagnostic)]
119 //~^ ERROR cannot find value `slug` in module `rustc_errors::fluent`
120 //~^^ NOTE not found in `rustc_errors::fluent`
127 #[derive(SessionSubdiagnostic)]
129 //~^ ERROR diagnostic slug must be first argument of a `#[label(...)]` attribute
136 #[derive(SessionSubdiagnostic)]
137 #[label(parser::add_paren, code = "...")]
138 //~^ ERROR `code` is not a valid nested attribute of a `label` attribute
145 #[derive(SessionSubdiagnostic)]
146 #[label(parser::add_paren, applicability = "machine-applicable")]
147 //~^ ERROR `applicability` is not a valid nested attribute of a `label` attribute
154 #[derive(SessionSubdiagnostic)]
156 //~^ ERROR cannot find attribute `foo` in this scope
157 //~^^ ERROR unsupported type attribute for subdiagnostic enum
159 #[label(parser::add_paren)]
167 #[derive(SessionSubdiagnostic)]
170 //~^ ERROR `#[bar]` is not a valid attribute
171 //~^^ ERROR cannot find attribute `bar` in this scope
179 #[derive(SessionSubdiagnostic)]
182 //~^ ERROR `#[bar = ...]` is not a valid attribute
183 //~^^ ERROR cannot find attribute `bar` in this scope
191 #[derive(SessionSubdiagnostic)]
194 //~^ ERROR `#[bar = ...]` is not a valid attribute
195 //~^^ ERROR cannot find attribute `bar` in this scope
203 #[derive(SessionSubdiagnostic)]
206 //~^ ERROR `#[bar(...)]` is not a valid attribute
207 //~^^ ERROR cannot find attribute `bar` in this scope
215 #[derive(SessionSubdiagnostic)]
217 #[label(code = "...")]
218 //~^ ERROR diagnostic slug must be first argument of a `#[label(...)]` attribute
226 #[derive(SessionSubdiagnostic)]
228 #[label(parser::add_paren)]
235 //~^ ERROR subdiagnostic kind not specified
242 #[derive(SessionSubdiagnostic)]
243 #[label(parser::add_paren)]
244 //~^ ERROR label without `#[primary_span]` field
247 //~^ ERROR the `#[primary_span]` attribute can only be applied to fields of type `Span` or `MultiSpan`
251 #[derive(SessionSubdiagnostic)]
252 #[label(parser::add_paren)]
257 //~^ ERROR `#[applicability]` is only valid on suggestions
258 applicability: Applicability,
261 #[derive(SessionSubdiagnostic)]
262 #[label(parser::add_paren)]
267 //~^ ERROR `#[bar]` is not a valid attribute
268 //~^^ ERROR cannot find attribute `bar` in this scope
272 #[derive(SessionSubdiagnostic)]
273 #[label(parser::add_paren)]
278 //~^ ERROR `#[bar = ...]` is not a valid attribute
279 //~^^ ERROR cannot find attribute `bar` in this scope
283 #[derive(SessionSubdiagnostic)]
284 #[label(parser::add_paren)]
289 //~^ ERROR `#[bar(...)]` is not a valid attribute
290 //~^^ ERROR cannot find attribute `bar` in this scope
294 #[derive(SessionSubdiagnostic)]
295 #[label(parser::add_paren)]
303 #[derive(SessionSubdiagnostic)]
305 //~^ ERROR unexpected unsupported untagged union
310 #[derive(SessionSubdiagnostic)]
311 #[label(parser::add_paren)]
312 //~^ NOTE previously specified here
313 #[label(parser::add_paren)]
314 //~^ ERROR specified multiple times
320 #[derive(SessionSubdiagnostic)]
321 #[label(parser::add_paren, parser::add_paren)]
322 //~^ ERROR `#[label(parser::add_paren)]` is not a valid attribute
328 #[derive(SessionSubdiagnostic)]
329 #[label(parser::add_paren)]
332 //~^ NOTE previously specified here
335 //~^ ERROR specified multiple times
339 #[derive(SessionSubdiagnostic)]
341 //~^ ERROR subdiagnostic kind not specified
346 #[derive(SessionSubdiagnostic)]
347 #[suggestion(parser::add_paren, code = "...")]
352 applicability: Applicability,
356 #[derive(SessionSubdiagnostic)]
358 #[suggestion(parser::add_paren, code = "...")]
363 applicability: Applicability,
366 #[suggestion(parser::add_paren, code = "...")]
371 applicability: Applicability,
376 #[derive(SessionSubdiagnostic)]
377 #[suggestion(parser::add_paren, code = "...", code = "...")]
378 //~^ ERROR specified multiple times
379 //~^^ NOTE previously specified here
384 applicability: Applicability,
387 #[derive(SessionSubdiagnostic)]
388 #[suggestion(parser::add_paren, code = "...")]
393 //~^ NOTE previously specified here
394 applicability_a: Applicability,
396 //~^ ERROR specified multiple times
397 applicability_b: Applicability,
400 #[derive(SessionSubdiagnostic)]
401 #[suggestion(parser::add_paren, code = "...")]
406 //~^ ERROR the `#[applicability]` attribute can only be applied to fields of type `Applicability`
410 #[derive(SessionSubdiagnostic)]
411 #[suggestion(parser::add_paren, code = "...")]
417 #[derive(SessionSubdiagnostic)]
418 #[suggestion(parser::add_paren)]
419 //~^ ERROR suggestion without `code = "..."`
424 applicability: Applicability,
427 #[derive(SessionSubdiagnostic)]
428 #[suggestion(parser::add_paren, code ="...", applicability = "foo")]
429 //~^ ERROR invalid applicability
435 #[derive(SessionSubdiagnostic)]
436 #[help(parser::add_paren)]
441 #[derive(SessionSubdiagnostic)]
442 #[note(parser::add_paren)]
445 #[derive(SessionSubdiagnostic)]
446 #[suggestion(parser::add_paren, code = "...")]
447 //~^ ERROR suggestion without `#[primary_span]` field
452 #[derive(SessionSubdiagnostic)]
453 #[suggestion(parser::add_paren, code ="...", applicability = "machine-applicable")]
459 #[derive(SessionSubdiagnostic)]
461 //~^ ERROR unsupported type attribute for subdiagnostic enum
463 #[label(parser::add_paren)]
471 #[derive(SessionSubdiagnostic)]
472 #[suggestion(parser::add_paren, code ="{var}", applicability = "machine-applicable")]
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
487 #[derive(SessionSubdiagnostic)]
489 #[suggestion(parser::add_paren, code ="{var}", applicability = "machine-applicable")]
497 #[derive(SessionSubdiagnostic)]
499 #[suggestion(parser::add_paren, code ="{var}", applicability = "machine-applicable")]
500 //~^ ERROR `var` doesn't refer to a field on this type
507 #[derive(SessionSubdiagnostic)]
508 #[warning(parser::add_paren)]
511 #[derive(SessionSubdiagnostic)]
512 #[warning(parser::add_paren)]
518 #[derive(SessionSubdiagnostic)]
519 #[suggestion(parser::add_paren, code = "...")]
520 //~^ ERROR suggestion without `#[primary_span]` field
523 //~^ ERROR `#[suggestion_part]` is not a valid attribute
525 #[suggestion_part(code = "...")]
526 //~^ ERROR `#[suggestion_part(...)]` is not a valid attribute
529 applicability: Applicability,
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
541 #[derive(SessionSubdiagnostic)]
542 #[multipart_suggestion(parser::add_paren, applicability = "machine-applicable")]
545 //~^ ERROR `#[suggestion_part(...)]` attribute without `code = "..."`
549 #[derive(SessionSubdiagnostic)]
550 #[multipart_suggestion(parser::add_paren, applicability = "machine-applicable")]
553 //~^ ERROR `#[suggestion_part(...)]` attribute without `code = "..."`
557 #[derive(SessionSubdiagnostic)]
558 #[multipart_suggestion(parser::add_paren)]
559 //~^ ERROR multipart suggestion without any `#[suggestion_part(...)]` fields
562 //~^ ERROR `#[primary_span]` is not a valid attribute
566 #[derive(SessionSubdiagnostic)]
567 #[multipart_suggestion(parser::add_paren)]
570 //~^ ERROR `#[suggestion_part(...)]` attribute without `code = "..."`
573 //~^ ERROR `#[suggestion_part(...)]` attribute without `code = "..."`
575 #[suggestion_part(foo = "bar")]
576 //~^ ERROR `#[suggestion_part(foo = ...)]` is not a valid attribute
578 #[suggestion_part(code = "...")]
579 //~^ ERROR the `#[suggestion_part(...)]` attribute can only be applied to fields of type `Span` or `MultiSpan`
582 //~^ ERROR the `#[suggestion_part(...)]` attribute can only be applied to fields of type `Span` or `MultiSpan`
586 #[derive(SessionSubdiagnostic)]
587 #[multipart_suggestion(parser::add_paren, applicability = "machine-applicable")]
589 #[suggestion_part(code = "...", code = ",,,")]
590 //~^ ERROR specified multiple times
591 //~| NOTE previously specified here
595 #[derive(SessionSubdiagnostic)]
596 #[multipart_suggestion(parser::add_paren, applicability = "machine-applicable")]
598 #[suggestion_part(code = "(")]
600 #[suggestion_part(code = ")")]
604 #[derive(SessionSubdiagnostic)]
605 #[multipart_suggestion(parser::add_paren)]
609 #[suggestion_part(code = "(")]
611 #[suggestion_part(code = ")")]
615 #[derive(SessionSubdiagnostic)]
616 #[multipart_suggestion(parser::add_paren, applicability = "machine-applicable")]
617 //~^ NOTE previously specified here
620 //~^ ERROR specified multiple times
622 #[suggestion_part(code = "(")]
624 #[suggestion_part(code = ")")]
628 #[derive(SessionSubdiagnostic)]
629 #[multipart_suggestion(parser::add_paren, applicability = "machine-applicable")]
631 #[suggestion_part(code = "")]