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