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