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