1use std::io::Error;
2use std::path::{Path, PathBuf};
3
4use rustc_errors::codes::*;
5use rustc_errors::{
6 Applicability, Diag, DiagCtxtHandle, DiagSymbolList, Diagnostic, EmissionGuarantee, Level,
7 MultiSpan,
8};
9use rustc_hir::Target;
10use rustc_hir::attrs::{MirDialect, MirPhase};
11use rustc_macros::{Diagnostic, LintDiagnostic, Subdiagnostic};
12use rustc_middle::ty::{MainDefinition, Ty};
13use rustc_span::{DUMMY_SP, Span, Symbol};
14
15use crate::check_attr::ProcMacroKind;
16use crate::fluent_generated as fluent;
17use crate::lang_items::Duplicate;
18
19#[derive(LintDiagnostic)]
20#[diag(passes_incorrect_do_not_recommend_location)]
21pub(crate) struct IncorrectDoNotRecommendLocation;
22
23#[derive(LintDiagnostic)]
24#[diag(passes_incorrect_do_not_recommend_args)]
25pub(crate) struct DoNotRecommendDoesNotExpectArgs;
26
27#[derive(LintDiagnostic)]
28#[diag(passes_doc_attr_expects_string)]
29pub(crate) struct DocAttrExpectsString {
30 pub(crate) attr_name: Symbol,
31}
32
33#[derive(LintDiagnostic)]
34#[diag(passes_doc_attr_expects_no_value)]
35pub(crate) struct DocAttrExpectsNoValue {
36 pub(crate) attr_name: Symbol,
37}
38
39#[derive(Diagnostic)]
40#[diag(passes_autodiff_attr)]
41pub(crate) struct AutoDiffAttr {
42 #[primary_span]
43 #[label]
44 pub attr_span: Span,
45}
46
47#[derive(Diagnostic)]
48#[diag(passes_loop_match_attr)]
49pub(crate) struct LoopMatchAttr {
50 #[primary_span]
51 pub attr_span: Span,
52 #[label]
53 pub node_span: Span,
54}
55
56#[derive(Diagnostic)]
57#[diag(passes_const_continue_attr)]
58pub(crate) struct ConstContinueAttr {
59 #[primary_span]
60 pub attr_span: Span,
61 #[label]
62 pub node_span: Span,
63}
64
65#[derive(LintDiagnostic)]
66#[diag(passes_mixed_export_name_and_no_mangle)]
67pub(crate) struct MixedExportNameAndNoMangle {
68 #[label]
69 #[suggestion(style = "verbose", code = "", applicability = "machine-applicable")]
70 pub no_mangle_span: Span,
71 #[note]
72 pub export_name_span: Span,
73 pub no_mangle_attr: &'static str,
74 pub export_name_attr: &'static str,
75}
76
77#[derive(LintDiagnostic)]
78#[diag(passes_outer_crate_level_attr)]
79pub(crate) struct OuterCrateLevelAttr {
80 #[subdiagnostic]
81 pub suggestion: OuterCrateLevelAttrSuggestion,
82}
83
84#[derive(Subdiagnostic)]
85#[multipart_suggestion(passes_outer_crate_level_attr_suggestion, style = "verbose")]
86pub(crate) struct OuterCrateLevelAttrSuggestion {
87 #[suggestion_part(code = "!")]
88 pub bang_position: Span,
89}
90
91#[derive(LintDiagnostic)]
92#[diag(passes_inner_crate_level_attr)]
93pub(crate) struct InnerCrateLevelAttr;
94
95#[derive(LintDiagnostic)]
96#[diag(passes_ignored_attr_with_macro)]
97pub(crate) struct IgnoredAttrWithMacro<'a> {
98 pub sym: &'a str,
99}
100
101#[derive(Diagnostic)]
102#[diag(passes_should_be_applied_to_fn)]
103pub(crate) struct AttrShouldBeAppliedToFn {
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_non_exhaustive_with_default_field_values)]
113pub(crate) struct NonExhaustiveWithDefaultFieldValues {
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)]
122pub(crate) struct AttrShouldBeAppliedToTrait {
123 #[primary_span]
124 pub attr_span: Span,
125 #[label]
126 pub defn_span: Span,
127}
128
129#[derive(Diagnostic)]
130#[diag(passes_should_be_applied_to_static)]
131pub(crate) struct AttrShouldBeAppliedToStatic {
132 #[primary_span]
133 pub attr_span: Span,
134 #[label]
135 pub defn_span: Span,
136}
137
138#[derive(Diagnostic)]
139#[diag(passes_doc_expect_str)]
140pub(crate) struct DocExpectStr<'a> {
141 #[primary_span]
142 pub attr_span: Span,
143 pub attr_name: &'a str,
144}
145
146#[derive(Diagnostic)]
147#[diag(passes_doc_alias_empty)]
148pub(crate) struct DocAliasEmpty<'a> {
149 #[primary_span]
150 pub span: Span,
151 pub attr_str: &'a str,
152}
153
154#[derive(Diagnostic)]
155#[diag(passes_doc_alias_bad_char)]
156pub(crate) struct DocAliasBadChar<'a> {
157 #[primary_span]
158 pub span: Span,
159 pub attr_str: &'a str,
160 pub char_: char,
161}
162
163#[derive(Diagnostic)]
164#[diag(passes_doc_alias_start_end)]
165pub(crate) struct DocAliasStartEnd<'a> {
166 #[primary_span]
167 pub span: Span,
168 pub attr_str: &'a str,
169}
170
171#[derive(Diagnostic)]
172#[diag(passes_doc_alias_bad_location)]
173pub(crate) struct DocAliasBadLocation<'a> {
174 #[primary_span]
175 pub span: Span,
176 pub attr_str: &'a str,
177 pub location: &'a str,
178}
179
180#[derive(Diagnostic)]
181#[diag(passes_doc_alias_not_an_alias)]
182pub(crate) struct DocAliasNotAnAlias<'a> {
183 #[primary_span]
184 pub span: Span,
185 pub attr_str: &'a str,
186}
187
188#[derive(LintDiagnostic)]
189#[diag(passes_doc_alias_duplicated)]
190pub(crate) struct DocAliasDuplicated {
191 #[label]
192 pub first_defn: Span,
193}
194
195#[derive(Diagnostic)]
196#[diag(passes_doc_alias_not_string_literal)]
197pub(crate) struct DocAliasNotStringLiteral {
198 #[primary_span]
199 pub span: Span,
200}
201
202#[derive(Diagnostic)]
203#[diag(passes_doc_alias_malformed)]
204pub(crate) struct DocAliasMalformed {
205 #[primary_span]
206 pub span: Span,
207}
208
209#[derive(Diagnostic)]
210#[diag(passes_doc_keyword_attribute_empty_mod)]
211pub(crate) struct DocKeywordAttributeEmptyMod {
212 #[primary_span]
213 pub span: Span,
214 pub attr_name: &'static str,
215}
216
217#[derive(Diagnostic)]
218#[diag(passes_doc_keyword_not_keyword)]
219#[help]
220pub(crate) struct DocKeywordNotKeyword {
221 #[primary_span]
222 pub span: Span,
223 pub keyword: Symbol,
224}
225
226#[derive(Diagnostic)]
227#[diag(passes_doc_attribute_not_attribute)]
228#[help]
229pub(crate) struct DocAttributeNotAttribute {
230 #[primary_span]
231 pub span: Span,
232 pub attribute: Symbol,
233}
234
235#[derive(Diagnostic)]
236#[diag(passes_doc_keyword_attribute_not_mod)]
237pub(crate) struct DocKeywordAttributeNotMod {
238 #[primary_span]
239 pub span: Span,
240 pub attr_name: &'static str,
241}
242
243#[derive(Diagnostic)]
244#[diag(passes_doc_fake_variadic_not_valid)]
245pub(crate) struct DocFakeVariadicNotValid {
246 #[primary_span]
247 pub span: Span,
248}
249
250#[derive(Diagnostic)]
251#[diag(passes_doc_keyword_only_impl)]
252pub(crate) struct DocKeywordOnlyImpl {
253 #[primary_span]
254 pub span: Span,
255}
256
257#[derive(Diagnostic)]
258#[diag(passes_doc_search_unbox_invalid)]
259pub(crate) struct DocSearchUnboxInvalid {
260 #[primary_span]
261 pub span: Span,
262}
263
264#[derive(Diagnostic)]
265#[diag(passes_doc_inline_conflict)]
266#[help]
267pub(crate) struct DocKeywordConflict {
268 #[primary_span]
269 pub spans: MultiSpan,
270}
271
272#[derive(LintDiagnostic)]
273#[diag(passes_doc_inline_only_use)]
274#[note]
275pub(crate) struct DocInlineOnlyUse {
276 #[label]
277 pub attr_span: Span,
278 #[label(passes_not_a_use_item_label)]
279 pub item_span: Option<Span>,
280}
281
282#[derive(LintDiagnostic)]
283#[diag(passes_doc_masked_only_extern_crate)]
284#[note]
285pub(crate) struct DocMaskedOnlyExternCrate {
286 #[label]
287 pub attr_span: Span,
288 #[label(passes_not_an_extern_crate_label)]
289 pub item_span: Option<Span>,
290}
291
292#[derive(LintDiagnostic)]
293#[diag(passes_doc_masked_not_extern_crate_self)]
294pub(crate) struct DocMaskedNotExternCrateSelf {
295 #[label]
296 pub attr_span: Span,
297 #[label(passes_extern_crate_self_label)]
298 pub item_span: Option<Span>,
299}
300
301#[derive(Diagnostic)]
302#[diag(passes_doc_attr_not_crate_level)]
303pub(crate) struct DocAttrNotCrateLevel<'a> {
304 #[primary_span]
305 pub span: Span,
306 pub attr_name: &'a str,
307}
308
309#[derive(LintDiagnostic)]
310#[diag(passes_doc_test_unknown)]
311pub(crate) struct DocTestUnknown {
312 pub path: String,
313}
314
315#[derive(LintDiagnostic)]
316#[diag(passes_doc_test_literal)]
317pub(crate) struct DocTestLiteral;
318
319#[derive(LintDiagnostic)]
320#[diag(passes_doc_test_takes_list)]
321pub(crate) struct DocTestTakesList;
322
323#[derive(LintDiagnostic)]
324#[diag(passes_doc_auto_cfg_wrong_literal)]
325pub(crate) struct DocAutoCfgWrongLiteral;
326
327#[derive(LintDiagnostic)]
328#[diag(passes_doc_auto_cfg_expects_hide_or_show)]
329pub(crate) struct DocAutoCfgExpectsHideOrShow;
330
331#[derive(LintDiagnostic)]
332#[diag(passes_doc_auto_cfg_hide_show_expects_list)]
333pub(crate) struct DocAutoCfgHideShowExpectsList {
334 pub attr_name: Symbol,
335}
336
337#[derive(LintDiagnostic)]
338#[diag(passes_doc_auto_cfg_hide_show_unexpected_item)]
339pub(crate) struct DocAutoCfgHideShowUnexpectedItem {
340 pub attr_name: Symbol,
341}
342
343#[derive(LintDiagnostic)]
344#[diag(passes_doc_test_unknown_any)]
345pub(crate) struct DocTestUnknownAny {
346 pub path: String,
347}
348
349#[derive(LintDiagnostic)]
350#[diag(passes_doc_test_unknown_spotlight)]
351#[note]
352#[note(passes_no_op_note)]
353pub(crate) struct DocTestUnknownSpotlight {
354 pub path: String,
355 #[suggestion(style = "short", applicability = "machine-applicable", code = "notable_trait")]
356 pub span: Span,
357}
358
359#[derive(LintDiagnostic)]
360#[diag(passes_doc_test_unknown_passes)]
361#[note]
362#[note(passes_no_op_note)]
363pub(crate) struct DocTestUnknownPasses {
364 pub path: String,
365 #[label]
366 pub span: Span,
367}
368
369#[derive(LintDiagnostic)]
370#[diag(passes_doc_test_unknown_plugins)]
371#[note]
372#[note(passes_no_op_note)]
373pub(crate) struct DocTestUnknownPlugins {
374 pub path: String,
375 #[label]
376 pub span: Span,
377}
378
379#[derive(LintDiagnostic)]
380#[diag(passes_doc_test_unknown_include)]
381pub(crate) struct DocTestUnknownInclude {
382 pub path: String,
383 pub value: String,
384 pub inner: &'static str,
385 #[suggestion(code = "#{inner}[doc = include_str!(\"{value}\")]")]
386 pub sugg: (Span, Applicability),
387}
388
389#[derive(LintDiagnostic)]
390#[diag(passes_doc_invalid)]
391pub(crate) struct DocInvalid;
392
393#[derive(Diagnostic)]
394#[diag(passes_has_incoherent_inherent_impl)]
395pub(crate) struct HasIncoherentInherentImpl {
396 #[primary_span]
397 pub attr_span: Span,
398 #[label]
399 pub span: Span,
400}
401
402#[derive(Diagnostic)]
403#[diag(passes_both_ffi_const_and_pure, code = E0757)]
404pub(crate) struct BothFfiConstAndPure {
405 #[primary_span]
406 pub attr_span: Span,
407}
408
409#[derive(Diagnostic)]
410#[diag(passes_must_not_suspend)]
411pub(crate) struct MustNotSuspend {
412 #[primary_span]
413 pub attr_span: Span,
414 #[label]
415 pub span: Span,
416}
417
418#[derive(LintDiagnostic)]
419#[diag(passes_link)]
420#[warning]
421pub(crate) struct Link {
422 #[label]
423 pub span: Option<Span>,
424}
425
426#[derive(Diagnostic)]
427#[diag(passes_no_link)]
428pub(crate) struct NoLink {
429 #[primary_span]
430 pub attr_span: Span,
431 #[label]
432 pub span: Span,
433}
434
435#[derive(Diagnostic)]
436#[diag(passes_rustc_legacy_const_generics_only)]
437pub(crate) 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)]
446pub(crate) 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)]
455pub(crate) 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)]
464pub(crate) struct RustcLegacyConstGenericsIndexNegative {
465 #[primary_span]
466 pub invalid_args: Vec<Span>,
467}
468
469#[derive(Diagnostic)]
470#[diag(passes_rustc_dirty_clean)]
471pub(crate) struct RustcDirtyClean {
472 #[primary_span]
473 pub span: Span,
474}
475
476#[derive(Diagnostic)]
477#[diag(passes_repr_conflicting, code = E0566)]
478pub(crate) struct ReprConflicting {
479 #[primary_span]
480 pub hint_spans: Vec<Span>,
481}
482
483#[derive(Diagnostic)]
484#[diag(passes_repr_align_greater_than_target_max, code = E0589)]
485#[note]
486pub(crate) struct InvalidReprAlignForTarget {
487 #[primary_span]
488 pub span: Span,
489 pub size: u64,
490}
491
492#[derive(LintDiagnostic)]
493#[diag(passes_repr_conflicting, code = E0566)]
494pub(crate) struct ReprConflictingLint;
495
496#[derive(Diagnostic)]
497#[diag(passes_macro_only_attribute)]
498pub(crate) struct MacroOnlyAttribute {
499 #[primary_span]
500 pub attr_span: Span,
501 #[label]
502 pub span: Span,
503}
504
505#[derive(Diagnostic)]
506#[diag(passes_debug_visualizer_unreadable)]
507pub(crate) struct DebugVisualizerUnreadable<'a> {
508 #[primary_span]
509 pub span: Span,
510 pub file: &'a Path,
511 pub error: Error,
512}
513
514#[derive(Diagnostic)]
515#[diag(passes_rustc_allow_const_fn_unstable)]
516pub(crate) struct RustcAllowConstFnUnstable {
517 #[primary_span]
518 pub attr_span: Span,
519 #[label]
520 pub span: Span,
521}
522
523#[derive(Diagnostic)]
524#[diag(passes_rustc_pub_transparent)]
525pub(crate) struct RustcPubTransparent {
526 #[primary_span]
527 pub attr_span: Span,
528 #[label]
529 pub span: Span,
530}
531
532#[derive(Diagnostic)]
533#[diag(passes_rustc_force_inline_coro)]
534pub(crate) struct RustcForceInlineCoro {
535 #[primary_span]
536 pub attr_span: Span,
537 #[label]
538 pub span: Span,
539}
540
541#[derive(LintDiagnostic)]
542pub(crate) enum MacroExport {
543 #[diag(passes_macro_export_on_decl_macro)]
544 #[note]
545 OnDeclMacro,
546}
547
548#[derive(Subdiagnostic)]
549pub(crate) enum UnusedNote {
550 #[note(passes_unused_empty_lints_note)]
551 EmptyList { name: Symbol },
552 #[note(passes_unused_no_lints_note)]
553 NoLints { name: Symbol },
554 #[note(passes_unused_default_method_body_const_note)]
555 DefaultMethodBodyConst,
556 #[note(passes_unused_linker_messages_note)]
557 LinkerMessagesBinaryCrateOnly,
558}
559
560#[derive(LintDiagnostic)]
561#[diag(passes_unused)]
562pub(crate) struct Unused {
563 #[suggestion(code = "", applicability = "machine-applicable")]
564 pub attr_span: Span,
565 #[subdiagnostic]
566 pub note: UnusedNote,
567}
568
569#[derive(Diagnostic)]
570#[diag(passes_non_exported_macro_invalid_attrs, code = E0518)]
571pub(crate) struct NonExportedMacroInvalidAttrs {
572 #[primary_span]
573 #[label]
574 pub attr_span: Span,
575}
576
577#[derive(Diagnostic)]
578#[diag(passes_may_dangle)]
579pub(crate) struct InvalidMayDangle {
580 #[primary_span]
581 pub attr_span: Span,
582}
583
584#[derive(LintDiagnostic)]
585#[diag(passes_unused_duplicate)]
586pub(crate) struct UnusedDuplicate {
587 #[suggestion(code = "", applicability = "machine-applicable")]
588 pub this: Span,
589 #[note]
590 pub other: Span,
591 #[warning]
592 pub warning: bool,
593}
594
595#[derive(Diagnostic)]
596#[diag(passes_unused_multiple)]
597pub(crate) struct UnusedMultiple {
598 #[primary_span]
599 #[suggestion(code = "", applicability = "machine-applicable")]
600 pub this: Span,
601 #[note]
602 pub other: Span,
603 pub name: Symbol,
604}
605
606#[derive(Diagnostic)]
607#[diag(passes_rustc_lint_opt_ty)]
608pub(crate) struct RustcLintOptTy {
609 #[primary_span]
610 pub attr_span: Span,
611 #[label]
612 pub span: Span,
613}
614
615#[derive(Diagnostic)]
616#[diag(passes_rustc_lint_opt_deny_field_access)]
617pub(crate) struct RustcLintOptDenyFieldAccess {
618 #[primary_span]
619 pub attr_span: Span,
620 #[label]
621 pub span: Span,
622}
623
624#[derive(Diagnostic)]
625#[diag(passes_collapse_debuginfo)]
626pub(crate) struct CollapseDebuginfo {
627 #[primary_span]
628 pub attr_span: Span,
629 #[label]
630 pub defn_span: Span,
631}
632
633#[derive(LintDiagnostic)]
634#[diag(passes_deprecated_annotation_has_no_effect)]
635pub(crate) struct DeprecatedAnnotationHasNoEffect {
636 #[suggestion(applicability = "machine-applicable", code = "")]
637 pub span: Span,
638}
639
640#[derive(Diagnostic)]
641#[diag(passes_unknown_external_lang_item, code = E0264)]
642pub(crate) struct UnknownExternLangItem {
643 #[primary_span]
644 pub span: Span,
645 pub lang_item: Symbol,
646}
647
648#[derive(Diagnostic)]
649#[diag(passes_missing_panic_handler)]
650pub(crate) struct MissingPanicHandler;
651
652#[derive(Diagnostic)]
653#[diag(passes_panic_unwind_without_std)]
654#[help]
655#[note]
656pub(crate) struct PanicUnwindWithoutStd;
657
658#[derive(Diagnostic)]
659#[diag(passes_missing_lang_item)]
660#[note]
661#[help]
662pub(crate) struct MissingLangItem {
663 pub name: Symbol,
664}
665
666#[derive(Diagnostic)]
667#[diag(passes_lang_item_fn_with_track_caller)]
668pub(crate) struct LangItemWithTrackCaller {
669 #[primary_span]
670 pub attr_span: Span,
671 pub name: Symbol,
672 #[label]
673 pub sig_span: Span,
674}
675
676#[derive(Diagnostic)]
677#[diag(passes_lang_item_fn_with_target_feature)]
678pub(crate) struct LangItemWithTargetFeature {
679 #[primary_span]
680 pub attr_span: Span,
681 pub name: Symbol,
682 #[label]
683 pub sig_span: Span,
684}
685
686#[derive(Diagnostic)]
687#[diag(passes_lang_item_on_incorrect_target, code = E0718)]
688pub(crate) struct LangItemOnIncorrectTarget {
689 #[primary_span]
690 #[label]
691 pub span: Span,
692 pub name: Symbol,
693 pub expected_target: Target,
694 pub actual_target: Target,
695}
696
697#[derive(Diagnostic)]
698#[diag(passes_unknown_lang_item, code = E0522)]
699pub(crate) struct UnknownLangItem {
700 #[primary_span]
701 #[label]
702 pub span: Span,
703 pub name: Symbol,
704}
705
706pub(crate) struct InvalidAttrAtCrateLevel {
707 pub span: Span,
708 pub sugg_span: Option<Span>,
709 pub name: Symbol,
710 pub item: Option<ItemFollowingInnerAttr>,
711}
712
713#[derive(Clone, Copy)]
714pub(crate) struct ItemFollowingInnerAttr {
715 pub span: Span,
716 pub kind: &'static str,
717}
718
719impl<G: EmissionGuarantee> Diagnostic<'_, G> for InvalidAttrAtCrateLevel {
720 #[track_caller]
721 fn into_diag(self, dcx: DiagCtxtHandle<'_>, level: Level) -> Diag<'_, G> {
722 let mut diag = Diag::new(dcx, level, fluent::passes_invalid_attr_at_crate_level);
723 diag.span(self.span);
724 diag.arg("name", self.name);
725 if let Some(span) = self.sugg_span {
728 diag.span_suggestion_verbose(
729 span,
730 fluent::passes_suggestion,
731 String::new(),
732 Applicability::MachineApplicable,
733 );
734 }
735 if let Some(item) = self.item {
736 diag.arg("kind", item.kind);
737 diag.span_label(item.span, fluent::passes_invalid_attr_at_crate_level_item);
738 }
739 diag
740 }
741}
742
743#[derive(Diagnostic)]
744#[diag(passes_duplicate_diagnostic_item_in_crate)]
745pub(crate) struct DuplicateDiagnosticItemInCrate {
746 #[primary_span]
747 pub duplicate_span: Option<Span>,
748 #[note(passes_diagnostic_item_first_defined)]
749 pub orig_span: Option<Span>,
750 #[note]
751 pub different_crates: bool,
752 pub crate_name: Symbol,
753 pub orig_crate_name: Symbol,
754 pub name: Symbol,
755}
756
757#[derive(Diagnostic)]
758#[diag(passes_layout_abi)]
759pub(crate) struct LayoutAbi {
760 #[primary_span]
761 pub span: Span,
762 pub abi: String,
763}
764
765#[derive(Diagnostic)]
766#[diag(passes_layout_align)]
767pub(crate) struct LayoutAlign {
768 #[primary_span]
769 pub span: Span,
770 pub align: String,
771}
772
773#[derive(Diagnostic)]
774#[diag(passes_layout_size)]
775pub(crate) struct LayoutSize {
776 #[primary_span]
777 pub span: Span,
778 pub size: String,
779}
780
781#[derive(Diagnostic)]
782#[diag(passes_layout_homogeneous_aggregate)]
783pub(crate) struct LayoutHomogeneousAggregate {
784 #[primary_span]
785 pub span: Span,
786 pub homogeneous_aggregate: String,
787}
788
789#[derive(Diagnostic)]
790#[diag(passes_layout_of)]
791pub(crate) struct LayoutOf<'tcx> {
792 #[primary_span]
793 pub span: Span,
794 pub normalized_ty: Ty<'tcx>,
795 pub ty_layout: String,
796}
797
798#[derive(Diagnostic)]
799#[diag(passes_layout_invalid_attribute)]
800pub(crate) struct LayoutInvalidAttribute {
801 #[primary_span]
802 pub span: Span,
803}
804
805#[derive(Diagnostic)]
806#[diag(passes_abi_of)]
807pub(crate) struct AbiOf {
808 #[primary_span]
809 pub span: Span,
810 pub fn_name: Symbol,
811 pub fn_abi: String,
812}
813
814#[derive(Diagnostic)]
815#[diag(passes_abi_ne)]
816pub(crate) struct AbiNe {
817 #[primary_span]
818 pub span: Span,
819 pub left: String,
820 pub right: String,
821}
822
823#[derive(Diagnostic)]
824#[diag(passes_abi_invalid_attribute)]
825pub(crate) struct AbiInvalidAttribute {
826 #[primary_span]
827 pub span: Span,
828}
829
830#[derive(Diagnostic)]
831#[diag(passes_unrecognized_argument)]
832pub(crate) struct UnrecognizedArgument {
833 #[primary_span]
834 pub span: Span,
835}
836
837#[derive(Diagnostic)]
838#[diag(passes_feature_stable_twice, code = E0711)]
839pub(crate) struct FeatureStableTwice {
840 #[primary_span]
841 pub span: Span,
842 pub feature: Symbol,
843 pub since: Symbol,
844 pub prev_since: Symbol,
845}
846
847#[derive(Diagnostic)]
848#[diag(passes_feature_previously_declared, code = E0711)]
849pub(crate) struct FeaturePreviouslyDeclared<'a> {
850 #[primary_span]
851 pub span: Span,
852 pub feature: Symbol,
853 pub declared: &'a str,
854 pub prev_declared: &'a str,
855}
856
857#[derive(Diagnostic)]
858#[diag(passes_multiple_rustc_main, code = E0137)]
859pub(crate) struct MultipleRustcMain {
860 #[primary_span]
861 pub span: Span,
862 #[label(passes_first)]
863 pub first: Span,
864 #[label(passes_additional)]
865 pub additional: Span,
866}
867
868#[derive(Diagnostic)]
869#[diag(passes_extern_main)]
870pub(crate) struct ExternMain {
871 #[primary_span]
872 pub span: Span,
873}
874
875pub(crate) struct NoMainErr {
876 pub sp: Span,
877 pub crate_name: Symbol,
878 pub has_filename: bool,
879 pub filename: PathBuf,
880 pub file_empty: bool,
881 pub non_main_fns: Vec<Span>,
882 pub main_def_opt: Option<MainDefinition>,
883 pub add_teach_note: bool,
884}
885
886impl<'a, G: EmissionGuarantee> Diagnostic<'a, G> for NoMainErr {
887 #[track_caller]
888 fn into_diag(self, dcx: DiagCtxtHandle<'a>, level: Level) -> Diag<'a, G> {
889 let mut diag = Diag::new(dcx, level, fluent::passes_no_main_function);
890 diag.span(DUMMY_SP);
891 diag.code(E0601);
892 diag.arg("crate_name", self.crate_name);
893 diag.arg("filename", self.filename);
894 diag.arg("has_filename", self.has_filename);
895 let note = if !self.non_main_fns.is_empty() {
896 for &span in &self.non_main_fns {
897 diag.span_note(span, fluent::passes_here_is_main);
898 }
899 diag.note(fluent::passes_one_or_more_possible_main);
900 diag.help(fluent::passes_consider_moving_main);
901 fluent::passes_main_must_be_defined_at_crate
903 } else if self.has_filename {
904 fluent::passes_consider_adding_main_to_file
905 } else {
906 fluent::passes_consider_adding_main_at_crate
907 };
908 if self.file_empty {
909 diag.note(note);
910 } else {
911 diag.span(self.sp.shrink_to_hi());
912 diag.span_label(self.sp.shrink_to_hi(), note);
913 }
914
915 if let Some(main_def) = self.main_def_opt
916 && main_def.opt_fn_def_id().is_none()
917 {
918 diag.span_label(main_def.span, fluent::passes_non_function_main);
920 }
921
922 if self.add_teach_note {
923 diag.note(fluent::passes_teach_note);
924 }
925 diag
926 }
927}
928
929pub(crate) struct DuplicateLangItem {
930 pub local_span: Option<Span>,
931 pub lang_item_name: Symbol,
932 pub crate_name: Symbol,
933 pub dependency_of: Option<Symbol>,
934 pub is_local: bool,
935 pub path: String,
936 pub first_defined_span: Option<Span>,
937 pub orig_crate_name: Option<Symbol>,
938 pub orig_dependency_of: Option<Symbol>,
939 pub orig_is_local: bool,
940 pub orig_path: String,
941 pub(crate) duplicate: Duplicate,
942}
943
944impl<G: EmissionGuarantee> Diagnostic<'_, G> for DuplicateLangItem {
945 #[track_caller]
946 fn into_diag(self, dcx: DiagCtxtHandle<'_>, level: Level) -> Diag<'_, G> {
947 let mut diag = Diag::new(
948 dcx,
949 level,
950 match self.duplicate {
951 Duplicate::Plain => fluent::passes_duplicate_lang_item,
952 Duplicate::Crate => fluent::passes_duplicate_lang_item_crate,
953 Duplicate::CrateDepends => fluent::passes_duplicate_lang_item_crate_depends,
954 },
955 );
956 diag.code(E0152);
957 diag.arg("lang_item_name", self.lang_item_name);
958 diag.arg("crate_name", self.crate_name);
959 if let Some(dependency_of) = self.dependency_of {
960 diag.arg("dependency_of", dependency_of);
961 }
962 diag.arg("path", self.path);
963 if let Some(orig_crate_name) = self.orig_crate_name {
964 diag.arg("orig_crate_name", orig_crate_name);
965 }
966 if let Some(orig_dependency_of) = self.orig_dependency_of {
967 diag.arg("orig_dependency_of", orig_dependency_of);
968 }
969 diag.arg("orig_path", self.orig_path);
970 if let Some(span) = self.local_span {
971 diag.span(span);
972 }
973 if let Some(span) = self.first_defined_span {
974 diag.span_note(span, fluent::passes_first_defined_span);
975 } else {
976 if self.orig_dependency_of.is_none() {
977 diag.note(fluent::passes_first_defined_crate);
978 } else {
979 diag.note(fluent::passes_first_defined_crate_depends);
980 }
981
982 if self.orig_is_local {
983 diag.note(fluent::passes_first_definition_local);
984 } else {
985 diag.note(fluent::passes_first_definition_path);
986 }
987
988 if self.is_local {
989 diag.note(fluent::passes_second_definition_local);
990 } else {
991 diag.note(fluent::passes_second_definition_path);
992 }
993 }
994 diag
995 }
996}
997
998#[derive(Diagnostic)]
999#[diag(passes_incorrect_target, code = E0718)]
1000pub(crate) struct IncorrectTarget<'a> {
1001 #[primary_span]
1002 pub span: Span,
1003 #[label]
1004 pub generics_span: Span,
1005 pub name: &'a str, pub kind: &'static str,
1007 pub num: usize,
1008 pub actual_num: usize,
1009 pub at_least: bool,
1010}
1011
1012#[derive(Diagnostic)]
1013#[diag(passes_incorrect_crate_type)]
1014pub(crate) struct IncorrectCrateType {
1015 #[primary_span]
1016 pub span: Span,
1017}
1018
1019#[derive(LintDiagnostic)]
1020#[diag(passes_useless_assignment)]
1021pub(crate) struct UselessAssignment<'a> {
1022 pub is_field_assign: bool,
1023 pub ty: Ty<'a>,
1024}
1025
1026#[derive(LintDiagnostic)]
1027#[diag(passes_inline_ignored_for_exported)]
1028#[help]
1029pub(crate) struct InlineIgnoredForExported {}
1030
1031#[derive(Diagnostic)]
1032#[diag(passes_object_lifetime_err)]
1033pub(crate) struct ObjectLifetimeErr {
1034 #[primary_span]
1035 pub span: Span,
1036 pub repr: String,
1037}
1038
1039#[derive(Diagnostic)]
1040pub(crate) enum AttrApplication {
1041 #[diag(passes_attr_application_enum, code = E0517)]
1042 Enum {
1043 #[primary_span]
1044 hint_span: Span,
1045 #[label]
1046 span: Span,
1047 },
1048 #[diag(passes_attr_application_struct, code = E0517)]
1049 Struct {
1050 #[primary_span]
1051 hint_span: Span,
1052 #[label]
1053 span: Span,
1054 },
1055 #[diag(passes_attr_application_struct_union, code = E0517)]
1056 StructUnion {
1057 #[primary_span]
1058 hint_span: Span,
1059 #[label]
1060 span: Span,
1061 },
1062 #[diag(passes_attr_application_struct_enum_union, code = E0517)]
1063 StructEnumUnion {
1064 #[primary_span]
1065 hint_span: Span,
1066 #[label]
1067 span: Span,
1068 },
1069}
1070
1071#[derive(Diagnostic)]
1072#[diag(passes_transparent_incompatible, code = E0692)]
1073pub(crate) struct TransparentIncompatible {
1074 #[primary_span]
1075 pub hint_spans: Vec<Span>,
1076 pub target: String,
1077}
1078
1079#[derive(Diagnostic)]
1080#[diag(passes_deprecated_attribute, code = E0549)]
1081pub(crate) struct DeprecatedAttribute {
1082 #[primary_span]
1083 pub span: Span,
1084}
1085
1086#[derive(Diagnostic)]
1087#[diag(passes_useless_stability)]
1088pub(crate) struct UselessStability {
1089 #[primary_span]
1090 #[label]
1091 pub span: Span,
1092 #[label(passes_item)]
1093 pub item_sp: Span,
1094}
1095
1096#[derive(Diagnostic)]
1097#[diag(passes_cannot_stabilize_deprecated)]
1098pub(crate) struct CannotStabilizeDeprecated {
1099 #[primary_span]
1100 #[label]
1101 pub span: Span,
1102 #[label(passes_item)]
1103 pub item_sp: Span,
1104}
1105
1106#[derive(Diagnostic)]
1107#[diag(passes_unstable_attr_for_already_stable_feature)]
1108pub(crate) struct UnstableAttrForAlreadyStableFeature {
1109 #[primary_span]
1110 #[label]
1111 #[help]
1112 pub attr_span: Span,
1113 #[label(passes_item)]
1114 pub item_span: Span,
1115}
1116
1117#[derive(Diagnostic)]
1118#[diag(passes_missing_stability_attr)]
1119pub(crate) struct MissingStabilityAttr<'a> {
1120 #[primary_span]
1121 pub span: Span,
1122 pub descr: &'a str,
1123}
1124
1125#[derive(Diagnostic)]
1126#[diag(passes_missing_const_stab_attr)]
1127pub(crate) struct MissingConstStabAttr<'a> {
1128 #[primary_span]
1129 pub span: Span,
1130 pub descr: &'a str,
1131}
1132
1133#[derive(Diagnostic)]
1134#[diag(passes_trait_impl_const_stable)]
1135#[note]
1136pub(crate) struct TraitImplConstStable {
1137 #[primary_span]
1138 pub span: Span,
1139}
1140
1141#[derive(Diagnostic)]
1142#[diag(passes_trait_impl_const_stability_mismatch)]
1143pub(crate) struct TraitImplConstStabilityMismatch {
1144 #[primary_span]
1145 pub span: Span,
1146 #[subdiagnostic]
1147 pub impl_stability: ImplConstStability,
1148 #[subdiagnostic]
1149 pub trait_stability: TraitConstStability,
1150}
1151
1152#[derive(Subdiagnostic)]
1153pub(crate) enum TraitConstStability {
1154 #[note(passes_trait_impl_const_stability_mismatch_trait_stable)]
1155 Stable {
1156 #[primary_span]
1157 span: Span,
1158 },
1159 #[note(passes_trait_impl_const_stability_mismatch_trait_unstable)]
1160 Unstable {
1161 #[primary_span]
1162 span: Span,
1163 },
1164}
1165
1166#[derive(Subdiagnostic)]
1167pub(crate) enum ImplConstStability {
1168 #[note(passes_trait_impl_const_stability_mismatch_impl_stable)]
1169 Stable {
1170 #[primary_span]
1171 span: Span,
1172 },
1173 #[note(passes_trait_impl_const_stability_mismatch_impl_unstable)]
1174 Unstable {
1175 #[primary_span]
1176 span: Span,
1177 },
1178}
1179
1180#[derive(Diagnostic)]
1181#[diag(passes_unknown_feature, code = E0635)]
1182pub(crate) struct UnknownFeature {
1183 #[primary_span]
1184 pub span: Span,
1185 pub feature: Symbol,
1186}
1187
1188#[derive(Diagnostic)]
1189#[diag(passes_unknown_feature_alias, code = E0635)]
1190pub(crate) struct RenamedFeature {
1191 #[primary_span]
1192 pub span: Span,
1193 pub feature: Symbol,
1194 pub alias: Symbol,
1195}
1196
1197#[derive(Diagnostic)]
1198#[diag(passes_implied_feature_not_exist)]
1199pub(crate) struct ImpliedFeatureNotExist {
1200 #[primary_span]
1201 pub span: Span,
1202 pub feature: Symbol,
1203 pub implied_by: Symbol,
1204}
1205
1206#[derive(Diagnostic)]
1207#[diag(passes_duplicate_feature_err, code = E0636)]
1208pub(crate) struct DuplicateFeatureErr {
1209 #[primary_span]
1210 pub span: Span,
1211 pub feature: Symbol,
1212}
1213
1214#[derive(Diagnostic)]
1215#[diag(passes_missing_const_err)]
1216pub(crate) struct MissingConstErr {
1217 #[primary_span]
1218 #[help]
1219 pub fn_sig_span: Span,
1220}
1221
1222#[derive(Diagnostic)]
1223#[diag(passes_const_stable_not_stable)]
1224pub(crate) struct ConstStableNotStable {
1225 #[primary_span]
1226 pub fn_sig_span: Span,
1227 #[label]
1228 pub const_span: Span,
1229}
1230
1231#[derive(LintDiagnostic)]
1232pub(crate) enum MultipleDeadCodes<'tcx> {
1233 #[diag(passes_dead_codes)]
1234 DeadCodes {
1235 multiple: bool,
1236 num: usize,
1237 descr: &'tcx str,
1238 participle: &'tcx str,
1239 name_list: DiagSymbolList,
1240 #[subdiagnostic]
1241 enum_variants_with_same_name: Vec<EnumVariantSameName<'tcx>>,
1243 #[subdiagnostic]
1244 parent_info: Option<ParentInfo<'tcx>>,
1245 #[subdiagnostic]
1246 ignored_derived_impls: Option<IgnoredDerivedImpls>,
1247 },
1248 #[diag(passes_dead_codes)]
1249 UnusedTupleStructFields {
1250 multiple: bool,
1251 num: usize,
1252 descr: &'tcx str,
1253 participle: &'tcx str,
1254 name_list: DiagSymbolList,
1255 #[subdiagnostic]
1256 change_fields_suggestion: ChangeFields,
1257 #[subdiagnostic]
1258 parent_info: Option<ParentInfo<'tcx>>,
1259 #[subdiagnostic]
1260 ignored_derived_impls: Option<IgnoredDerivedImpls>,
1261 },
1262}
1263
1264#[derive(Subdiagnostic)]
1265#[note(passes_enum_variant_same_name)]
1266pub(crate) struct EnumVariantSameName<'tcx> {
1267 #[primary_span]
1268 pub variant_span: Span,
1269 pub dead_name: Symbol,
1270 pub dead_descr: &'tcx str,
1271}
1272
1273#[derive(Subdiagnostic)]
1274#[label(passes_parent_info)]
1275pub(crate) struct ParentInfo<'tcx> {
1276 pub num: usize,
1277 pub descr: &'tcx str,
1278 pub parent_descr: &'tcx str,
1279 #[primary_span]
1280 pub span: Span,
1281}
1282
1283#[derive(Subdiagnostic)]
1284#[note(passes_ignored_derived_impls)]
1285pub(crate) struct IgnoredDerivedImpls {
1286 pub name: Symbol,
1287 pub trait_list: DiagSymbolList,
1288 pub trait_list_len: usize,
1289}
1290
1291#[derive(Subdiagnostic)]
1292pub(crate) enum ChangeFields {
1293 #[multipart_suggestion(
1294 passes_change_fields_to_be_of_unit_type,
1295 applicability = "has-placeholders"
1296 )]
1297 ChangeToUnitTypeOrRemove {
1298 num: usize,
1299 #[suggestion_part(code = "()")]
1300 spans: Vec<Span>,
1301 },
1302 #[help(passes_remove_fields)]
1303 Remove { num: usize },
1304}
1305
1306#[derive(Diagnostic)]
1307#[diag(passes_proc_macro_bad_sig)]
1308pub(crate) struct ProcMacroBadSig {
1309 #[primary_span]
1310 pub span: Span,
1311 pub kind: ProcMacroKind,
1312}
1313
1314#[derive(LintDiagnostic)]
1315#[diag(passes_unnecessary_stable_feature)]
1316pub(crate) struct UnnecessaryStableFeature {
1317 pub feature: Symbol,
1318 pub since: Symbol,
1319}
1320
1321#[derive(LintDiagnostic)]
1322#[diag(passes_unnecessary_partial_stable_feature)]
1323pub(crate) struct UnnecessaryPartialStableFeature {
1324 #[suggestion(code = "{implies}", applicability = "maybe-incorrect")]
1325 pub span: Span,
1326 #[suggestion(passes_suggestion_remove, code = "", applicability = "maybe-incorrect")]
1327 pub line: Span,
1328 pub feature: Symbol,
1329 pub since: Symbol,
1330 pub implies: Symbol,
1331}
1332
1333#[derive(LintDiagnostic)]
1334#[diag(passes_ineffective_unstable_impl)]
1335#[note]
1336pub(crate) struct IneffectiveUnstableImpl;
1337
1338#[derive(LintDiagnostic)]
1339#[diag(passes_attr_crate_level)]
1340#[note]
1341pub(crate) struct AttrCrateLevelOnly {
1342 #[subdiagnostic]
1343 pub sugg: Option<AttrCrateLevelOnlySugg>,
1344}
1345
1346#[derive(Subdiagnostic)]
1347#[suggestion(passes_suggestion, applicability = "maybe-incorrect", code = "!", style = "verbose")]
1348pub(crate) struct AttrCrateLevelOnlySugg {
1349 #[primary_span]
1350 pub attr: Span,
1351}
1352
1353#[derive(Diagnostic)]
1355#[diag(passes_sanitize_attribute_not_allowed)]
1356pub(crate) struct SanitizeAttributeNotAllowed {
1357 #[primary_span]
1358 pub attr_span: Span,
1359 #[label(passes_not_fn_impl_mod)]
1361 pub not_fn_impl_mod: Option<Span>,
1362 #[label(passes_no_body)]
1364 pub no_body: Option<Span>,
1365 #[help]
1367 pub help: (),
1368}
1369
1370#[derive(Diagnostic)]
1372#[diag(passes_rustc_const_stable_indirect_pairing)]
1373pub(crate) struct RustcConstStableIndirectPairing {
1374 #[primary_span]
1375 pub span: Span,
1376}
1377
1378#[derive(Diagnostic)]
1379#[diag(passes_unsupported_attributes_in_where)]
1380#[help]
1381pub(crate) struct UnsupportedAttributesInWhere {
1382 #[primary_span]
1383 pub span: MultiSpan,
1384}
1385
1386#[derive(Diagnostic)]
1387pub(crate) enum UnexportableItem<'a> {
1388 #[diag(passes_unexportable_item)]
1389 Item {
1390 #[primary_span]
1391 span: Span,
1392 descr: &'a str,
1393 },
1394
1395 #[diag(passes_unexportable_generic_fn)]
1396 GenericFn(#[primary_span] Span),
1397
1398 #[diag(passes_unexportable_fn_abi)]
1399 FnAbi(#[primary_span] Span),
1400
1401 #[diag(passes_unexportable_type_repr)]
1402 TypeRepr(#[primary_span] Span),
1403
1404 #[diag(passes_unexportable_type_in_interface)]
1405 TypeInInterface {
1406 #[primary_span]
1407 span: Span,
1408 desc: &'a str,
1409 ty: &'a str,
1410 #[label]
1411 ty_span: Span,
1412 },
1413
1414 #[diag(passes_unexportable_priv_item)]
1415 PrivItem {
1416 #[primary_span]
1417 span: Span,
1418 #[note]
1419 vis_note: Span,
1420 vis_descr: &'a str,
1421 },
1422
1423 #[diag(passes_unexportable_adt_with_private_fields)]
1424 AdtWithPrivFields {
1425 #[primary_span]
1426 span: Span,
1427 #[note]
1428 vis_note: Span,
1429 field_name: &'a str,
1430 },
1431}
1432
1433#[derive(Diagnostic)]
1434#[diag(passes_repr_align_should_be_align)]
1435pub(crate) struct ReprAlignShouldBeAlign {
1436 #[primary_span]
1437 #[help]
1438 pub span: Span,
1439 pub item: &'static str,
1440}
1441
1442#[derive(Diagnostic)]
1443#[diag(passes_repr_align_should_be_align_static)]
1444pub(crate) struct ReprAlignShouldBeAlignStatic {
1445 #[primary_span]
1446 #[help]
1447 pub span: Span,
1448 pub item: &'static str,
1449}
1450
1451#[derive(Diagnostic)]
1452#[diag(passes_custom_mir_phase_requires_dialect)]
1453pub(crate) struct CustomMirPhaseRequiresDialect {
1454 #[primary_span]
1455 pub attr_span: Span,
1456 #[label]
1457 pub phase_span: Span,
1458}
1459
1460#[derive(Diagnostic)]
1461#[diag(passes_custom_mir_incompatible_dialect_and_phase)]
1462pub(crate) struct CustomMirIncompatibleDialectAndPhase {
1463 pub dialect: MirDialect,
1464 pub phase: MirPhase,
1465 #[primary_span]
1466 pub attr_span: Span,
1467 #[label]
1468 pub dialect_span: Span,
1469 #[label]
1470 pub phase_span: Span,
1471}