]> git.lizzy.rs Git - rust.git/blob - tests/ui-fulldeps/session-diagnostic/diagnostic-derive.rs
Auto merge of #106776 - oli-obk:om_nom_nom_nom_nom, r=cjgillot
[rust.git] / tests / ui-fulldeps / session-diagnostic / diagnostic-derive.rs
1 // check-fail
2 // Tests error conditions for specifying diagnostics using #[derive(Diagnostic)]
3
4 // normalize-stderr-test "the following other types implement trait `IntoDiagnosticArg`:(?:.*\n){0,9}\s+and \d+ others" -> "normalized in stderr"
5 // normalize-stderr-test "diagnostic_builder\.rs:[0-9]+:[0-9]+" -> "diagnostic_builder.rs:LL:CC"
6 // The proc_macro2 crate handles spans differently when on beta/stable release rather than nightly,
7 // changing the output of this test. Since Diagnostic is strictly internal to the compiler
8 // the test is just ignored on stable and beta:
9 // ignore-beta
10 // ignore-stable
11
12 #![feature(rustc_private)]
13 #![crate_type = "lib"]
14
15 extern crate rustc_span;
16 use rustc_span::symbol::Ident;
17 use rustc_span::Span;
18
19 extern crate rustc_macros;
20 use rustc_macros::{Diagnostic, LintDiagnostic, Subdiagnostic};
21
22 extern crate rustc_middle;
23 use rustc_middle::ty::Ty;
24
25 extern crate rustc_errors;
26 use rustc_errors::{Applicability, MultiSpan};
27
28 extern crate rustc_session;
29
30 #[derive(Diagnostic)]
31 #[diag(compiletest_example, code = "E0123")]
32 struct Hello {}
33
34 #[derive(Diagnostic)]
35 #[diag(compiletest_example, code = "E0123")]
36 struct HelloWarn {}
37
38 #[derive(Diagnostic)]
39 #[diag(compiletest_example, code = "E0123")]
40 //~^ ERROR unsupported type attribute for diagnostic derive enum
41 enum DiagnosticOnEnum {
42     Foo,
43     //~^ ERROR diagnostic slug not specified
44     Bar,
45     //~^ ERROR diagnostic slug not specified
46 }
47
48 #[derive(Diagnostic)]
49 #[diag(compiletest_example, code = "E0123")]
50 #[diag = "E0123"]
51 //~^ ERROR `#[diag = ...]` is not a valid attribute
52 struct WrongStructAttrStyle {}
53
54 #[derive(Diagnostic)]
55 #[nonsense(compiletest_example, code = "E0123")]
56 //~^ ERROR `#[nonsense(...)]` is not a valid attribute
57 //~^^ ERROR diagnostic slug not specified
58 //~^^^ ERROR cannot find attribute `nonsense` in this scope
59 struct InvalidStructAttr {}
60
61 #[derive(Diagnostic)]
62 #[diag("E0123")]
63 //~^ ERROR `#[diag("...")]` is not a valid attribute
64 //~^^ ERROR diagnostic slug not specified
65 struct InvalidLitNestedAttr {}
66
67 #[derive(Diagnostic)]
68 #[diag(nonsense, code = "E0123")]
69 //~^ ERROR cannot find value `nonsense` in module `rustc_errors::fluent`
70 struct InvalidNestedStructAttr {}
71
72 #[derive(Diagnostic)]
73 #[diag(nonsense("foo"), code = "E0123", slug = "foo")]
74 //~^ ERROR `#[diag(nonsense(...))]` is not a valid attribute
75 //~^^ ERROR diagnostic slug not specified
76 struct InvalidNestedStructAttr1 {}
77
78 #[derive(Diagnostic)]
79 #[diag(nonsense = "...", code = "E0123", slug = "foo")]
80 //~^ ERROR `#[diag(nonsense = ...)]` is not a valid attribute
81 //~| ERROR `#[diag(slug = ...)]` is not a valid attribute
82 //~| ERROR diagnostic slug not specified
83 struct InvalidNestedStructAttr2 {}
84
85 #[derive(Diagnostic)]
86 #[diag(nonsense = 4, code = "E0123", slug = "foo")]
87 //~^ ERROR `#[diag(nonsense = ...)]` is not a valid attribute
88 //~| ERROR `#[diag(slug = ...)]` is not a valid attribute
89 //~| ERROR diagnostic slug not specified
90 struct InvalidNestedStructAttr3 {}
91
92 #[derive(Diagnostic)]
93 #[diag(compiletest_example, code = "E0123", slug = "foo")]
94 //~^ ERROR `#[diag(slug = ...)]` is not a valid attribute
95 struct InvalidNestedStructAttr4 {}
96
97 #[derive(Diagnostic)]
98 #[diag(compiletest_example, code = "E0123")]
99 struct WrongPlaceField {
100     #[suggestion = "bar"]
101     //~^ ERROR `#[suggestion = ...]` is not a valid attribute
102     sp: Span,
103 }
104
105 #[derive(Diagnostic)]
106 #[diag(compiletest_example, code = "E0123")]
107 #[diag(compiletest_example, code = "E0456")]
108 //~^ ERROR specified multiple times
109 //~^^ ERROR specified multiple times
110 struct DiagSpecifiedTwice {}
111
112 #[derive(Diagnostic)]
113 #[diag(compiletest_example, code = "E0456", code = "E0457")]
114 //~^ ERROR specified multiple times
115 struct CodeSpecifiedTwice {}
116
117 #[derive(Diagnostic)]
118 #[diag(compiletest_example, compiletest_example, code = "E0456")]
119 //~^ ERROR `#[diag(compiletest_example)]` is not a valid attribute
120 struct SlugSpecifiedTwice {}
121
122 #[derive(Diagnostic)]
123 struct KindNotProvided {} //~ ERROR diagnostic slug not specified
124
125 #[derive(Diagnostic)]
126 #[diag(code = "E0456")]
127 //~^ ERROR diagnostic slug not specified
128 struct SlugNotProvided {}
129
130 #[derive(Diagnostic)]
131 #[diag(compiletest_example)]
132 struct CodeNotProvided {}
133
134 #[derive(Diagnostic)]
135 #[diag(compiletest_example, code = "E0123")]
136 struct MessageWrongType {
137     #[primary_span]
138     //~^ ERROR `#[primary_span]` attribute can only be applied to fields of type `Span` or `MultiSpan`
139     foo: String,
140 }
141
142 #[derive(Diagnostic)]
143 #[diag(compiletest_example, code = "E0123")]
144 struct InvalidPathFieldAttr {
145     #[nonsense]
146     //~^ ERROR `#[nonsense]` is not a valid attribute
147     //~^^ ERROR cannot find attribute `nonsense` in this scope
148     foo: String,
149 }
150
151 #[derive(Diagnostic)]
152 #[diag(compiletest_example, code = "E0123")]
153 struct ErrorWithField {
154     name: String,
155     #[label(label)]
156     span: Span,
157 }
158
159 #[derive(Diagnostic)]
160 #[diag(compiletest_example, code = "E0123")]
161 struct ErrorWithMessageAppliedToField {
162     #[label(label)]
163     //~^ ERROR the `#[label(...)]` attribute can only be applied to fields of type `Span` or `MultiSpan`
164     name: String,
165 }
166
167 #[derive(Diagnostic)]
168 #[diag(compiletest_example, code = "E0123")]
169 struct ErrorWithNonexistentField {
170     #[suggestion(suggestion, code = "{name}")]
171     //~^ ERROR `name` doesn't refer to a field on this type
172     suggestion: (Span, Applicability),
173 }
174
175 #[derive(Diagnostic)]
176 //~^ ERROR invalid format string: expected `'}'`
177 #[diag(compiletest_example, code = "E0123")]
178 struct ErrorMissingClosingBrace {
179     #[suggestion(suggestion, code = "{name")]
180     suggestion: (Span, Applicability),
181     name: String,
182     val: usize,
183 }
184
185 #[derive(Diagnostic)]
186 //~^ ERROR invalid format string: unmatched `}`
187 #[diag(compiletest_example, code = "E0123")]
188 struct ErrorMissingOpeningBrace {
189     #[suggestion(suggestion, code = "name}")]
190     suggestion: (Span, Applicability),
191     name: String,
192     val: usize,
193 }
194
195 #[derive(Diagnostic)]
196 #[diag(compiletest_example, code = "E0123")]
197 struct LabelOnSpan {
198     #[label(label)]
199     sp: Span,
200 }
201
202 #[derive(Diagnostic)]
203 #[diag(compiletest_example, code = "E0123")]
204 struct LabelOnNonSpan {
205     #[label(label)]
206     //~^ ERROR the `#[label(...)]` attribute can only be applied to fields of type `Span` or `MultiSpan`
207     id: u32,
208 }
209
210 #[derive(Diagnostic)]
211 #[diag(compiletest_example, code = "E0123")]
212 struct Suggest {
213     #[suggestion(suggestion, code = "This is the suggested code")]
214     #[suggestion(suggestion, code = "This is the suggested code", style = "normal")]
215     #[suggestion(suggestion, code = "This is the suggested code", style = "short")]
216     #[suggestion(suggestion, code = "This is the suggested code", style = "hidden")]
217     #[suggestion(suggestion, code = "This is the suggested code", style = "verbose")]
218     suggestion: (Span, Applicability),
219 }
220
221 #[derive(Diagnostic)]
222 #[diag(compiletest_example, code = "E0123")]
223 struct SuggestWithoutCode {
224     #[suggestion(suggestion)]
225     //~^ ERROR suggestion without `code = "..."`
226     suggestion: (Span, Applicability),
227 }
228
229 #[derive(Diagnostic)]
230 #[diag(compiletest_example, code = "E0123")]
231 struct SuggestWithBadKey {
232     #[suggestion(nonsense = "bar")]
233     //~^ ERROR `#[suggestion(nonsense = ...)]` is not a valid attribute
234     //~| ERROR suggestion without `code = "..."`
235     suggestion: (Span, Applicability),
236 }
237
238 #[derive(Diagnostic)]
239 #[diag(compiletest_example, code = "E0123")]
240 struct SuggestWithShorthandMsg {
241     #[suggestion(msg = "bar")]
242     //~^ ERROR `#[suggestion(msg = ...)]` is not a valid attribute
243     //~| ERROR suggestion without `code = "..."`
244     suggestion: (Span, Applicability),
245 }
246
247 #[derive(Diagnostic)]
248 #[diag(compiletest_example, code = "E0123")]
249 struct SuggestWithoutMsg {
250     #[suggestion(code = "bar")]
251     suggestion: (Span, Applicability),
252 }
253
254 #[derive(Diagnostic)]
255 #[diag(compiletest_example, code = "E0123")]
256 struct SuggestWithTypesSwapped {
257     #[suggestion(suggestion, code = "This is suggested code")]
258     suggestion: (Applicability, Span),
259 }
260
261 #[derive(Diagnostic)]
262 #[diag(compiletest_example, code = "E0123")]
263 struct SuggestWithWrongTypeApplicabilityOnly {
264     #[suggestion(suggestion, code = "This is suggested code")]
265     //~^ ERROR wrong field type for suggestion
266     suggestion: Applicability,
267 }
268
269 #[derive(Diagnostic)]
270 #[diag(compiletest_example, code = "E0123")]
271 struct SuggestWithSpanOnly {
272     #[suggestion(suggestion, code = "This is suggested code")]
273     suggestion: Span,
274 }
275
276 #[derive(Diagnostic)]
277 #[diag(compiletest_example, code = "E0123")]
278 struct SuggestWithDuplicateSpanAndApplicability {
279     #[suggestion(suggestion, code = "This is suggested code")]
280     suggestion: (Span, Span, Applicability),
281     //~^ ERROR specified multiple times
282 }
283
284 #[derive(Diagnostic)]
285 #[diag(compiletest_example, code = "E0123")]
286 struct SuggestWithDuplicateApplicabilityAndSpan {
287     #[suggestion(suggestion, code = "This is suggested code")]
288     suggestion: (Applicability, Applicability, Span),
289     //~^ ERROR specified multiple times
290 }
291
292 #[derive(Diagnostic)]
293 #[diag(compiletest_example, code = "E0123")]
294 struct WrongKindOfAnnotation {
295     #[label = "bar"]
296     //~^ ERROR `#[label = ...]` is not a valid attribute
297     z: Span,
298 }
299
300 #[derive(Diagnostic)]
301 #[diag(compiletest_example, code = "E0123")]
302 struct OptionsInErrors {
303     #[label(label)]
304     label: Option<Span>,
305     #[suggestion(suggestion, code = "...")]
306     opt_sugg: Option<(Span, Applicability)>,
307 }
308
309 #[derive(Diagnostic)]
310 #[diag(compiletest_example, code = "E0456")]
311 struct MoveOutOfBorrowError<'tcx> {
312     name: Ident,
313     ty: Ty<'tcx>,
314     #[primary_span]
315     #[label(label)]
316     span: Span,
317     #[label(label)]
318     other_span: Span,
319     #[suggestion(suggestion, code = "{name}.clone()")]
320     opt_sugg: Option<(Span, Applicability)>,
321 }
322
323 #[derive(Diagnostic)]
324 #[diag(compiletest_example, code = "E0123")]
325 struct ErrorWithLifetime<'a> {
326     #[label(label)]
327     span: Span,
328     name: &'a str,
329 }
330
331 #[derive(Diagnostic)]
332 #[diag(compiletest_example, code = "E0123")]
333 struct ErrorWithDefaultLabelAttr<'a> {
334     #[label]
335     span: Span,
336     name: &'a str,
337 }
338
339 #[derive(Diagnostic)]
340 //~^ ERROR the trait bound `Hello: IntoDiagnosticArg` is not satisfied
341 #[diag(compiletest_example, code = "E0123")]
342 struct ArgFieldWithoutSkip {
343     #[primary_span]
344     span: Span,
345     other: Hello,
346 }
347
348 #[derive(Diagnostic)]
349 #[diag(compiletest_example, code = "E0123")]
350 struct ArgFieldWithSkip {
351     #[primary_span]
352     span: Span,
353     // `Hello` does not implement `IntoDiagnosticArg` so this would result in an error if
354     // not for `#[skip_arg]`.
355     #[skip_arg]
356     other: Hello,
357 }
358
359 #[derive(Diagnostic)]
360 #[diag(compiletest_example, code = "E0123")]
361 struct ErrorWithSpannedNote {
362     #[note]
363     span: Span,
364 }
365
366 #[derive(Diagnostic)]
367 #[diag(compiletest_example, code = "E0123")]
368 struct ErrorWithSpannedNoteCustom {
369     #[note(note)]
370     span: Span,
371 }
372
373 #[derive(Diagnostic)]
374 #[diag(compiletest_example, code = "E0123")]
375 #[note]
376 struct ErrorWithNote {
377     val: String,
378 }
379
380 #[derive(Diagnostic)]
381 #[diag(compiletest_example, code = "E0123")]
382 #[note(note)]
383 struct ErrorWithNoteCustom {
384     val: String,
385 }
386
387 #[derive(Diagnostic)]
388 #[diag(compiletest_example, code = "E0123")]
389 struct ErrorWithSpannedHelp {
390     #[help]
391     span: Span,
392 }
393
394 #[derive(Diagnostic)]
395 #[diag(compiletest_example, code = "E0123")]
396 struct ErrorWithSpannedHelpCustom {
397     #[help(help)]
398     span: Span,
399 }
400
401 #[derive(Diagnostic)]
402 #[diag(compiletest_example, code = "E0123")]
403 #[help]
404 struct ErrorWithHelp {
405     val: String,
406 }
407
408 #[derive(Diagnostic)]
409 #[diag(compiletest_example, code = "E0123")]
410 #[help(help)]
411 struct ErrorWithHelpCustom {
412     val: String,
413 }
414
415 #[derive(Diagnostic)]
416 #[help]
417 #[diag(compiletest_example, code = "E0123")]
418 struct ErrorWithHelpWrongOrder {
419     val: String,
420 }
421
422 #[derive(Diagnostic)]
423 #[help(help)]
424 #[diag(compiletest_example, code = "E0123")]
425 struct ErrorWithHelpCustomWrongOrder {
426     val: String,
427 }
428
429 #[derive(Diagnostic)]
430 #[note]
431 #[diag(compiletest_example, code = "E0123")]
432 struct ErrorWithNoteWrongOrder {
433     val: String,
434 }
435
436 #[derive(Diagnostic)]
437 #[note(note)]
438 #[diag(compiletest_example, code = "E0123")]
439 struct ErrorWithNoteCustomWrongOrder {
440     val: String,
441 }
442
443 #[derive(Diagnostic)]
444 #[diag(compiletest_example, code = "E0123")]
445 struct ApplicabilityInBoth {
446     #[suggestion(suggestion, code = "...", applicability = "maybe-incorrect")]
447     //~^ ERROR specified multiple times
448     suggestion: (Span, Applicability),
449 }
450
451 #[derive(Diagnostic)]
452 #[diag(compiletest_example, code = "E0123")]
453 struct InvalidApplicability {
454     #[suggestion(suggestion, code = "...", applicability = "batman")]
455     //~^ ERROR invalid applicability
456     suggestion: Span,
457 }
458
459 #[derive(Diagnostic)]
460 #[diag(compiletest_example, code = "E0123")]
461 struct ValidApplicability {
462     #[suggestion(suggestion, code = "...", applicability = "maybe-incorrect")]
463     suggestion: Span,
464 }
465
466 #[derive(Diagnostic)]
467 #[diag(compiletest_example, code = "E0123")]
468 struct NoApplicability {
469     #[suggestion(suggestion, code = "...")]
470     suggestion: Span,
471 }
472
473 #[derive(Subdiagnostic)]
474 #[note(parse_add_paren)]
475 struct Note;
476
477 #[derive(Diagnostic)]
478 #[diag(compiletest_example)]
479 struct Subdiagnostic {
480     #[subdiagnostic]
481     note: Note,
482 }
483
484 #[derive(Diagnostic)]
485 #[diag(compiletest_example, code = "E0123")]
486 struct VecField {
487     #[primary_span]
488     #[label]
489     spans: Vec<Span>,
490 }
491
492 #[derive(Diagnostic)]
493 #[diag(compiletest_example, code = "E0123")]
494 struct UnitField {
495     #[primary_span]
496     spans: Span,
497     #[help]
498     foo: (),
499     #[help(help)]
500     bar: (),
501 }
502
503 #[derive(Diagnostic)]
504 #[diag(compiletest_example, code = "E0123")]
505 struct OptUnitField {
506     #[primary_span]
507     spans: Span,
508     #[help]
509     foo: Option<()>,
510     #[help(help)]
511     bar: Option<()>,
512 }
513
514 #[derive(Diagnostic)]
515 #[diag(compiletest_example, code = "E0123")]
516 struct LabelWithTrailingPath {
517     #[label(label, foo)]
518     //~^ ERROR `#[label(foo)]` is not a valid attribute
519     span: Span,
520 }
521
522 #[derive(Diagnostic)]
523 #[diag(compiletest_example, code = "E0123")]
524 struct LabelWithTrailingNameValue {
525     #[label(label, foo = "...")]
526     //~^ ERROR `#[label(foo = ...)]` is not a valid attribute
527     span: Span,
528 }
529
530 #[derive(Diagnostic)]
531 #[diag(compiletest_example, code = "E0123")]
532 struct LabelWithTrailingList {
533     #[label(label, foo("..."))]
534     //~^ ERROR `#[label(foo(...))]` is not a valid attribute
535     span: Span,
536 }
537
538 #[derive(LintDiagnostic)]
539 #[diag(compiletest_example)]
540 struct LintsGood {}
541
542 #[derive(LintDiagnostic)]
543 #[diag(compiletest_example)]
544 struct PrimarySpanOnLint {
545     #[primary_span]
546     //~^ ERROR `#[primary_span]` is not a valid attribute
547     span: Span,
548 }
549
550 #[derive(Diagnostic)]
551 #[diag(compiletest_example, code = "E0123")]
552 struct ErrorWithMultiSpan {
553     #[primary_span]
554     span: MultiSpan,
555 }
556
557 #[derive(Diagnostic)]
558 #[diag(compiletest_example, code = "E0123")]
559 #[warning]
560 struct ErrorWithWarn {
561     val: String,
562 }
563
564 #[derive(Diagnostic)]
565 #[error(compiletest_example, code = "E0123")]
566 //~^ ERROR `#[error(...)]` is not a valid attribute
567 //~| ERROR diagnostic slug not specified
568 //~| ERROR cannot find attribute `error` in this scope
569 struct ErrorAttribute {}
570
571 #[derive(Diagnostic)]
572 #[warn_(compiletest_example, code = "E0123")]
573 //~^ ERROR `#[warn_(...)]` is not a valid attribute
574 //~| ERROR diagnostic slug not specified
575 //~| ERROR cannot find attribute `warn_` in this scope
576 struct WarnAttribute {}
577
578 #[derive(Diagnostic)]
579 #[lint(compiletest_example, code = "E0123")]
580 //~^ ERROR `#[lint(...)]` is not a valid attribute
581 //~| ERROR diagnostic slug not specified
582 //~| ERROR cannot find attribute `lint` in this scope
583 struct LintAttributeOnSessionDiag {}
584
585 #[derive(LintDiagnostic)]
586 #[lint(compiletest_example, code = "E0123")]
587 //~^ ERROR `#[lint(...)]` is not a valid attribute
588 //~| ERROR `#[lint(...)]` is not a valid attribute
589 //~| ERROR diagnostic slug not specified
590 //~| ERROR cannot find attribute `lint` in this scope
591 struct LintAttributeOnLintDiag {}
592
593 #[derive(Diagnostic)]
594 #[diag(compiletest_example, code = "E0123")]
595 struct DuplicatedSuggestionCode {
596     #[suggestion(suggestion, code = "...", code = ",,,")]
597     //~^ ERROR specified multiple times
598     suggestion: Span,
599 }
600
601 #[derive(Diagnostic)]
602 #[diag(compiletest_example, code = "E0123")]
603 struct InvalidTypeInSuggestionTuple {
604     #[suggestion(suggestion, code = "...")]
605     suggestion: (Span, usize),
606     //~^ ERROR wrong types for suggestion
607 }
608
609 #[derive(Diagnostic)]
610 #[diag(compiletest_example, code = "E0123")]
611 struct MissingApplicabilityInSuggestionTuple {
612     #[suggestion(suggestion, code = "...")]
613     suggestion: (Span,),
614     //~^ ERROR wrong types for suggestion
615 }
616
617 #[derive(Diagnostic)]
618 #[diag(compiletest_example, code = "E0123")]
619 struct MissingCodeInSuggestion {
620     #[suggestion(suggestion)]
621     //~^ ERROR suggestion without `code = "..."`
622     suggestion: Span,
623 }
624
625 #[derive(Diagnostic)]
626 #[diag(compiletest_example, code = "E0123")]
627 #[multipart_suggestion(suggestion)]
628 //~^ ERROR `#[multipart_suggestion(...)]` is not a valid attribute
629 //~| ERROR cannot find attribute `multipart_suggestion` in this scope
630 #[multipart_suggestion()]
631 //~^ ERROR `#[multipart_suggestion(...)]` is not a valid attribute
632 //~| ERROR cannot find attribute `multipart_suggestion` in this scope
633 struct MultipartSuggestion {
634     #[multipart_suggestion(suggestion)]
635     //~^ ERROR `#[multipart_suggestion(...)]` is not a valid attribute
636     //~| ERROR cannot find attribute `multipart_suggestion` in this scope
637     suggestion: Span,
638 }
639
640 #[derive(Diagnostic)]
641 #[diag(compiletest_example, code = "E0123")]
642 #[suggestion(suggestion, code = "...")]
643 //~^ ERROR `#[suggestion(...)]` is not a valid attribute
644 struct SuggestionOnStruct {
645     #[primary_span]
646     suggestion: Span,
647 }
648
649 #[derive(Diagnostic)]
650 #[diag(compiletest_example, code = "E0123")]
651 #[label]
652 //~^ ERROR `#[label]` is not a valid attribute
653 struct LabelOnStruct {
654     #[primary_span]
655     suggestion: Span,
656 }
657
658 #[derive(Diagnostic)]
659 enum ExampleEnum {
660     #[diag(compiletest_example)]
661     Foo {
662         #[primary_span]
663         sp: Span,
664         #[note]
665         note_sp: Span,
666     },
667     #[diag(compiletest_example)]
668     Bar {
669         #[primary_span]
670         sp: Span,
671     },
672     #[diag(compiletest_example)]
673     Baz,
674 }
675
676 #[derive(Diagnostic)]
677 #[diag(compiletest_example, code = "E0123")]
678 struct RawIdentDiagnosticArg {
679     pub r#type: String,
680 }
681
682 #[derive(Diagnostic)]
683 #[diag(compiletest_example)]
684 struct SubdiagnosticBad {
685     #[subdiagnostic(bad)]
686     //~^ ERROR `#[subdiagnostic(...)]` is not a valid attribute
687     note: Note,
688 }
689
690 #[derive(Diagnostic)]
691 #[diag(compiletest_example)]
692 struct SubdiagnosticBadStr {
693     #[subdiagnostic = "bad"]
694     //~^ ERROR `#[subdiagnostic = ...]` is not a valid attribute
695     note: Note,
696 }
697
698 #[derive(Diagnostic)]
699 #[diag(compiletest_example)]
700 struct SubdiagnosticBadTwice {
701     #[subdiagnostic(bad, bad)]
702     //~^ ERROR `#[subdiagnostic(...)]` is not a valid attribute
703     note: Note,
704 }
705
706 #[derive(Diagnostic)]
707 #[diag(compiletest_example)]
708 struct SubdiagnosticBadLitStr {
709     #[subdiagnostic("bad")]
710     //~^ ERROR `#[subdiagnostic(...)]` is not a valid attribute
711     note: Note,
712 }
713
714 #[derive(LintDiagnostic)]
715 #[diag(compiletest_example)]
716 struct SubdiagnosticEagerLint {
717     #[subdiagnostic(eager)]
718     //~^ ERROR `#[subdiagnostic(...)]` is not a valid attribute
719     note: Note,
720 }
721
722 #[derive(Diagnostic)]
723 #[diag(compiletest_example)]
724 struct SubdiagnosticEagerCorrect {
725     #[subdiagnostic(eager)]
726     note: Note,
727 }
728
729 // Check that formatting of `correct` in suggestion doesn't move the binding for that field, making
730 // the `set_arg` call a compile error; and that isn't worked around by moving the `set_arg` call
731 // after the `span_suggestion` call - which breaks eager translation.
732
733 #[derive(Subdiagnostic)]
734 #[suggestion(use_instead, applicability = "machine-applicable", code = "{correct}")]
735 pub(crate) struct SubdiagnosticWithSuggestion {
736     #[primary_span]
737     span: Span,
738     invalid: String,
739     correct: String,
740 }
741
742 #[derive(Diagnostic)]
743 #[diag(compiletest_example)]
744 struct SubdiagnosticEagerSuggestion {
745     #[subdiagnostic(eager)]
746     sub: SubdiagnosticWithSuggestion,
747 }
748
749 /// with a doc comment on the type..
750 #[derive(Diagnostic)]
751 #[diag(compiletest_example, code = "E0123")]
752 struct WithDocComment {
753     /// ..and the field
754     #[primary_span]
755     span: Span,
756 }
757
758 #[derive(Diagnostic)]
759 #[diag(compiletest_example)]
760 struct SuggestionsGood {
761     #[suggestion(code("foo", "bar"))]
762     sub: Span,
763 }
764
765 #[derive(Diagnostic)]
766 #[diag(compiletest_example)]
767 struct SuggestionsSingleItem {
768     #[suggestion(code("foo"))]
769     sub: Span,
770 }
771
772 #[derive(Diagnostic)]
773 #[diag(compiletest_example)]
774 struct SuggestionsNoItem {
775     #[suggestion(code())]
776     //~^ ERROR expected at least one string literal for `code(...)`
777     sub: Span,
778 }
779
780 #[derive(Diagnostic)]
781 #[diag(compiletest_example)]
782 struct SuggestionsInvalidItem {
783     #[suggestion(code(foo))]
784     //~^ ERROR `code(...)` must contain only string literals
785     sub: Span,
786 }
787
788 #[derive(Diagnostic)]
789 #[diag(compiletest_example)]
790 struct SuggestionsInvalidLiteral {
791     #[suggestion(code = 3)]
792     //~^ ERROR `code = "..."`/`code(...)` must contain only string literals
793     sub: Span,
794 }
795
796 #[derive(Diagnostic)]
797 #[diag(compiletest_example)]
798 struct SuggestionStyleGood {
799     #[suggestion(code = "", style = "hidden")]
800     sub: Span,
801 }