]> git.lizzy.rs Git - rust.git/blob - compiler/rustc_passes/src/errors.rs
fcbcc298bd5b7fa05efe8ba3213d5928ded8f66c
[rust.git] / compiler / rustc_passes / src / errors.rs
1 use std::{io::Error, path::Path};
2
3 use rustc_ast::Label;
4 use rustc_errors::{error_code, Applicability, ErrorGuaranteed, IntoDiagnostic, MultiSpan};
5 use rustc_hir::{self as hir, ExprKind, Target};
6 use rustc_macros::{Diagnostic, LintDiagnostic, Subdiagnostic};
7 use rustc_span::{Span, Symbol};
8
9 #[derive(LintDiagnostic)]
10 #[diag(passes::outer_crate_level_attr)]
11 pub struct OuterCrateLevelAttr;
12
13 #[derive(LintDiagnostic)]
14 #[diag(passes::inner_crate_level_attr)]
15 pub struct InnerCrateLevelAttr;
16
17 #[derive(LintDiagnostic)]
18 #[diag(passes::ignored_attr_with_macro)]
19 pub struct IgnoredAttrWithMacro<'a> {
20     pub sym: &'a str,
21 }
22
23 #[derive(LintDiagnostic)]
24 #[diag(passes::ignored_attr)]
25 pub struct IgnoredAttr<'a> {
26     pub sym: &'a str,
27 }
28
29 #[derive(LintDiagnostic)]
30 #[diag(passes::inline_ignored_function_prototype)]
31 pub struct IgnoredInlineAttrFnProto;
32
33 #[derive(LintDiagnostic)]
34 #[diag(passes::inline_ignored_constants)]
35 #[warning]
36 #[note]
37 pub struct IgnoredInlineAttrConstants;
38
39 #[derive(Diagnostic)]
40 #[diag(passes::inline_not_fn_or_closure, code = "E0518")]
41 pub struct InlineNotFnOrClosure {
42     #[primary_span]
43     pub attr_span: Span,
44     #[label]
45     pub defn_span: Span,
46 }
47
48 #[derive(LintDiagnostic)]
49 #[diag(passes::no_coverage_ignored_function_prototype)]
50 pub struct IgnoredNoCoverageFnProto;
51
52 #[derive(LintDiagnostic)]
53 #[diag(passes::no_coverage_propagate)]
54 pub struct IgnoredNoCoveragePropagate;
55
56 #[derive(LintDiagnostic)]
57 #[diag(passes::no_coverage_fn_defn)]
58 pub struct IgnoredNoCoverageFnDefn;
59
60 #[derive(Diagnostic)]
61 #[diag(passes::no_coverage_not_coverable, code = "E0788")]
62 pub struct IgnoredNoCoverageNotCoverable {
63     #[primary_span]
64     pub attr_span: Span,
65     #[label]
66     pub defn_span: Span,
67 }
68
69 #[derive(Diagnostic)]
70 #[diag(passes::should_be_applied_to_fn)]
71 pub struct AttrShouldBeAppliedToFn {
72     #[primary_span]
73     pub attr_span: Span,
74     #[label]
75     pub defn_span: Span,
76 }
77
78 #[derive(Diagnostic)]
79 #[diag(passes::naked_tracked_caller, code = "E0736")]
80 pub struct NakedTrackedCaller {
81     #[primary_span]
82     pub attr_span: Span,
83 }
84
85 #[derive(Diagnostic)]
86 #[diag(passes::should_be_applied_to_fn, code = "E0739")]
87 pub struct TrackedCallerWrongLocation {
88     #[primary_span]
89     pub attr_span: Span,
90     #[label]
91     pub defn_span: Span,
92 }
93
94 #[derive(Diagnostic)]
95 #[diag(passes::should_be_applied_to_struct_enum, code = "E0701")]
96 pub struct NonExhaustiveWrongLocation {
97     #[primary_span]
98     pub attr_span: Span,
99     #[label]
100     pub defn_span: Span,
101 }
102
103 #[derive(Diagnostic)]
104 #[diag(passes::should_be_applied_to_trait)]
105 pub struct AttrShouldBeAppliedToTrait {
106     #[primary_span]
107     pub attr_span: Span,
108     #[label]
109     pub defn_span: Span,
110 }
111
112 #[derive(LintDiagnostic)]
113 #[diag(passes::target_feature_on_statement)]
114 pub struct TargetFeatureOnStatement;
115
116 #[derive(Diagnostic)]
117 #[diag(passes::should_be_applied_to_static)]
118 pub struct AttrShouldBeAppliedToStatic {
119     #[primary_span]
120     pub attr_span: Span,
121     #[label]
122     pub defn_span: Span,
123 }
124
125 #[derive(Diagnostic)]
126 #[diag(passes::doc_expect_str)]
127 pub struct DocExpectStr<'a> {
128     #[primary_span]
129     pub attr_span: Span,
130     pub attr_name: &'a str,
131 }
132
133 #[derive(Diagnostic)]
134 #[diag(passes::doc_alias_empty)]
135 pub struct DocAliasEmpty<'a> {
136     #[primary_span]
137     pub span: Span,
138     pub attr_str: &'a str,
139 }
140
141 #[derive(Diagnostic)]
142 #[diag(passes::doc_alias_bad_char)]
143 pub struct DocAliasBadChar<'a> {
144     #[primary_span]
145     pub span: Span,
146     pub attr_str: &'a str,
147     pub char_: char,
148 }
149
150 #[derive(Diagnostic)]
151 #[diag(passes::doc_alias_start_end)]
152 pub struct DocAliasStartEnd<'a> {
153     #[primary_span]
154     pub span: Span,
155     pub attr_str: &'a str,
156 }
157
158 #[derive(Diagnostic)]
159 #[diag(passes::doc_alias_bad_location)]
160 pub struct DocAliasBadLocation<'a> {
161     #[primary_span]
162     pub span: Span,
163     pub attr_str: &'a str,
164     pub location: &'a str,
165 }
166
167 #[derive(Diagnostic)]
168 #[diag(passes::doc_alias_not_an_alias)]
169 pub struct DocAliasNotAnAlias<'a> {
170     #[primary_span]
171     pub span: Span,
172     pub attr_str: &'a str,
173 }
174
175 #[derive(LintDiagnostic)]
176 #[diag(passes::doc_alias_duplicated)]
177 pub struct DocAliasDuplicated {
178     #[label]
179     pub first_defn: Span,
180 }
181
182 #[derive(Diagnostic)]
183 #[diag(passes::doc_alias_not_string_literal)]
184 pub struct DocAliasNotStringLiteral {
185     #[primary_span]
186     pub span: Span,
187 }
188
189 #[derive(Diagnostic)]
190 #[diag(passes::doc_alias_malformed)]
191 pub struct DocAliasMalformed {
192     #[primary_span]
193     pub span: Span,
194 }
195
196 #[derive(Diagnostic)]
197 #[diag(passes::doc_keyword_empty_mod)]
198 pub struct DocKeywordEmptyMod {
199     #[primary_span]
200     pub span: Span,
201 }
202
203 #[derive(Diagnostic)]
204 #[diag(passes::doc_keyword_not_mod)]
205 pub struct DocKeywordNotMod {
206     #[primary_span]
207     pub span: Span,
208 }
209
210 #[derive(Diagnostic)]
211 #[diag(passes::doc_keyword_invalid_ident)]
212 pub struct DocKeywordInvalidIdent {
213     #[primary_span]
214     pub span: Span,
215     pub doc_keyword: Symbol,
216 }
217
218 #[derive(Diagnostic)]
219 #[diag(passes::doc_fake_variadic_not_valid)]
220 pub struct DocFakeVariadicNotValid {
221     #[primary_span]
222     pub span: Span,
223 }
224
225 #[derive(Diagnostic)]
226 #[diag(passes::doc_keyword_only_impl)]
227 pub struct DocKeywordOnlyImpl {
228     #[primary_span]
229     pub span: Span,
230 }
231
232 #[derive(Diagnostic)]
233 #[diag(passes::doc_inline_conflict)]
234 #[help]
235 pub struct DocKeywordConflict {
236     #[primary_span]
237     pub spans: MultiSpan,
238 }
239
240 #[derive(LintDiagnostic)]
241 #[diag(passes::doc_inline_only_use)]
242 #[note]
243 pub struct DocInlineOnlyUse {
244     #[label]
245     pub attr_span: Span,
246     #[label(passes::not_a_use_item_label)]
247     pub item_span: Option<Span>,
248 }
249
250 #[derive(Diagnostic)]
251 #[diag(passes::doc_attr_not_crate_level)]
252 pub struct DocAttrNotCrateLevel<'a> {
253     #[primary_span]
254     pub span: Span,
255     pub attr_name: &'a str,
256 }
257
258 #[derive(LintDiagnostic)]
259 #[diag(passes::doc_test_unknown)]
260 pub struct DocTestUnknown {
261     pub path: String,
262 }
263
264 #[derive(LintDiagnostic)]
265 #[diag(passes::doc_test_takes_list)]
266 pub struct DocTestTakesList;
267
268 #[derive(LintDiagnostic)]
269 #[diag(passes::doc_primitive)]
270 pub struct DocPrimitive;
271
272 #[derive(LintDiagnostic)]
273 #[diag(passes::doc_test_unknown_any)]
274 pub struct DocTestUnknownAny {
275     pub path: String,
276 }
277
278 #[derive(LintDiagnostic)]
279 #[diag(passes::doc_test_unknown_spotlight)]
280 #[note]
281 #[note(passes::no_op_note)]
282 pub struct DocTestUnknownSpotlight {
283     pub path: String,
284     #[suggestion_short(applicability = "machine-applicable", code = "notable_trait")]
285     pub span: Span,
286 }
287
288 #[derive(LintDiagnostic)]
289 #[diag(passes::doc_test_unknown_include)]
290 pub struct DocTestUnknownInclude {
291     pub path: String,
292     pub value: String,
293     pub inner: &'static str,
294     #[suggestion(code = "#{inner}[doc = include_str!(\"{value}\")]")]
295     pub sugg: (Span, Applicability),
296 }
297
298 #[derive(LintDiagnostic)]
299 #[diag(passes::doc_invalid)]
300 pub struct DocInvalid;
301
302 #[derive(Diagnostic)]
303 #[diag(passes::pass_by_value)]
304 pub struct PassByValue {
305     #[primary_span]
306     pub attr_span: Span,
307     #[label]
308     pub span: Span,
309 }
310
311 #[derive(Diagnostic)]
312 #[diag(passes::allow_incoherent_impl)]
313 pub struct AllowIncoherentImpl {
314     #[primary_span]
315     pub attr_span: Span,
316     #[label]
317     pub span: Span,
318 }
319
320 #[derive(Diagnostic)]
321 #[diag(passes::has_incoherent_inherent_impl)]
322 pub struct HasIncoherentInherentImpl {
323     #[primary_span]
324     pub attr_span: Span,
325     #[label]
326     pub span: Span,
327 }
328
329 #[derive(LintDiagnostic)]
330 #[diag(passes::must_use_async)]
331 pub struct MustUseAsync {
332     #[label]
333     pub span: Span,
334 }
335
336 #[derive(LintDiagnostic)]
337 #[diag(passes::must_use_no_effect)]
338 pub struct MustUseNoEffect {
339     pub article: &'static str,
340     pub target: rustc_hir::Target,
341 }
342
343 #[derive(Diagnostic)]
344 #[diag(passes::must_not_suspend)]
345 pub struct MustNotSuspend {
346     #[primary_span]
347     pub attr_span: Span,
348     #[label]
349     pub span: Span,
350 }
351
352 #[derive(LintDiagnostic)]
353 #[diag(passes::cold)]
354 #[warning]
355 pub struct Cold {
356     #[label]
357     pub span: Span,
358 }
359
360 #[derive(LintDiagnostic)]
361 #[diag(passes::link)]
362 #[warning]
363 pub struct Link {
364     #[label]
365     pub span: Option<Span>,
366 }
367
368 #[derive(LintDiagnostic)]
369 #[diag(passes::link_name)]
370 #[warning]
371 pub struct LinkName<'a> {
372     #[help]
373     pub attr_span: Option<Span>,
374     #[label]
375     pub span: Span,
376     pub value: &'a str,
377 }
378
379 #[derive(Diagnostic)]
380 #[diag(passes::no_link)]
381 pub struct NoLink {
382     #[primary_span]
383     pub attr_span: Span,
384     #[label]
385     pub span: Span,
386 }
387
388 #[derive(Diagnostic)]
389 #[diag(passes::export_name)]
390 pub struct ExportName {
391     #[primary_span]
392     pub attr_span: Span,
393     #[label]
394     pub span: Span,
395 }
396
397 #[derive(Diagnostic)]
398 #[diag(passes::rustc_layout_scalar_valid_range_not_struct)]
399 pub struct RustcLayoutScalarValidRangeNotStruct {
400     #[primary_span]
401     pub attr_span: Span,
402     #[label]
403     pub span: Span,
404 }
405
406 #[derive(Diagnostic)]
407 #[diag(passes::rustc_layout_scalar_valid_range_arg)]
408 pub struct RustcLayoutScalarValidRangeArg {
409     #[primary_span]
410     pub attr_span: Span,
411 }
412
413 #[derive(Diagnostic)]
414 #[diag(passes::rustc_legacy_const_generics_only)]
415 pub struct RustcLegacyConstGenericsOnly {
416     #[primary_span]
417     pub attr_span: Span,
418     #[label]
419     pub param_span: Span,
420 }
421
422 #[derive(Diagnostic)]
423 #[diag(passes::rustc_legacy_const_generics_index)]
424 pub struct RustcLegacyConstGenericsIndex {
425     #[primary_span]
426     pub attr_span: Span,
427     #[label]
428     pub generics_span: Span,
429 }
430
431 #[derive(Diagnostic)]
432 #[diag(passes::rustc_legacy_const_generics_index_exceed)]
433 pub struct RustcLegacyConstGenericsIndexExceed {
434     #[primary_span]
435     #[label]
436     pub span: Span,
437     pub arg_count: usize,
438 }
439
440 #[derive(Diagnostic)]
441 #[diag(passes::rustc_legacy_const_generics_index_negative)]
442 pub struct RustcLegacyConstGenericsIndexNegative {
443     #[primary_span]
444     pub invalid_args: Vec<Span>,
445 }
446
447 #[derive(Diagnostic)]
448 #[diag(passes::rustc_dirty_clean)]
449 pub struct RustcDirtyClean {
450     #[primary_span]
451     pub span: Span,
452 }
453
454 #[derive(LintDiagnostic)]
455 #[diag(passes::link_section)]
456 #[warning]
457 pub struct LinkSection {
458     #[label]
459     pub span: Span,
460 }
461
462 #[derive(LintDiagnostic)]
463 #[diag(passes::no_mangle_foreign)]
464 #[warning]
465 #[note]
466 pub struct NoMangleForeign {
467     #[label]
468     pub span: Span,
469     #[suggestion(code = "", applicability = "machine-applicable")]
470     pub attr_span: Span,
471     pub foreign_item_kind: &'static str,
472 }
473
474 #[derive(LintDiagnostic)]
475 #[diag(passes::no_mangle)]
476 #[warning]
477 pub struct NoMangle {
478     #[label]
479     pub span: Span,
480 }
481
482 #[derive(Diagnostic)]
483 #[diag(passes::repr_ident, code = "E0565")]
484 pub struct ReprIdent {
485     #[primary_span]
486     pub span: Span,
487 }
488
489 #[derive(LintDiagnostic)]
490 #[diag(passes::repr_conflicting, code = "E0566")]
491 pub struct ReprConflicting;
492
493 #[derive(Diagnostic)]
494 #[diag(passes::used_static)]
495 pub struct UsedStatic {
496     #[primary_span]
497     pub span: Span,
498 }
499
500 #[derive(Diagnostic)]
501 #[diag(passes::used_compiler_linker)]
502 pub struct UsedCompilerLinker {
503     #[primary_span]
504     pub spans: Vec<Span>,
505 }
506
507 #[derive(Diagnostic)]
508 #[diag(passes::allow_internal_unstable)]
509 pub struct AllowInternalUnstable {
510     #[primary_span]
511     pub attr_span: Span,
512     #[label]
513     pub span: Span,
514 }
515
516 #[derive(Diagnostic)]
517 #[diag(passes::debug_visualizer_placement)]
518 pub struct DebugVisualizerPlacement {
519     #[primary_span]
520     pub span: Span,
521 }
522
523 #[derive(Diagnostic)]
524 #[diag(passes::debug_visualizer_invalid)]
525 #[note(passes::note_1)]
526 #[note(passes::note_2)]
527 #[note(passes::note_3)]
528 pub struct DebugVisualizerInvalid {
529     #[primary_span]
530     pub span: Span,
531 }
532
533 #[derive(Diagnostic)]
534 #[diag(passes::debug_visualizer_unreadable)]
535 pub struct DebugVisualizerUnreadable<'a> {
536     #[primary_span]
537     pub span: Span,
538     pub file: &'a Path,
539     pub error: Error,
540 }
541
542 #[derive(Diagnostic)]
543 #[diag(passes::rustc_allow_const_fn_unstable)]
544 pub struct RustcAllowConstFnUnstable {
545     #[primary_span]
546     pub attr_span: Span,
547     #[label]
548     pub span: Span,
549 }
550
551 #[derive(Diagnostic)]
552 #[diag(passes::rustc_std_internal_symbol)]
553 pub struct RustcStdInternalSymbol {
554     #[primary_span]
555     pub attr_span: Span,
556     #[label]
557     pub span: Span,
558 }
559
560 #[derive(Diagnostic)]
561 #[diag(passes::const_trait)]
562 pub struct ConstTrait {
563     #[primary_span]
564     pub attr_span: Span,
565 }
566
567 #[derive(Diagnostic)]
568 #[diag(passes::link_ordinal)]
569 pub struct LinkOrdinal {
570     #[primary_span]
571     pub attr_span: Span,
572 }
573
574 #[derive(Diagnostic)]
575 #[diag(passes::stability_promotable)]
576 pub struct StabilityPromotable {
577     #[primary_span]
578     pub attr_span: Span,
579 }
580
581 #[derive(LintDiagnostic)]
582 #[diag(passes::deprecated)]
583 pub struct Deprecated;
584
585 #[derive(LintDiagnostic)]
586 #[diag(passes::macro_use)]
587 pub struct MacroUse {
588     pub name: Symbol,
589 }
590
591 #[derive(LintDiagnostic)]
592 #[diag(passes::macro_export)]
593 pub struct MacroExport;
594
595 #[derive(LintDiagnostic)]
596 #[diag(passes::plugin_registrar)]
597 pub struct PluginRegistrar;
598
599 #[derive(Subdiagnostic)]
600 pub enum UnusedNote {
601     #[note(passes::unused_empty_lints_note)]
602     EmptyList { name: Symbol },
603     #[note(passes::unused_no_lints_note)]
604     NoLints { name: Symbol },
605     #[note(passes::unused_default_method_body_const_note)]
606     DefaultMethodBodyConst,
607 }
608
609 #[derive(LintDiagnostic)]
610 #[diag(passes::unused)]
611 pub struct Unused {
612     #[suggestion(code = "", applicability = "machine-applicable")]
613     pub attr_span: Span,
614     #[subdiagnostic]
615     pub note: UnusedNote,
616 }
617
618 #[derive(Diagnostic)]
619 #[diag(passes::non_exported_macro_invalid_attrs, code = "E0518")]
620 pub struct NonExportedMacroInvalidAttrs {
621     #[primary_span]
622     #[label]
623     pub attr_span: Span,
624 }
625
626 #[derive(LintDiagnostic)]
627 #[diag(passes::unused_duplicate)]
628 pub struct UnusedDuplicate {
629     #[suggestion(code = "", applicability = "machine-applicable")]
630     pub this: Span,
631     #[note]
632     pub other: Span,
633     #[warning]
634     pub warning: Option<()>,
635 }
636
637 #[derive(Diagnostic)]
638 #[diag(passes::unused_multiple)]
639 pub struct UnusedMultiple {
640     #[primary_span]
641     #[suggestion(code = "", applicability = "machine-applicable")]
642     pub this: Span,
643     #[note]
644     pub other: Span,
645     pub name: Symbol,
646 }
647
648 #[derive(Diagnostic)]
649 #[diag(passes::rustc_lint_opt_ty)]
650 pub struct RustcLintOptTy {
651     #[primary_span]
652     pub attr_span: Span,
653     #[label]
654     pub span: Span,
655 }
656
657 #[derive(Diagnostic)]
658 #[diag(passes::rustc_lint_opt_deny_field_access)]
659 pub struct RustcLintOptDenyFieldAccess {
660     #[primary_span]
661     pub attr_span: Span,
662     #[label]
663     pub span: Span,
664 }
665
666 #[derive(Diagnostic)]
667 #[diag(passes::collapse_debuginfo)]
668 pub struct CollapseDebuginfo {
669     #[primary_span]
670     pub attr_span: Span,
671     #[label]
672     pub defn_span: Span,
673 }
674
675 #[derive(LintDiagnostic)]
676 #[diag(passes::deprecated_annotation_has_no_effect)]
677 pub struct DeprecatedAnnotationHasNoEffect {
678     #[suggestion(applicability = "machine-applicable", code = "")]
679     pub span: Span,
680 }
681
682 #[derive(Diagnostic)]
683 #[diag(passes::unknown_external_lang_item, code = "E0264")]
684 pub struct UnknownExternLangItem {
685     #[primary_span]
686     pub span: Span,
687     pub lang_item: Symbol,
688 }
689
690 #[derive(Diagnostic)]
691 #[diag(passes::missing_panic_handler)]
692 pub struct MissingPanicHandler;
693
694 #[derive(Diagnostic)]
695 #[diag(passes::alloc_func_required)]
696 pub struct AllocFuncRequired;
697
698 #[derive(Diagnostic)]
699 #[diag(passes::missing_alloc_error_handler)]
700 pub struct MissingAllocErrorHandler;
701
702 #[derive(Diagnostic)]
703 #[diag(passes::missing_lang_item)]
704 #[note]
705 #[help]
706 pub struct MissingLangItem {
707     pub name: Symbol,
708 }
709
710 #[derive(Diagnostic)]
711 #[diag(passes::lang_item_on_incorrect_target, code = "E0718")]
712 pub struct LangItemOnIncorrectTarget {
713     #[primary_span]
714     #[label]
715     pub span: Span,
716     pub name: Symbol,
717     pub expected_target: Target,
718     pub actual_target: Target,
719 }
720
721 #[derive(Diagnostic)]
722 #[diag(passes::unknown_lang_item, code = "E0522")]
723 pub struct UnknownLangItem {
724     #[primary_span]
725     #[label]
726     pub span: Span,
727     pub name: Symbol,
728 }
729
730 pub struct InvalidAttrAtCrateLevel {
731     pub span: Span,
732     pub snippet: Option<String>,
733     pub name: Symbol,
734 }
735
736 impl IntoDiagnostic<'_> for InvalidAttrAtCrateLevel {
737     fn into_diagnostic(
738         self,
739         handler: &'_ rustc_errors::Handler,
740     ) -> rustc_errors::DiagnosticBuilder<'_, ErrorGuaranteed> {
741         let mut diag =
742             handler.struct_err(rustc_errors::fluent::passes::invalid_attr_at_crate_level);
743         diag.set_span(self.span);
744         diag.set_arg("name", self.name);
745         // Only emit an error with a suggestion if we can create a string out
746         // of the attribute span
747         if let Some(src) = self.snippet {
748             let replacement = src.replace("#!", "#");
749             diag.span_suggestion_verbose(
750                 self.span,
751                 rustc_errors::fluent::passes::suggestion,
752                 replacement,
753                 rustc_errors::Applicability::MachineApplicable,
754             );
755         }
756         diag
757     }
758 }
759
760 #[derive(Diagnostic)]
761 #[diag(passes::duplicate_diagnostic_item)]
762 pub struct DuplicateDiagnosticItem {
763     #[primary_span]
764     pub span: Span,
765     pub name: Symbol,
766 }
767
768 #[derive(Diagnostic)]
769 #[diag(passes::duplicate_diagnostic_item_in_crate)]
770 pub struct DuplicateDiagnosticItemInCrate {
771     #[note(passes::diagnostic_item_first_defined)]
772     pub span: Option<Span>,
773     pub orig_crate_name: Symbol,
774     #[note]
775     pub have_orig_crate_name: Option<()>,
776     pub crate_name: Symbol,
777     pub name: Symbol,
778 }
779
780 #[derive(Diagnostic)]
781 #[diag(passes::abi)]
782 pub struct Abi {
783     #[primary_span]
784     pub span: Span,
785     pub abi: String,
786 }
787
788 #[derive(Diagnostic)]
789 #[diag(passes::align)]
790 pub struct Align {
791     #[primary_span]
792     pub span: Span,
793     pub align: String,
794 }
795
796 #[derive(Diagnostic)]
797 #[diag(passes::size)]
798 pub struct Size {
799     #[primary_span]
800     pub span: Span,
801     pub size: String,
802 }
803
804 #[derive(Diagnostic)]
805 #[diag(passes::homogeneous_aggregate)]
806 pub struct HomogeneousAggregate {
807     #[primary_span]
808     pub span: Span,
809     pub homogeneous_aggregate: String,
810 }
811
812 #[derive(Diagnostic)]
813 #[diag(passes::layout_of)]
814 pub struct LayoutOf {
815     #[primary_span]
816     pub span: Span,
817     pub normalized_ty: String,
818     pub ty_layout: String,
819 }
820
821 #[derive(Diagnostic)]
822 #[diag(passes::unrecognized_field)]
823 pub struct UnrecognizedField {
824     #[primary_span]
825     pub span: Span,
826     pub name: Symbol,
827 }
828
829 #[derive(Diagnostic)]
830 #[diag(passes::layout)]
831 pub struct Layout {
832     #[primary_span]
833     pub span: Span,
834     pub layout_error: String,
835 }
836
837 #[derive(Diagnostic)]
838 #[diag(passes::feature_stable_twice, code = "E0711")]
839 pub struct FeatureStableTwice {
840     #[primary_span]
841     pub span: Span,
842     pub feature: Symbol,
843     pub since: Symbol,
844     pub prev_since: Symbol,
845 }
846
847 #[derive(Diagnostic)]
848 #[diag(passes::feature_previously_declared, code = "E0711")]
849 pub struct FeaturePreviouslyDeclared<'a, 'b> {
850     #[primary_span]
851     pub span: Span,
852     pub feature: Symbol,
853     pub declared: &'a str,
854     pub prev_declared: &'b str,
855 }
856
857 #[derive(Diagnostic)]
858 #[diag(passes::expr_not_allowed_in_context, code = "E0744")]
859 pub struct ExprNotAllowedInContext<'a> {
860     #[primary_span]
861     pub span: Span,
862     pub expr: String,
863     pub context: &'a str,
864 }
865
866 #[derive(Diagnostic)]
867 #[diag(passes::const_impl_const_trait)]
868 pub struct ConstImplConstTrait {
869     #[primary_span]
870     pub span: Span,
871     #[note]
872     pub def_span: Span,
873 }
874
875 pub struct BreakNonLoop<'a> {
876     pub span: Span,
877     pub head: Option<Span>,
878     pub kind: &'a str,
879     pub suggestion: String,
880     pub loop_label: Option<Label>,
881     pub break_label: Option<Label>,
882     pub break_expr_kind: &'a ExprKind<'a>,
883     pub break_expr_span: Span,
884 }
885
886 impl<'a> IntoDiagnostic<'_> for BreakNonLoop<'a> {
887     fn into_diagnostic(
888         self,
889         handler: &rustc_errors::Handler,
890     ) -> rustc_errors::DiagnosticBuilder<'_, ErrorGuaranteed> {
891         let mut diag = handler.struct_span_err_with_code(
892             self.span,
893             rustc_errors::fluent::passes::break_non_loop,
894             error_code!(E0571),
895         );
896         diag.set_arg("kind", self.kind);
897         diag.span_label(self.span, rustc_errors::fluent::passes::label);
898         if let Some(head) = self.head {
899             diag.span_label(head, rustc_errors::fluent::passes::label2);
900         }
901         diag.span_suggestion(
902             self.span,
903             rustc_errors::fluent::passes::suggestion,
904             self.suggestion,
905             Applicability::MaybeIncorrect,
906         );
907         if let (Some(label), None) = (self.loop_label, self.break_label) {
908             match self.break_expr_kind {
909                 ExprKind::Path(hir::QPath::Resolved(
910                     None,
911                     hir::Path { segments: [segment], res: hir::def::Res::Err, .. },
912                 )) if label.ident.to_string() == format!("'{}", segment.ident) => {
913                     // This error is redundant, we will have already emitted a
914                     // suggestion to use the label when `segment` wasn't found
915                     // (hence the `Res::Err` check).
916                     diag.delay_as_bug();
917                 }
918                 _ => {
919                     diag.span_suggestion(
920                         self.break_expr_span,
921                         rustc_errors::fluent::passes::break_expr_suggestion,
922                         label.ident,
923                         Applicability::MaybeIncorrect,
924                     );
925                 }
926             }
927         }
928         diag
929     }
930 }
931
932 #[derive(Diagnostic)]
933 #[diag(passes::continue_labeled_block, code = "E0696")]
934 pub struct ContinueLabeledBlock {
935     #[primary_span]
936     #[label]
937     pub span: Span,
938     #[label(passes::block_label)]
939     pub block_span: Span,
940 }
941
942 #[derive(Diagnostic)]
943 #[diag(passes::break_inside_closure, code = "E0267")]
944 pub struct BreakInsideClosure<'a> {
945     #[primary_span]
946     #[label]
947     pub span: Span,
948     #[label(passes::closure_label)]
949     pub closure_span: Span,
950     pub name: &'a str,
951 }
952
953 #[derive(Diagnostic)]
954 #[diag(passes::break_inside_async_block, code = "E0267")]
955 pub struct BreakInsideAsyncBlock<'a> {
956     #[primary_span]
957     #[label]
958     pub span: Span,
959     #[label(passes::async_block_label)]
960     pub closure_span: Span,
961     pub name: &'a str,
962 }
963
964 #[derive(Diagnostic)]
965 #[diag(passes::outside_loop, code = "E0268")]
966 pub struct OutsideLoop<'a> {
967     #[primary_span]
968     #[label]
969     pub span: Span,
970     pub name: &'a str,
971 }
972
973 #[derive(Diagnostic)]
974 #[diag(passes::unlabeled_in_labeled_block, code = "E0695")]
975 pub struct UnlabeledInLabeledBlock<'a> {
976     #[primary_span]
977     #[label]
978     pub span: Span,
979     pub cf_type: &'a str,
980 }
981
982 #[derive(Diagnostic)]
983 #[diag(passes::unlabeled_cf_in_while_condition, code = "E0590")]
984 pub struct UnlabeledCfInWhileCondition<'a> {
985     #[primary_span]
986     #[label]
987     pub span: Span,
988     pub cf_type: &'a str,
989 }