]> git.lizzy.rs Git - rust.git/blob - compiler/rustc_passes/src/errors.rs
Rollup merge of #105859 - compiler-errors:hr-lifetime-add, r=davidtwco
[rust.git] / compiler / rustc_passes / src / errors.rs
1 use std::{
2     io::Error,
3     path::{Path, PathBuf},
4 };
5
6 use rustc_ast::Label;
7 use rustc_errors::{
8     error_code, Applicability, DiagnosticSymbolList, ErrorGuaranteed, IntoDiagnostic, MultiSpan,
9 };
10 use rustc_hir::{self as hir, ExprKind, Target};
11 use rustc_macros::{Diagnostic, LintDiagnostic, Subdiagnostic};
12 use rustc_middle::ty::{MainDefinition, Ty};
13 use rustc_span::{Span, Symbol, DUMMY_SP};
14
15 use crate::lang_items::Duplicate;
16
17 #[derive(LintDiagnostic)]
18 #[diag(passes_outer_crate_level_attr)]
19 pub struct OuterCrateLevelAttr;
20
21 #[derive(LintDiagnostic)]
22 #[diag(passes_inner_crate_level_attr)]
23 pub struct InnerCrateLevelAttr;
24
25 #[derive(LintDiagnostic)]
26 #[diag(passes_ignored_attr_with_macro)]
27 pub struct IgnoredAttrWithMacro<'a> {
28     pub sym: &'a str,
29 }
30
31 #[derive(LintDiagnostic)]
32 #[diag(passes_ignored_attr)]
33 pub struct IgnoredAttr<'a> {
34     pub sym: &'a str,
35 }
36
37 #[derive(LintDiagnostic)]
38 #[diag(passes_inline_ignored_function_prototype)]
39 pub struct IgnoredInlineAttrFnProto;
40
41 #[derive(LintDiagnostic)]
42 #[diag(passes_inline_ignored_constants)]
43 #[warning]
44 #[note]
45 pub struct IgnoredInlineAttrConstants;
46
47 #[derive(Diagnostic)]
48 #[diag(passes_inline_not_fn_or_closure, code = "E0518")]
49 pub struct InlineNotFnOrClosure {
50     #[primary_span]
51     pub attr_span: Span,
52     #[label]
53     pub defn_span: Span,
54 }
55
56 #[derive(LintDiagnostic)]
57 #[diag(passes_no_coverage_ignored_function_prototype)]
58 pub struct IgnoredNoCoverageFnProto;
59
60 #[derive(LintDiagnostic)]
61 #[diag(passes_no_coverage_propagate)]
62 pub struct IgnoredNoCoveragePropagate;
63
64 #[derive(LintDiagnostic)]
65 #[diag(passes_no_coverage_fn_defn)]
66 pub struct IgnoredNoCoverageFnDefn;
67
68 #[derive(Diagnostic)]
69 #[diag(passes_no_coverage_not_coverable, code = "E0788")]
70 pub struct IgnoredNoCoverageNotCoverable {
71     #[primary_span]
72     pub attr_span: Span,
73     #[label]
74     pub defn_span: Span,
75 }
76
77 #[derive(Diagnostic)]
78 #[diag(passes_should_be_applied_to_fn)]
79 pub struct AttrShouldBeAppliedToFn {
80     #[primary_span]
81     pub attr_span: Span,
82     #[label]
83     pub defn_span: Span,
84     pub on_crate: bool,
85 }
86
87 #[derive(Diagnostic)]
88 #[diag(passes_naked_tracked_caller, code = "E0736")]
89 pub struct NakedTrackedCaller {
90     #[primary_span]
91     pub attr_span: Span,
92 }
93
94 #[derive(Diagnostic)]
95 #[diag(passes_should_be_applied_to_fn, code = "E0739")]
96 pub struct TrackedCallerWrongLocation {
97     #[primary_span]
98     pub attr_span: Span,
99     #[label]
100     pub defn_span: Span,
101     pub on_crate: bool,
102 }
103
104 #[derive(Diagnostic)]
105 #[diag(passes_should_be_applied_to_struct_enum, code = "E0701")]
106 pub struct NonExhaustiveWrongLocation {
107     #[primary_span]
108     pub attr_span: Span,
109     #[label]
110     pub defn_span: Span,
111 }
112
113 #[derive(Diagnostic)]
114 #[diag(passes_should_be_applied_to_trait)]
115 pub struct AttrShouldBeAppliedToTrait {
116     #[primary_span]
117     pub attr_span: Span,
118     #[label]
119     pub defn_span: Span,
120 }
121
122 #[derive(LintDiagnostic)]
123 #[diag(passes_target_feature_on_statement)]
124 pub struct TargetFeatureOnStatement;
125
126 #[derive(Diagnostic)]
127 #[diag(passes_should_be_applied_to_static)]
128 pub struct AttrShouldBeAppliedToStatic {
129     #[primary_span]
130     pub attr_span: Span,
131     #[label]
132     pub defn_span: Span,
133 }
134
135 #[derive(Diagnostic)]
136 #[diag(passes_doc_expect_str)]
137 pub struct DocExpectStr<'a> {
138     #[primary_span]
139     pub attr_span: Span,
140     pub attr_name: &'a str,
141 }
142
143 #[derive(Diagnostic)]
144 #[diag(passes_doc_alias_empty)]
145 pub struct DocAliasEmpty<'a> {
146     #[primary_span]
147     pub span: Span,
148     pub attr_str: &'a str,
149 }
150
151 #[derive(Diagnostic)]
152 #[diag(passes_doc_alias_bad_char)]
153 pub struct DocAliasBadChar<'a> {
154     #[primary_span]
155     pub span: Span,
156     pub attr_str: &'a str,
157     pub char_: char,
158 }
159
160 #[derive(Diagnostic)]
161 #[diag(passes_doc_alias_start_end)]
162 pub struct DocAliasStartEnd<'a> {
163     #[primary_span]
164     pub span: Span,
165     pub attr_str: &'a str,
166 }
167
168 #[derive(Diagnostic)]
169 #[diag(passes_doc_alias_bad_location)]
170 pub struct DocAliasBadLocation<'a> {
171     #[primary_span]
172     pub span: Span,
173     pub attr_str: &'a str,
174     pub location: &'a str,
175 }
176
177 #[derive(Diagnostic)]
178 #[diag(passes_doc_alias_not_an_alias)]
179 pub struct DocAliasNotAnAlias<'a> {
180     #[primary_span]
181     pub span: Span,
182     pub attr_str: &'a str,
183 }
184
185 #[derive(LintDiagnostic)]
186 #[diag(passes_doc_alias_duplicated)]
187 pub struct DocAliasDuplicated {
188     #[label]
189     pub first_defn: Span,
190 }
191
192 #[derive(Diagnostic)]
193 #[diag(passes_doc_alias_not_string_literal)]
194 pub struct DocAliasNotStringLiteral {
195     #[primary_span]
196     pub span: Span,
197 }
198
199 #[derive(Diagnostic)]
200 #[diag(passes_doc_alias_malformed)]
201 pub struct DocAliasMalformed {
202     #[primary_span]
203     pub span: Span,
204 }
205
206 #[derive(Diagnostic)]
207 #[diag(passes_doc_keyword_empty_mod)]
208 pub struct DocKeywordEmptyMod {
209     #[primary_span]
210     pub span: Span,
211 }
212
213 #[derive(Diagnostic)]
214 #[diag(passes_doc_keyword_not_mod)]
215 pub struct DocKeywordNotMod {
216     #[primary_span]
217     pub span: Span,
218 }
219
220 #[derive(Diagnostic)]
221 #[diag(passes_doc_keyword_invalid_ident)]
222 pub struct DocKeywordInvalidIdent {
223     #[primary_span]
224     pub span: Span,
225     pub doc_keyword: Symbol,
226 }
227
228 #[derive(Diagnostic)]
229 #[diag(passes_doc_fake_variadic_not_valid)]
230 pub struct DocFakeVariadicNotValid {
231     #[primary_span]
232     pub span: Span,
233 }
234
235 #[derive(Diagnostic)]
236 #[diag(passes_doc_keyword_only_impl)]
237 pub struct DocKeywordOnlyImpl {
238     #[primary_span]
239     pub span: Span,
240 }
241
242 #[derive(Diagnostic)]
243 #[diag(passes_doc_inline_conflict)]
244 #[help]
245 pub struct DocKeywordConflict {
246     #[primary_span]
247     pub spans: MultiSpan,
248 }
249
250 #[derive(LintDiagnostic)]
251 #[diag(passes_doc_inline_only_use)]
252 #[note]
253 pub struct DocInlineOnlyUse {
254     #[label]
255     pub attr_span: Span,
256     #[label(not_a_use_item_label)]
257     pub item_span: Option<Span>,
258 }
259
260 #[derive(Diagnostic)]
261 #[diag(passes_doc_attr_not_crate_level)]
262 pub struct DocAttrNotCrateLevel<'a> {
263     #[primary_span]
264     pub span: Span,
265     pub attr_name: &'a str,
266 }
267
268 #[derive(LintDiagnostic)]
269 #[diag(passes_doc_test_unknown)]
270 pub struct DocTestUnknown {
271     pub path: String,
272 }
273
274 #[derive(LintDiagnostic)]
275 #[diag(passes_doc_test_takes_list)]
276 pub struct DocTestTakesList;
277
278 #[derive(LintDiagnostic)]
279 #[diag(passes_doc_cfg_hide_takes_list)]
280 pub struct DocCfgHideTakesList;
281
282 #[derive(LintDiagnostic)]
283 #[diag(passes_doc_primitive)]
284 pub struct DocPrimitive;
285
286 #[derive(LintDiagnostic)]
287 #[diag(passes_doc_test_unknown_any)]
288 pub struct DocTestUnknownAny {
289     pub path: String,
290 }
291
292 #[derive(LintDiagnostic)]
293 #[diag(passes_doc_test_unknown_spotlight)]
294 #[note]
295 #[note(no_op_note)]
296 pub struct DocTestUnknownSpotlight {
297     pub path: String,
298     #[suggestion(style = "short", applicability = "machine-applicable", code = "notable_trait")]
299     pub span: Span,
300 }
301
302 #[derive(LintDiagnostic)]
303 #[diag(passes_doc_test_unknown_include)]
304 pub struct DocTestUnknownInclude {
305     pub path: String,
306     pub value: String,
307     pub inner: &'static str,
308     #[suggestion(code = "#{inner}[doc = include_str!(\"{value}\")]")]
309     pub sugg: (Span, Applicability),
310 }
311
312 #[derive(LintDiagnostic)]
313 #[diag(passes_doc_invalid)]
314 pub struct DocInvalid;
315
316 #[derive(Diagnostic)]
317 #[diag(passes_pass_by_value)]
318 pub struct PassByValue {
319     #[primary_span]
320     pub attr_span: Span,
321     #[label]
322     pub span: Span,
323 }
324
325 #[derive(Diagnostic)]
326 #[diag(passes_allow_incoherent_impl)]
327 pub struct AllowIncoherentImpl {
328     #[primary_span]
329     pub attr_span: Span,
330     #[label]
331     pub span: Span,
332 }
333
334 #[derive(Diagnostic)]
335 #[diag(passes_has_incoherent_inherent_impl)]
336 pub struct HasIncoherentInherentImpl {
337     #[primary_span]
338     pub attr_span: Span,
339     #[label]
340     pub span: Span,
341 }
342
343 #[derive(LintDiagnostic)]
344 #[diag(passes_must_use_async)]
345 pub struct MustUseAsync {
346     #[label]
347     pub span: Span,
348 }
349
350 #[derive(LintDiagnostic)]
351 #[diag(passes_must_use_no_effect)]
352 pub struct MustUseNoEffect {
353     pub article: &'static str,
354     pub target: rustc_hir::Target,
355 }
356
357 #[derive(Diagnostic)]
358 #[diag(passes_must_not_suspend)]
359 pub struct MustNotSuspend {
360     #[primary_span]
361     pub attr_span: Span,
362     #[label]
363     pub span: Span,
364 }
365
366 #[derive(LintDiagnostic)]
367 #[diag(passes_cold)]
368 #[warning]
369 pub struct Cold {
370     #[label]
371     pub span: Span,
372     pub on_crate: bool,
373 }
374
375 #[derive(LintDiagnostic)]
376 #[diag(passes_link)]
377 #[warning]
378 pub struct Link {
379     #[label]
380     pub span: Option<Span>,
381 }
382
383 #[derive(LintDiagnostic)]
384 #[diag(passes_link_name)]
385 #[warning]
386 pub struct LinkName<'a> {
387     #[help]
388     pub attr_span: Option<Span>,
389     #[label]
390     pub span: Span,
391     pub value: &'a str,
392 }
393
394 #[derive(Diagnostic)]
395 #[diag(passes_no_link)]
396 pub struct NoLink {
397     #[primary_span]
398     pub attr_span: Span,
399     #[label]
400     pub span: Span,
401 }
402
403 #[derive(Diagnostic)]
404 #[diag(passes_export_name)]
405 pub struct ExportName {
406     #[primary_span]
407     pub attr_span: Span,
408     #[label]
409     pub span: Span,
410 }
411
412 #[derive(Diagnostic)]
413 #[diag(passes_rustc_layout_scalar_valid_range_not_struct)]
414 pub struct RustcLayoutScalarValidRangeNotStruct {
415     #[primary_span]
416     pub attr_span: Span,
417     #[label]
418     pub span: Span,
419 }
420
421 #[derive(Diagnostic)]
422 #[diag(passes_rustc_layout_scalar_valid_range_arg)]
423 pub struct RustcLayoutScalarValidRangeArg {
424     #[primary_span]
425     pub attr_span: Span,
426 }
427
428 #[derive(Diagnostic)]
429 #[diag(passes_rustc_legacy_const_generics_only)]
430 pub struct RustcLegacyConstGenericsOnly {
431     #[primary_span]
432     pub attr_span: Span,
433     #[label]
434     pub param_span: Span,
435 }
436
437 #[derive(Diagnostic)]
438 #[diag(passes_rustc_legacy_const_generics_index)]
439 pub struct RustcLegacyConstGenericsIndex {
440     #[primary_span]
441     pub attr_span: Span,
442     #[label]
443     pub generics_span: Span,
444 }
445
446 #[derive(Diagnostic)]
447 #[diag(passes_rustc_legacy_const_generics_index_exceed)]
448 pub struct RustcLegacyConstGenericsIndexExceed {
449     #[primary_span]
450     #[label]
451     pub span: Span,
452     pub arg_count: usize,
453 }
454
455 #[derive(Diagnostic)]
456 #[diag(passes_rustc_legacy_const_generics_index_negative)]
457 pub struct RustcLegacyConstGenericsIndexNegative {
458     #[primary_span]
459     pub invalid_args: Vec<Span>,
460 }
461
462 #[derive(Diagnostic)]
463 #[diag(passes_rustc_dirty_clean)]
464 pub struct RustcDirtyClean {
465     #[primary_span]
466     pub span: Span,
467 }
468
469 #[derive(LintDiagnostic)]
470 #[diag(passes_link_section)]
471 #[warning]
472 pub struct LinkSection {
473     #[label]
474     pub span: Span,
475 }
476
477 #[derive(LintDiagnostic)]
478 #[diag(passes_no_mangle_foreign)]
479 #[warning]
480 #[note]
481 pub struct NoMangleForeign {
482     #[label]
483     pub span: Span,
484     #[suggestion(code = "", applicability = "machine-applicable")]
485     pub attr_span: Span,
486     pub foreign_item_kind: &'static str,
487 }
488
489 #[derive(LintDiagnostic)]
490 #[diag(passes_no_mangle)]
491 #[warning]
492 pub struct NoMangle {
493     #[label]
494     pub span: Span,
495 }
496
497 #[derive(Diagnostic)]
498 #[diag(passes_repr_ident, code = "E0565")]
499 pub struct ReprIdent {
500     #[primary_span]
501     pub span: Span,
502 }
503
504 #[derive(LintDiagnostic)]
505 #[diag(passes_repr_conflicting, code = "E0566")]
506 pub struct ReprConflicting;
507
508 #[derive(Diagnostic)]
509 #[diag(passes_used_static)]
510 pub struct UsedStatic {
511     #[primary_span]
512     pub span: Span,
513 }
514
515 #[derive(Diagnostic)]
516 #[diag(passes_used_compiler_linker)]
517 pub struct UsedCompilerLinker {
518     #[primary_span]
519     pub spans: Vec<Span>,
520 }
521
522 #[derive(Diagnostic)]
523 #[diag(passes_allow_internal_unstable)]
524 pub struct AllowInternalUnstable {
525     #[primary_span]
526     pub attr_span: Span,
527     #[label]
528     pub span: Span,
529 }
530
531 #[derive(Diagnostic)]
532 #[diag(passes_debug_visualizer_placement)]
533 pub struct DebugVisualizerPlacement {
534     #[primary_span]
535     pub span: Span,
536 }
537
538 #[derive(Diagnostic)]
539 #[diag(passes_debug_visualizer_invalid)]
540 #[note(note_1)]
541 #[note(note_2)]
542 #[note(note_3)]
543 pub struct DebugVisualizerInvalid {
544     #[primary_span]
545     pub span: Span,
546 }
547
548 #[derive(Diagnostic)]
549 #[diag(passes_debug_visualizer_unreadable)]
550 pub struct DebugVisualizerUnreadable<'a> {
551     #[primary_span]
552     pub span: Span,
553     pub file: &'a Path,
554     pub error: Error,
555 }
556
557 #[derive(Diagnostic)]
558 #[diag(passes_rustc_allow_const_fn_unstable)]
559 pub struct RustcAllowConstFnUnstable {
560     #[primary_span]
561     pub attr_span: Span,
562     #[label]
563     pub span: Span,
564 }
565
566 #[derive(Diagnostic)]
567 #[diag(passes_rustc_std_internal_symbol)]
568 pub struct RustcStdInternalSymbol {
569     #[primary_span]
570     pub attr_span: Span,
571     #[label]
572     pub span: Span,
573 }
574
575 #[derive(Diagnostic)]
576 #[diag(passes_const_trait)]
577 pub struct ConstTrait {
578     #[primary_span]
579     pub attr_span: Span,
580 }
581
582 #[derive(Diagnostic)]
583 #[diag(passes_link_ordinal)]
584 pub struct LinkOrdinal {
585     #[primary_span]
586     pub attr_span: Span,
587 }
588
589 #[derive(Diagnostic)]
590 #[diag(passes_stability_promotable)]
591 pub struct StabilityPromotable {
592     #[primary_span]
593     pub attr_span: Span,
594 }
595
596 #[derive(LintDiagnostic)]
597 #[diag(passes_deprecated)]
598 pub struct Deprecated;
599
600 #[derive(LintDiagnostic)]
601 #[diag(passes_macro_use)]
602 pub struct MacroUse {
603     pub name: Symbol,
604 }
605
606 #[derive(LintDiagnostic)]
607 #[diag(passes_macro_export)]
608 pub struct MacroExport;
609
610 #[derive(LintDiagnostic)]
611 #[diag(passes_plugin_registrar)]
612 pub struct PluginRegistrar;
613
614 #[derive(Subdiagnostic)]
615 pub enum UnusedNote {
616     #[note(passes_unused_empty_lints_note)]
617     EmptyList { name: Symbol },
618     #[note(passes_unused_no_lints_note)]
619     NoLints { name: Symbol },
620     #[note(passes_unused_default_method_body_const_note)]
621     DefaultMethodBodyConst,
622 }
623
624 #[derive(LintDiagnostic)]
625 #[diag(passes_unused)]
626 pub struct Unused {
627     #[suggestion(code = "", applicability = "machine-applicable")]
628     pub attr_span: Span,
629     #[subdiagnostic]
630     pub note: UnusedNote,
631 }
632
633 #[derive(Diagnostic)]
634 #[diag(passes_non_exported_macro_invalid_attrs, code = "E0518")]
635 pub struct NonExportedMacroInvalidAttrs {
636     #[primary_span]
637     #[label]
638     pub attr_span: Span,
639 }
640
641 #[derive(LintDiagnostic)]
642 #[diag(passes_unused_duplicate)]
643 pub struct UnusedDuplicate {
644     #[suggestion(code = "", applicability = "machine-applicable")]
645     pub this: Span,
646     #[note]
647     pub other: Span,
648     #[warning]
649     pub warning: Option<()>,
650 }
651
652 #[derive(Diagnostic)]
653 #[diag(passes_unused_multiple)]
654 pub struct UnusedMultiple {
655     #[primary_span]
656     #[suggestion(code = "", applicability = "machine-applicable")]
657     pub this: Span,
658     #[note]
659     pub other: Span,
660     pub name: Symbol,
661 }
662
663 #[derive(Diagnostic)]
664 #[diag(passes_rustc_lint_opt_ty)]
665 pub struct RustcLintOptTy {
666     #[primary_span]
667     pub attr_span: Span,
668     #[label]
669     pub span: Span,
670 }
671
672 #[derive(Diagnostic)]
673 #[diag(passes_rustc_lint_opt_deny_field_access)]
674 pub struct RustcLintOptDenyFieldAccess {
675     #[primary_span]
676     pub attr_span: Span,
677     #[label]
678     pub span: Span,
679 }
680
681 #[derive(Diagnostic)]
682 #[diag(passes_collapse_debuginfo)]
683 pub struct CollapseDebuginfo {
684     #[primary_span]
685     pub attr_span: Span,
686     #[label]
687     pub defn_span: Span,
688 }
689
690 #[derive(LintDiagnostic)]
691 #[diag(passes_deprecated_annotation_has_no_effect)]
692 pub struct DeprecatedAnnotationHasNoEffect {
693     #[suggestion(applicability = "machine-applicable", code = "")]
694     pub span: Span,
695 }
696
697 #[derive(Diagnostic)]
698 #[diag(passes_unknown_external_lang_item, code = "E0264")]
699 pub struct UnknownExternLangItem {
700     #[primary_span]
701     pub span: Span,
702     pub lang_item: Symbol,
703 }
704
705 #[derive(Diagnostic)]
706 #[diag(passes_missing_panic_handler)]
707 pub struct MissingPanicHandler;
708
709 #[derive(Diagnostic)]
710 #[diag(passes_missing_lang_item)]
711 #[note]
712 #[help]
713 pub struct MissingLangItem {
714     pub name: Symbol,
715 }
716
717 #[derive(Diagnostic)]
718 #[diag(passes_lang_item_on_incorrect_target, code = "E0718")]
719 pub struct LangItemOnIncorrectTarget {
720     #[primary_span]
721     #[label]
722     pub span: Span,
723     pub name: Symbol,
724     pub expected_target: Target,
725     pub actual_target: Target,
726 }
727
728 #[derive(Diagnostic)]
729 #[diag(passes_unknown_lang_item, code = "E0522")]
730 pub struct UnknownLangItem {
731     #[primary_span]
732     #[label]
733     pub span: Span,
734     pub name: Symbol,
735 }
736
737 pub struct InvalidAttrAtCrateLevel {
738     pub span: Span,
739     pub snippet: Option<String>,
740     pub name: Symbol,
741 }
742
743 impl IntoDiagnostic<'_> for InvalidAttrAtCrateLevel {
744     #[track_caller]
745     fn into_diagnostic(
746         self,
747         handler: &'_ rustc_errors::Handler,
748     ) -> rustc_errors::DiagnosticBuilder<'_, ErrorGuaranteed> {
749         let mut diag = handler.struct_err(rustc_errors::fluent::passes_invalid_attr_at_crate_level);
750         diag.set_span(self.span);
751         diag.set_arg("name", self.name);
752         // Only emit an error with a suggestion if we can create a string out
753         // of the attribute span
754         if let Some(src) = self.snippet {
755             let replacement = src.replace("#!", "#");
756             diag.span_suggestion_verbose(
757                 self.span,
758                 rustc_errors::fluent::suggestion,
759                 replacement,
760                 rustc_errors::Applicability::MachineApplicable,
761             );
762         }
763         diag
764     }
765 }
766
767 #[derive(Diagnostic)]
768 #[diag(passes_duplicate_diagnostic_item)]
769 pub struct DuplicateDiagnosticItem {
770     #[primary_span]
771     pub span: Span,
772     pub name: Symbol,
773 }
774
775 #[derive(Diagnostic)]
776 #[diag(passes_duplicate_diagnostic_item_in_crate)]
777 pub struct DuplicateDiagnosticItemInCrate {
778     #[note(passes_diagnostic_item_first_defined)]
779     pub span: Option<Span>,
780     pub orig_crate_name: Symbol,
781     #[note]
782     pub have_orig_crate_name: Option<()>,
783     pub crate_name: Symbol,
784     pub name: Symbol,
785 }
786
787 #[derive(Diagnostic)]
788 #[diag(passes_abi)]
789 pub struct Abi {
790     #[primary_span]
791     pub span: Span,
792     pub abi: String,
793 }
794
795 #[derive(Diagnostic)]
796 #[diag(passes_align)]
797 pub struct Align {
798     #[primary_span]
799     pub span: Span,
800     pub align: String,
801 }
802
803 #[derive(Diagnostic)]
804 #[diag(passes_size)]
805 pub struct Size {
806     #[primary_span]
807     pub span: Span,
808     pub size: String,
809 }
810
811 #[derive(Diagnostic)]
812 #[diag(passes_homogeneous_aggregate)]
813 pub struct HomogeneousAggregate {
814     #[primary_span]
815     pub span: Span,
816     pub homogeneous_aggregate: String,
817 }
818
819 #[derive(Diagnostic)]
820 #[diag(passes_layout_of)]
821 pub struct LayoutOf {
822     #[primary_span]
823     pub span: Span,
824     pub normalized_ty: String,
825     pub ty_layout: String,
826 }
827
828 #[derive(Diagnostic)]
829 #[diag(passes_unrecognized_field)]
830 pub struct UnrecognizedField {
831     #[primary_span]
832     pub span: Span,
833     pub name: Symbol,
834 }
835
836 #[derive(Diagnostic)]
837 #[diag(passes_feature_stable_twice, code = "E0711")]
838 pub struct FeatureStableTwice {
839     #[primary_span]
840     pub span: Span,
841     pub feature: Symbol,
842     pub since: Symbol,
843     pub prev_since: Symbol,
844 }
845
846 #[derive(Diagnostic)]
847 #[diag(passes_feature_previously_declared, code = "E0711")]
848 pub struct FeaturePreviouslyDeclared<'a, 'b> {
849     #[primary_span]
850     pub span: Span,
851     pub feature: Symbol,
852     pub declared: &'a str,
853     pub prev_declared: &'b str,
854 }
855
856 #[derive(Diagnostic)]
857 #[diag(passes_expr_not_allowed_in_context, code = "E0744")]
858 pub struct ExprNotAllowedInContext<'a> {
859     #[primary_span]
860     pub span: Span,
861     pub expr: String,
862     pub context: &'a str,
863 }
864
865 pub struct BreakNonLoop<'a> {
866     pub span: Span,
867     pub head: Option<Span>,
868     pub kind: &'a str,
869     pub suggestion: String,
870     pub loop_label: Option<Label>,
871     pub break_label: Option<Label>,
872     pub break_expr_kind: &'a ExprKind<'a>,
873     pub break_expr_span: Span,
874 }
875
876 impl<'a> IntoDiagnostic<'_> for BreakNonLoop<'a> {
877     #[track_caller]
878     fn into_diagnostic(
879         self,
880         handler: &rustc_errors::Handler,
881     ) -> rustc_errors::DiagnosticBuilder<'_, ErrorGuaranteed> {
882         let mut diag = handler.struct_span_err_with_code(
883             self.span,
884             rustc_errors::fluent::passes_break_non_loop,
885             error_code!(E0571),
886         );
887         diag.set_arg("kind", self.kind);
888         diag.span_label(self.span, rustc_errors::fluent::label);
889         if let Some(head) = self.head {
890             diag.span_label(head, rustc_errors::fluent::label2);
891         }
892         diag.span_suggestion(
893             self.span,
894             rustc_errors::fluent::suggestion,
895             self.suggestion,
896             Applicability::MaybeIncorrect,
897         );
898         if let (Some(label), None) = (self.loop_label, self.break_label) {
899             match self.break_expr_kind {
900                 ExprKind::Path(hir::QPath::Resolved(
901                     None,
902                     hir::Path { segments: [segment], res: hir::def::Res::Err, .. },
903                 )) if label.ident.to_string() == format!("'{}", segment.ident) => {
904                     // This error is redundant, we will have already emitted a
905                     // suggestion to use the label when `segment` wasn't found
906                     // (hence the `Res::Err` check).
907                     diag.delay_as_bug();
908                 }
909                 _ => {
910                     diag.span_suggestion(
911                         self.break_expr_span,
912                         rustc_errors::fluent::break_expr_suggestion,
913                         label.ident,
914                         Applicability::MaybeIncorrect,
915                     );
916                 }
917             }
918         }
919         diag
920     }
921 }
922
923 #[derive(Diagnostic)]
924 #[diag(passes_continue_labeled_block, code = "E0696")]
925 pub struct ContinueLabeledBlock {
926     #[primary_span]
927     #[label]
928     pub span: Span,
929     #[label(block_label)]
930     pub block_span: Span,
931 }
932
933 #[derive(Diagnostic)]
934 #[diag(passes_break_inside_closure, code = "E0267")]
935 pub struct BreakInsideClosure<'a> {
936     #[primary_span]
937     #[label]
938     pub span: Span,
939     #[label(closure_label)]
940     pub closure_span: Span,
941     pub name: &'a str,
942 }
943
944 #[derive(Diagnostic)]
945 #[diag(passes_break_inside_async_block, code = "E0267")]
946 pub struct BreakInsideAsyncBlock<'a> {
947     #[primary_span]
948     #[label]
949     pub span: Span,
950     #[label(async_block_label)]
951     pub closure_span: Span,
952     pub name: &'a str,
953 }
954
955 #[derive(Diagnostic)]
956 #[diag(passes_outside_loop, code = "E0268")]
957 pub struct OutsideLoop<'a> {
958     #[primary_span]
959     #[label]
960     pub span: Span,
961     pub name: &'a str,
962     pub is_break: bool,
963 }
964
965 #[derive(Diagnostic)]
966 #[diag(passes_unlabeled_in_labeled_block, code = "E0695")]
967 pub struct UnlabeledInLabeledBlock<'a> {
968     #[primary_span]
969     #[label]
970     pub span: Span,
971     pub cf_type: &'a str,
972 }
973
974 #[derive(Diagnostic)]
975 #[diag(passes_unlabeled_cf_in_while_condition, code = "E0590")]
976 pub struct UnlabeledCfInWhileCondition<'a> {
977     #[primary_span]
978     #[label]
979     pub span: Span,
980     pub cf_type: &'a str,
981 }
982
983 #[derive(Diagnostic)]
984 #[diag(passes_cannot_inline_naked_function)]
985 pub struct CannotInlineNakedFunction {
986     #[primary_span]
987     pub span: Span,
988 }
989
990 #[derive(LintDiagnostic)]
991 #[diag(passes_undefined_naked_function_abi)]
992 pub struct UndefinedNakedFunctionAbi;
993
994 #[derive(Diagnostic)]
995 #[diag(passes_no_patterns)]
996 pub struct NoPatterns {
997     #[primary_span]
998     pub span: Span,
999 }
1000
1001 #[derive(Diagnostic)]
1002 #[diag(passes_params_not_allowed)]
1003 #[help]
1004 pub struct ParamsNotAllowed {
1005     #[primary_span]
1006     pub span: Span,
1007 }
1008
1009 pub struct NakedFunctionsAsmBlock {
1010     pub span: Span,
1011     pub multiple_asms: Vec<Span>,
1012     pub non_asms: Vec<Span>,
1013 }
1014
1015 impl IntoDiagnostic<'_> for NakedFunctionsAsmBlock {
1016     #[track_caller]
1017     fn into_diagnostic(
1018         self,
1019         handler: &rustc_errors::Handler,
1020     ) -> rustc_errors::DiagnosticBuilder<'_, ErrorGuaranteed> {
1021         let mut diag = handler.struct_span_err_with_code(
1022             self.span,
1023             rustc_errors::fluent::passes_naked_functions_asm_block,
1024             error_code!(E0787),
1025         );
1026         for span in self.multiple_asms.iter() {
1027             diag.span_label(*span, rustc_errors::fluent::label_multiple_asm);
1028         }
1029         for span in self.non_asms.iter() {
1030             diag.span_label(*span, rustc_errors::fluent::label_non_asm);
1031         }
1032         diag
1033     }
1034 }
1035
1036 #[derive(Diagnostic)]
1037 #[diag(passes_naked_functions_operands, code = "E0787")]
1038 pub struct NakedFunctionsOperands {
1039     #[primary_span]
1040     pub unsupported_operands: Vec<Span>,
1041 }
1042
1043 #[derive(Diagnostic)]
1044 #[diag(passes_naked_functions_asm_options, code = "E0787")]
1045 pub struct NakedFunctionsAsmOptions {
1046     #[primary_span]
1047     pub span: Span,
1048     pub unsupported_options: String,
1049 }
1050
1051 #[derive(Diagnostic)]
1052 #[diag(passes_naked_functions_must_use_noreturn, code = "E0787")]
1053 pub struct NakedFunctionsMustUseNoreturn {
1054     #[primary_span]
1055     pub span: Span,
1056     #[suggestion(code = ", options(noreturn)", applicability = "machine-applicable")]
1057     pub last_span: Span,
1058 }
1059
1060 #[derive(Diagnostic)]
1061 #[diag(passes_attr_only_on_main)]
1062 pub struct AttrOnlyOnMain {
1063     #[primary_span]
1064     pub span: Span,
1065     pub attr: Symbol,
1066 }
1067
1068 #[derive(Diagnostic)]
1069 #[diag(passes_attr_only_on_root_main)]
1070 pub struct AttrOnlyOnRootMain {
1071     #[primary_span]
1072     pub span: Span,
1073     pub attr: Symbol,
1074 }
1075
1076 #[derive(Diagnostic)]
1077 #[diag(passes_attr_only_in_functions)]
1078 pub struct AttrOnlyInFunctions {
1079     #[primary_span]
1080     pub span: Span,
1081     pub attr: Symbol,
1082 }
1083
1084 #[derive(Diagnostic)]
1085 #[diag(passes_multiple_rustc_main, code = "E0137")]
1086 pub struct MultipleRustcMain {
1087     #[primary_span]
1088     pub span: Span,
1089     #[label(first)]
1090     pub first: Span,
1091     #[label(additional)]
1092     pub additional: Span,
1093 }
1094
1095 #[derive(Diagnostic)]
1096 #[diag(passes_multiple_start_functions, code = "E0138")]
1097 pub struct MultipleStartFunctions {
1098     #[primary_span]
1099     pub span: Span,
1100     #[label]
1101     pub labeled: Span,
1102     #[label(previous)]
1103     pub previous: Span,
1104 }
1105
1106 #[derive(Diagnostic)]
1107 #[diag(passes_extern_main)]
1108 pub struct ExternMain {
1109     #[primary_span]
1110     pub span: Span,
1111 }
1112
1113 #[derive(Diagnostic)]
1114 #[diag(passes_unix_sigpipe_values)]
1115 pub struct UnixSigpipeValues {
1116     #[primary_span]
1117     pub span: Span,
1118 }
1119
1120 #[derive(Diagnostic)]
1121 #[diag(passes_no_main_function, code = "E0601")]
1122 pub struct NoMainFunction {
1123     #[primary_span]
1124     pub span: Span,
1125     pub crate_name: String,
1126 }
1127
1128 pub struct NoMainErr {
1129     pub sp: Span,
1130     pub crate_name: Symbol,
1131     pub has_filename: bool,
1132     pub filename: PathBuf,
1133     pub file_empty: bool,
1134     pub non_main_fns: Vec<Span>,
1135     pub main_def_opt: Option<MainDefinition>,
1136     pub add_teach_note: bool,
1137 }
1138
1139 impl<'a> IntoDiagnostic<'a> for NoMainErr {
1140     #[track_caller]
1141     fn into_diagnostic(
1142         self,
1143         handler: &'a rustc_errors::Handler,
1144     ) -> rustc_errors::DiagnosticBuilder<'a, ErrorGuaranteed> {
1145         let mut diag = handler.struct_span_err_with_code(
1146             DUMMY_SP,
1147             rustc_errors::fluent::passes_no_main_function,
1148             error_code!(E0601),
1149         );
1150         diag.set_arg("crate_name", self.crate_name);
1151         diag.set_arg("filename", self.filename);
1152         diag.set_arg("has_filename", self.has_filename);
1153         let note = if !self.non_main_fns.is_empty() {
1154             for &span in &self.non_main_fns {
1155                 diag.span_note(span, rustc_errors::fluent::here_is_main);
1156             }
1157             diag.note(rustc_errors::fluent::one_or_more_possible_main);
1158             diag.help(rustc_errors::fluent::consider_moving_main);
1159             // There were some functions named `main` though. Try to give the user a hint.
1160             rustc_errors::fluent::main_must_be_defined_at_crate
1161         } else if self.has_filename {
1162             rustc_errors::fluent::consider_adding_main_to_file
1163         } else {
1164             rustc_errors::fluent::consider_adding_main_at_crate
1165         };
1166         if self.file_empty {
1167             diag.note(note);
1168         } else {
1169             diag.set_span(self.sp.shrink_to_hi());
1170             diag.span_label(self.sp.shrink_to_hi(), note);
1171         }
1172
1173         if let Some(main_def) = self.main_def_opt && main_def.opt_fn_def_id().is_none(){
1174             // There is something at `crate::main`, but it is not a function definition.
1175             diag.span_label(main_def.span, rustc_errors::fluent::non_function_main);
1176         }
1177
1178         if self.add_teach_note {
1179             diag.note(rustc_errors::fluent::teach_note);
1180         }
1181         diag
1182     }
1183 }
1184
1185 pub struct DuplicateLangItem {
1186     pub local_span: Option<Span>,
1187     pub lang_item_name: Symbol,
1188     pub crate_name: Symbol,
1189     pub dependency_of: Symbol,
1190     pub is_local: bool,
1191     pub path: String,
1192     pub first_defined_span: Option<Span>,
1193     pub orig_crate_name: Symbol,
1194     pub orig_dependency_of: Symbol,
1195     pub orig_is_local: bool,
1196     pub orig_path: String,
1197     pub(crate) duplicate: Duplicate,
1198 }
1199
1200 impl IntoDiagnostic<'_> for DuplicateLangItem {
1201     #[track_caller]
1202     fn into_diagnostic(
1203         self,
1204         handler: &rustc_errors::Handler,
1205     ) -> rustc_errors::DiagnosticBuilder<'_, ErrorGuaranteed> {
1206         let mut diag = handler.struct_err_with_code(
1207             match self.duplicate {
1208                 Duplicate::Plain => rustc_errors::fluent::passes_duplicate_lang_item,
1209
1210                 Duplicate::Crate => rustc_errors::fluent::passes_duplicate_lang_item_crate,
1211                 Duplicate::CrateDepends => {
1212                     rustc_errors::fluent::passes_duplicate_lang_item_crate_depends
1213                 }
1214             },
1215             error_code!(E0152),
1216         );
1217         diag.set_arg("lang_item_name", self.lang_item_name);
1218         diag.set_arg("crate_name", self.crate_name);
1219         diag.set_arg("dependency_of", self.dependency_of);
1220         diag.set_arg("path", self.path);
1221         diag.set_arg("orig_crate_name", self.orig_crate_name);
1222         diag.set_arg("orig_dependency_of", self.orig_dependency_of);
1223         diag.set_arg("orig_path", self.orig_path);
1224         if let Some(span) = self.local_span {
1225             diag.set_span(span);
1226         }
1227         if let Some(span) = self.first_defined_span {
1228             diag.span_note(span, rustc_errors::fluent::first_defined_span);
1229         } else {
1230             if self.orig_dependency_of.is_empty() {
1231                 diag.note(rustc_errors::fluent::first_defined_crate);
1232             } else {
1233                 diag.note(rustc_errors::fluent::first_defined_crate_depends);
1234             }
1235
1236             if self.orig_is_local {
1237                 diag.note(rustc_errors::fluent::first_definition_local);
1238             } else {
1239                 diag.note(rustc_errors::fluent::first_definition_path);
1240             }
1241
1242             if self.is_local {
1243                 diag.note(rustc_errors::fluent::second_definition_local);
1244             } else {
1245                 diag.note(rustc_errors::fluent::second_definition_path);
1246             }
1247         }
1248         diag
1249     }
1250 }
1251
1252 #[derive(Diagnostic)]
1253 #[diag(passes_incorrect_target, code = "E0718")]
1254 pub struct IncorrectTarget<'a> {
1255     #[primary_span]
1256     pub span: Span,
1257     #[label]
1258     pub generics_span: Span,
1259     pub name: &'a str, // cannot be symbol because it renders e.g. `r#fn` instead of `fn`
1260     pub kind: &'static str,
1261     pub num: usize,
1262     pub actual_num: usize,
1263     pub at_least: bool,
1264 }
1265
1266 #[derive(LintDiagnostic)]
1267 #[diag(passes_useless_assignment)]
1268 pub struct UselessAssignment<'a> {
1269     pub is_field_assign: bool,
1270     pub ty: Ty<'a>,
1271 }
1272
1273 #[derive(LintDiagnostic)]
1274 #[diag(passes_only_has_effect_on)]
1275 pub struct OnlyHasEffectOn {
1276     pub attr_name: Symbol,
1277     pub target_name: String,
1278 }
1279
1280 #[derive(Diagnostic)]
1281 #[diag(passes_object_lifetime_err)]
1282 pub struct ObjectLifetimeErr {
1283     #[primary_span]
1284     pub span: Span,
1285     pub repr: String,
1286 }
1287
1288 #[derive(Diagnostic)]
1289 #[diag(passes_unrecognized_repr_hint, code = "E0552")]
1290 #[help]
1291 pub struct UnrecognizedReprHint {
1292     #[primary_span]
1293     pub span: Span,
1294 }
1295
1296 #[derive(Diagnostic)]
1297 pub enum AttrApplication {
1298     #[diag(passes_attr_application_enum, code = "E0517")]
1299     Enum {
1300         #[primary_span]
1301         hint_span: Span,
1302         #[label]
1303         span: Span,
1304     },
1305     #[diag(passes_attr_application_struct, code = "E0517")]
1306     Struct {
1307         #[primary_span]
1308         hint_span: Span,
1309         #[label]
1310         span: Span,
1311     },
1312     #[diag(passes_attr_application_struct_union, code = "E0517")]
1313     StructUnion {
1314         #[primary_span]
1315         hint_span: Span,
1316         #[label]
1317         span: Span,
1318     },
1319     #[diag(passes_attr_application_struct_enum_union, code = "E0517")]
1320     StructEnumUnion {
1321         #[primary_span]
1322         hint_span: Span,
1323         #[label]
1324         span: Span,
1325     },
1326     #[diag(passes_attr_application_struct_enum_function_union, code = "E0517")]
1327     StructEnumFunctionUnion {
1328         #[primary_span]
1329         hint_span: Span,
1330         #[label]
1331         span: Span,
1332     },
1333 }
1334
1335 #[derive(Diagnostic)]
1336 #[diag(passes_transparent_incompatible, code = "E0692")]
1337 pub struct TransparentIncompatible {
1338     #[primary_span]
1339     pub hint_spans: Vec<Span>,
1340     pub target: String,
1341 }
1342
1343 #[derive(Diagnostic)]
1344 #[diag(passes_deprecated_attribute, code = "E0549")]
1345 pub struct DeprecatedAttribute {
1346     #[primary_span]
1347     pub span: Span,
1348 }
1349
1350 #[derive(Diagnostic)]
1351 #[diag(passes_useless_stability)]
1352 pub struct UselessStability {
1353     #[primary_span]
1354     #[label]
1355     pub span: Span,
1356     #[label(item)]
1357     pub item_sp: Span,
1358 }
1359
1360 #[derive(Diagnostic)]
1361 #[diag(passes_invalid_stability)]
1362 pub struct InvalidStability {
1363     #[primary_span]
1364     #[label]
1365     pub span: Span,
1366     #[label(item)]
1367     pub item_sp: Span,
1368 }
1369
1370 #[derive(Diagnostic)]
1371 #[diag(passes_cannot_stabilize_deprecated)]
1372 pub struct CannotStabilizeDeprecated {
1373     #[primary_span]
1374     #[label]
1375     pub span: Span,
1376     #[label(item)]
1377     pub item_sp: Span,
1378 }
1379
1380 #[derive(Diagnostic)]
1381 #[diag(passes_invalid_deprecation_version)]
1382 pub struct InvalidDeprecationVersion {
1383     #[primary_span]
1384     #[label]
1385     pub span: Span,
1386     #[label(item)]
1387     pub item_sp: Span,
1388 }
1389
1390 #[derive(Diagnostic)]
1391 #[diag(passes_missing_stability_attr)]
1392 pub struct MissingStabilityAttr<'a> {
1393     #[primary_span]
1394     pub span: Span,
1395     pub descr: &'a str,
1396 }
1397
1398 #[derive(Diagnostic)]
1399 #[diag(passes_missing_const_stab_attr)]
1400 pub struct MissingConstStabAttr<'a> {
1401     #[primary_span]
1402     pub span: Span,
1403     pub descr: &'a str,
1404 }
1405
1406 #[derive(Diagnostic)]
1407 #[diag(passes_trait_impl_const_stable)]
1408 #[note]
1409 pub struct TraitImplConstStable {
1410     #[primary_span]
1411     pub span: Span,
1412 }
1413
1414 #[derive(Diagnostic)]
1415 #[diag(passes_feature_only_on_nightly, code = "E0554")]
1416 pub struct FeatureOnlyOnNightly {
1417     #[primary_span]
1418     pub span: Span,
1419     pub release_channel: &'static str,
1420 }
1421
1422 #[derive(Diagnostic)]
1423 #[diag(passes_unknown_feature, code = "E0635")]
1424 pub struct UnknownFeature {
1425     #[primary_span]
1426     pub span: Span,
1427     pub feature: Symbol,
1428 }
1429
1430 #[derive(Diagnostic)]
1431 #[diag(passes_implied_feature_not_exist)]
1432 pub struct ImpliedFeatureNotExist {
1433     #[primary_span]
1434     pub span: Span,
1435     pub feature: Symbol,
1436     pub implied_by: Symbol,
1437 }
1438
1439 #[derive(Diagnostic)]
1440 #[diag(passes_duplicate_feature_err, code = "E0636")]
1441 pub struct DuplicateFeatureErr {
1442     #[primary_span]
1443     pub span: Span,
1444     pub feature: Symbol,
1445 }
1446 #[derive(Diagnostic)]
1447 #[diag(passes_missing_const_err)]
1448 pub struct MissingConstErr {
1449     #[primary_span]
1450     #[help]
1451     pub fn_sig_span: Span,
1452     #[label]
1453     pub const_span: Span,
1454 }
1455
1456 #[derive(LintDiagnostic)]
1457 pub enum MultipleDeadCodes<'tcx> {
1458     #[diag(passes_dead_codes)]
1459     DeadCodes {
1460         multiple: bool,
1461         num: usize,
1462         descr: &'tcx str,
1463         participle: &'tcx str,
1464         name_list: DiagnosticSymbolList,
1465         #[subdiagnostic]
1466         parent_info: Option<ParentInfo<'tcx>>,
1467         #[subdiagnostic]
1468         ignored_derived_impls: Option<IgnoredDerivedImpls>,
1469     },
1470     #[diag(passes_dead_codes)]
1471     UnusedTupleStructFields {
1472         multiple: bool,
1473         num: usize,
1474         descr: &'tcx str,
1475         participle: &'tcx str,
1476         name_list: DiagnosticSymbolList,
1477         #[subdiagnostic]
1478         change_fields_suggestion: ChangeFieldsToBeOfUnitType,
1479         #[subdiagnostic]
1480         parent_info: Option<ParentInfo<'tcx>>,
1481         #[subdiagnostic]
1482         ignored_derived_impls: Option<IgnoredDerivedImpls>,
1483     },
1484 }
1485
1486 #[derive(Subdiagnostic)]
1487 #[label(passes_parent_info)]
1488 pub struct ParentInfo<'tcx> {
1489     pub num: usize,
1490     pub descr: &'tcx str,
1491     pub parent_descr: &'tcx str,
1492     #[primary_span]
1493     pub span: Span,
1494 }
1495
1496 #[derive(Subdiagnostic)]
1497 #[note(passes_ignored_derived_impls)]
1498 pub struct IgnoredDerivedImpls {
1499     pub name: Symbol,
1500     pub trait_list: DiagnosticSymbolList,
1501     pub trait_list_len: usize,
1502 }
1503
1504 #[derive(Subdiagnostic)]
1505 #[multipart_suggestion(passes_change_fields_to_be_of_unit_type, applicability = "has-placeholders")]
1506 pub struct ChangeFieldsToBeOfUnitType {
1507     pub num: usize,
1508     #[suggestion_part(code = "()")]
1509     pub spans: Vec<Span>,
1510 }