rustc_passes/
errors.rs

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