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, Subdiagnostic,
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_cfg_hide_takes_list)]
313pub(crate) struct DocCfgHideTakesList;
314
315#[derive(LintDiagnostic)]
316#[diag(passes_doc_test_unknown_any)]
317pub(crate) struct DocTestUnknownAny {
318    pub path: String,
319}
320
321#[derive(LintDiagnostic)]
322#[diag(passes_doc_test_unknown_spotlight)]
323#[note]
324#[note(passes_no_op_note)]
325pub(crate) struct DocTestUnknownSpotlight {
326    pub path: String,
327    #[suggestion(style = "short", applicability = "machine-applicable", code = "notable_trait")]
328    pub span: Span,
329}
330
331#[derive(LintDiagnostic)]
332#[diag(passes_doc_test_unknown_passes)]
333#[note]
334#[help]
335#[note(passes_no_op_note)]
336pub(crate) struct DocTestUnknownPasses {
337    pub path: String,
338    #[label]
339    pub span: Span,
340}
341
342#[derive(LintDiagnostic)]
343#[diag(passes_doc_test_unknown_plugins)]
344#[note]
345#[note(passes_no_op_note)]
346pub(crate) struct DocTestUnknownPlugins {
347    pub path: String,
348    #[label]
349    pub span: Span,
350}
351
352#[derive(LintDiagnostic)]
353#[diag(passes_doc_test_unknown_include)]
354pub(crate) struct DocTestUnknownInclude {
355    pub path: String,
356    pub value: String,
357    pub inner: &'static str,
358    #[suggestion(code = "#{inner}[doc = include_str!(\"{value}\")]")]
359    pub sugg: (Span, Applicability),
360}
361
362#[derive(LintDiagnostic)]
363#[diag(passes_doc_invalid)]
364pub(crate) struct DocInvalid;
365
366#[derive(Diagnostic)]
367#[diag(passes_has_incoherent_inherent_impl)]
368pub(crate) struct HasIncoherentInherentImpl {
369    #[primary_span]
370    pub attr_span: Span,
371    #[label]
372    pub span: Span,
373}
374
375#[derive(Diagnostic)]
376#[diag(passes_both_ffi_const_and_pure, code = E0757)]
377pub(crate) struct BothFfiConstAndPure {
378    #[primary_span]
379    pub attr_span: Span,
380}
381
382#[derive(Diagnostic)]
383#[diag(passes_must_not_suspend)]
384pub(crate) struct MustNotSuspend {
385    #[primary_span]
386    pub attr_span: Span,
387    #[label]
388    pub span: Span,
389}
390
391#[derive(LintDiagnostic)]
392#[diag(passes_link)]
393#[warning]
394pub(crate) struct Link {
395    #[label]
396    pub span: Option<Span>,
397}
398
399#[derive(Diagnostic)]
400#[diag(passes_no_link)]
401pub(crate) struct NoLink {
402    #[primary_span]
403    pub attr_span: Span,
404    #[label]
405    pub span: Span,
406}
407
408#[derive(Diagnostic)]
409#[diag(passes_rustc_legacy_const_generics_only)]
410pub(crate) struct RustcLegacyConstGenericsOnly {
411    #[primary_span]
412    pub attr_span: Span,
413    #[label]
414    pub param_span: Span,
415}
416
417#[derive(Diagnostic)]
418#[diag(passes_rustc_legacy_const_generics_index)]
419pub(crate) struct RustcLegacyConstGenericsIndex {
420    #[primary_span]
421    pub attr_span: Span,
422    #[label]
423    pub generics_span: Span,
424}
425
426#[derive(Diagnostic)]
427#[diag(passes_rustc_legacy_const_generics_index_exceed)]
428pub(crate) struct RustcLegacyConstGenericsIndexExceed {
429    #[primary_span]
430    #[label]
431    pub span: Span,
432    pub arg_count: usize,
433}
434
435#[derive(Diagnostic)]
436#[diag(passes_rustc_legacy_const_generics_index_negative)]
437pub(crate) struct RustcLegacyConstGenericsIndexNegative {
438    #[primary_span]
439    pub invalid_args: Vec<Span>,
440}
441
442#[derive(Diagnostic)]
443#[diag(passes_rustc_dirty_clean)]
444pub(crate) struct RustcDirtyClean {
445    #[primary_span]
446    pub span: Span,
447}
448
449#[derive(Diagnostic)]
450#[diag(passes_repr_conflicting, code = E0566)]
451pub(crate) struct ReprConflicting {
452    #[primary_span]
453    pub hint_spans: Vec<Span>,
454}
455
456#[derive(Diagnostic)]
457#[diag(passes_repr_align_greater_than_target_max, code = E0589)]
458#[note]
459pub(crate) struct InvalidReprAlignForTarget {
460    #[primary_span]
461    pub span: Span,
462    pub size: u64,
463}
464
465#[derive(LintDiagnostic)]
466#[diag(passes_repr_conflicting, code = E0566)]
467pub(crate) struct ReprConflictingLint;
468
469#[derive(Diagnostic)]
470#[diag(passes_macro_only_attribute)]
471pub(crate) struct MacroOnlyAttribute {
472    #[primary_span]
473    pub attr_span: Span,
474    #[label]
475    pub span: Span,
476}
477
478#[derive(Diagnostic)]
479#[diag(passes_debug_visualizer_placement)]
480pub(crate) struct DebugVisualizerPlacement {
481    #[primary_span]
482    pub span: Span,
483}
484
485#[derive(Diagnostic)]
486#[diag(passes_debug_visualizer_invalid)]
487#[note(passes_note_1)]
488#[note(passes_note_2)]
489#[note(passes_note_3)]
490pub(crate) struct DebugVisualizerInvalid {
491    #[primary_span]
492    pub span: Span,
493}
494
495#[derive(Diagnostic)]
496#[diag(passes_debug_visualizer_unreadable)]
497pub(crate) struct DebugVisualizerUnreadable<'a> {
498    #[primary_span]
499    pub span: Span,
500    pub file: &'a Path,
501    pub error: Error,
502}
503
504#[derive(Diagnostic)]
505#[diag(passes_rustc_allow_const_fn_unstable)]
506pub(crate) struct RustcAllowConstFnUnstable {
507    #[primary_span]
508    pub attr_span: Span,
509    #[label]
510    pub span: Span,
511}
512
513#[derive(Diagnostic)]
514#[diag(passes_rustc_pub_transparent)]
515pub(crate) struct RustcPubTransparent {
516    #[primary_span]
517    pub attr_span: Span,
518    #[label]
519    pub span: Span,
520}
521
522#[derive(Diagnostic)]
523#[diag(passes_rustc_force_inline_coro)]
524pub(crate) struct RustcForceInlineCoro {
525    #[primary_span]
526    pub attr_span: Span,
527    #[label]
528    pub span: Span,
529}
530
531#[derive(LintDiagnostic)]
532pub(crate) enum MacroExport {
533    #[diag(passes_macro_export_on_decl_macro)]
534    #[note]
535    OnDeclMacro,
536}
537
538#[derive(Subdiagnostic)]
539pub(crate) enum UnusedNote {
540    #[note(passes_unused_empty_lints_note)]
541    EmptyList { name: Symbol },
542    #[note(passes_unused_no_lints_note)]
543    NoLints { name: Symbol },
544    #[note(passes_unused_default_method_body_const_note)]
545    DefaultMethodBodyConst,
546    #[note(passes_unused_linker_messages_note)]
547    LinkerMessagesBinaryCrateOnly,
548}
549
550#[derive(LintDiagnostic)]
551#[diag(passes_unused)]
552pub(crate) struct Unused {
553    #[suggestion(code = "", applicability = "machine-applicable")]
554    pub attr_span: Span,
555    #[subdiagnostic]
556    pub note: UnusedNote,
557}
558
559#[derive(Diagnostic)]
560#[diag(passes_non_exported_macro_invalid_attrs, code = E0518)]
561pub(crate) struct NonExportedMacroInvalidAttrs {
562    #[primary_span]
563    #[label]
564    pub attr_span: Span,
565}
566
567#[derive(Diagnostic)]
568#[diag(passes_may_dangle)]
569pub(crate) struct InvalidMayDangle {
570    #[primary_span]
571    pub attr_span: Span,
572}
573
574#[derive(LintDiagnostic)]
575#[diag(passes_unused_duplicate)]
576pub(crate) struct UnusedDuplicate {
577    #[suggestion(code = "", applicability = "machine-applicable")]
578    pub this: Span,
579    #[note]
580    pub other: Span,
581    #[warning]
582    pub warning: bool,
583}
584
585#[derive(Diagnostic)]
586#[diag(passes_unused_multiple)]
587pub(crate) struct UnusedMultiple {
588    #[primary_span]
589    #[suggestion(code = "", applicability = "machine-applicable")]
590    pub this: Span,
591    #[note]
592    pub other: Span,
593    pub name: Symbol,
594}
595
596#[derive(Diagnostic)]
597#[diag(passes_rustc_lint_opt_ty)]
598pub(crate) struct RustcLintOptTy {
599    #[primary_span]
600    pub attr_span: Span,
601    #[label]
602    pub span: Span,
603}
604
605#[derive(Diagnostic)]
606#[diag(passes_rustc_lint_opt_deny_field_access)]
607pub(crate) struct RustcLintOptDenyFieldAccess {
608    #[primary_span]
609    pub attr_span: Span,
610    #[label]
611    pub span: Span,
612}
613
614#[derive(Diagnostic)]
615#[diag(passes_collapse_debuginfo)]
616pub(crate) struct CollapseDebuginfo {
617    #[primary_span]
618    pub attr_span: Span,
619    #[label]
620    pub defn_span: Span,
621}
622
623#[derive(LintDiagnostic)]
624#[diag(passes_deprecated_annotation_has_no_effect)]
625pub(crate) struct DeprecatedAnnotationHasNoEffect {
626    #[suggestion(applicability = "machine-applicable", code = "")]
627    pub span: Span,
628}
629
630#[derive(Diagnostic)]
631#[diag(passes_unknown_external_lang_item, code = E0264)]
632pub(crate) struct UnknownExternLangItem {
633    #[primary_span]
634    pub span: Span,
635    pub lang_item: Symbol,
636}
637
638#[derive(Diagnostic)]
639#[diag(passes_missing_panic_handler)]
640pub(crate) struct MissingPanicHandler;
641
642#[derive(Diagnostic)]
643#[diag(passes_panic_unwind_without_std)]
644#[help]
645#[note]
646pub(crate) struct PanicUnwindWithoutStd;
647
648#[derive(Diagnostic)]
649#[diag(passes_missing_lang_item)]
650#[note]
651#[help]
652pub(crate) struct MissingLangItem {
653    pub name: Symbol,
654}
655
656#[derive(Diagnostic)]
657#[diag(passes_lang_item_fn_with_track_caller)]
658pub(crate) struct LangItemWithTrackCaller {
659    #[primary_span]
660    pub attr_span: Span,
661    pub name: Symbol,
662    #[label]
663    pub sig_span: Span,
664}
665
666#[derive(Diagnostic)]
667#[diag(passes_lang_item_fn_with_target_feature)]
668pub(crate) struct LangItemWithTargetFeature {
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_on_incorrect_target, code = E0718)]
678pub(crate) struct LangItemOnIncorrectTarget {
679    #[primary_span]
680    #[label]
681    pub span: Span,
682    pub name: Symbol,
683    pub expected_target: Target,
684    pub actual_target: Target,
685}
686
687#[derive(Diagnostic)]
688#[diag(passes_unknown_lang_item, code = E0522)]
689pub(crate) struct UnknownLangItem {
690    #[primary_span]
691    #[label]
692    pub span: Span,
693    pub name: Symbol,
694}
695
696pub(crate) struct InvalidAttrAtCrateLevel {
697    pub span: Span,
698    pub sugg_span: Option<Span>,
699    pub name: Symbol,
700    pub item: Option<ItemFollowingInnerAttr>,
701}
702
703#[derive(Clone, Copy)]
704pub(crate) struct ItemFollowingInnerAttr {
705    pub span: Span,
706    pub kind: &'static str,
707}
708
709impl<G: EmissionGuarantee> Diagnostic<'_, G> for InvalidAttrAtCrateLevel {
710    #[track_caller]
711    fn into_diag(self, dcx: DiagCtxtHandle<'_>, level: Level) -> Diag<'_, G> {
712        let mut diag = Diag::new(dcx, level, fluent::passes_invalid_attr_at_crate_level);
713        diag.span(self.span);
714        diag.arg("name", self.name);
715        // Only emit an error with a suggestion if we can create a string out
716        // of the attribute span
717        if let Some(span) = self.sugg_span {
718            diag.span_suggestion_verbose(
719                span,
720                fluent::passes_suggestion,
721                String::new(),
722                Applicability::MachineApplicable,
723            );
724        }
725        if let Some(item) = self.item {
726            diag.arg("kind", item.kind);
727            diag.span_label(item.span, fluent::passes_invalid_attr_at_crate_level_item);
728        }
729        diag
730    }
731}
732
733#[derive(Diagnostic)]
734#[diag(passes_duplicate_diagnostic_item_in_crate)]
735pub(crate) struct DuplicateDiagnosticItemInCrate {
736    #[primary_span]
737    pub duplicate_span: Option<Span>,
738    #[note(passes_diagnostic_item_first_defined)]
739    pub orig_span: Option<Span>,
740    #[note]
741    pub different_crates: bool,
742    pub crate_name: Symbol,
743    pub orig_crate_name: Symbol,
744    pub name: Symbol,
745}
746
747#[derive(Diagnostic)]
748#[diag(passes_layout_abi)]
749pub(crate) struct LayoutAbi {
750    #[primary_span]
751    pub span: Span,
752    pub abi: String,
753}
754
755#[derive(Diagnostic)]
756#[diag(passes_layout_align)]
757pub(crate) struct LayoutAlign {
758    #[primary_span]
759    pub span: Span,
760    pub align: String,
761}
762
763#[derive(Diagnostic)]
764#[diag(passes_layout_size)]
765pub(crate) struct LayoutSize {
766    #[primary_span]
767    pub span: Span,
768    pub size: String,
769}
770
771#[derive(Diagnostic)]
772#[diag(passes_layout_homogeneous_aggregate)]
773pub(crate) struct LayoutHomogeneousAggregate {
774    #[primary_span]
775    pub span: Span,
776    pub homogeneous_aggregate: String,
777}
778
779#[derive(Diagnostic)]
780#[diag(passes_layout_of)]
781pub(crate) struct LayoutOf<'tcx> {
782    #[primary_span]
783    pub span: Span,
784    pub normalized_ty: Ty<'tcx>,
785    pub ty_layout: String,
786}
787
788#[derive(Diagnostic)]
789#[diag(passes_layout_invalid_attribute)]
790pub(crate) struct LayoutInvalidAttribute {
791    #[primary_span]
792    pub span: Span,
793}
794
795#[derive(Diagnostic)]
796#[diag(passes_abi_of)]
797pub(crate) struct AbiOf {
798    #[primary_span]
799    pub span: Span,
800    pub fn_name: Symbol,
801    pub fn_abi: String,
802}
803
804#[derive(Diagnostic)]
805#[diag(passes_abi_ne)]
806pub(crate) struct AbiNe {
807    #[primary_span]
808    pub span: Span,
809    pub left: String,
810    pub right: String,
811}
812
813#[derive(Diagnostic)]
814#[diag(passes_abi_invalid_attribute)]
815pub(crate) struct AbiInvalidAttribute {
816    #[primary_span]
817    pub span: Span,
818}
819
820#[derive(Diagnostic)]
821#[diag(passes_unrecognized_argument)]
822pub(crate) struct UnrecognizedArgument {
823    #[primary_span]
824    pub span: Span,
825}
826
827#[derive(Diagnostic)]
828#[diag(passes_feature_stable_twice, code = E0711)]
829pub(crate) struct FeatureStableTwice {
830    #[primary_span]
831    pub span: Span,
832    pub feature: Symbol,
833    pub since: Symbol,
834    pub prev_since: Symbol,
835}
836
837#[derive(Diagnostic)]
838#[diag(passes_feature_previously_declared, code = E0711)]
839pub(crate) struct FeaturePreviouslyDeclared<'a> {
840    #[primary_span]
841    pub span: Span,
842    pub feature: Symbol,
843    pub declared: &'a str,
844    pub prev_declared: &'a str,
845}
846
847#[derive(Diagnostic)]
848#[diag(passes_attr_only_in_functions)]
849pub(crate) struct AttrOnlyInFunctions {
850    #[primary_span]
851    pub span: Span,
852    pub attr: Symbol,
853}
854
855#[derive(Diagnostic)]
856#[diag(passes_multiple_rustc_main, code = E0137)]
857pub(crate) struct MultipleRustcMain {
858    #[primary_span]
859    pub span: Span,
860    #[label(passes_first)]
861    pub first: Span,
862    #[label(passes_additional)]
863    pub additional: Span,
864}
865
866#[derive(Diagnostic)]
867#[diag(passes_extern_main)]
868pub(crate) struct ExternMain {
869    #[primary_span]
870    pub span: Span,
871}
872
873pub(crate) struct NoMainErr {
874    pub sp: Span,
875    pub crate_name: Symbol,
876    pub has_filename: bool,
877    pub filename: PathBuf,
878    pub file_empty: bool,
879    pub non_main_fns: Vec<Span>,
880    pub main_def_opt: Option<MainDefinition>,
881    pub add_teach_note: bool,
882}
883
884impl<'a, G: EmissionGuarantee> Diagnostic<'a, G> for NoMainErr {
885    #[track_caller]
886    fn into_diag(self, dcx: DiagCtxtHandle<'a>, level: Level) -> Diag<'a, G> {
887        let mut diag = Diag::new(dcx, level, fluent::passes_no_main_function);
888        diag.span(DUMMY_SP);
889        diag.code(E0601);
890        diag.arg("crate_name", self.crate_name);
891        diag.arg("filename", self.filename);
892        diag.arg("has_filename", self.has_filename);
893        let note = if !self.non_main_fns.is_empty() {
894            for &span in &self.non_main_fns {
895                diag.span_note(span, fluent::passes_here_is_main);
896            }
897            diag.note(fluent::passes_one_or_more_possible_main);
898            diag.help(fluent::passes_consider_moving_main);
899            // There were some functions named `main` though. Try to give the user a hint.
900            fluent::passes_main_must_be_defined_at_crate
901        } else if self.has_filename {
902            fluent::passes_consider_adding_main_to_file
903        } else {
904            fluent::passes_consider_adding_main_at_crate
905        };
906        if self.file_empty {
907            diag.note(note);
908        } else {
909            diag.span(self.sp.shrink_to_hi());
910            diag.span_label(self.sp.shrink_to_hi(), note);
911        }
912
913        if let Some(main_def) = self.main_def_opt
914            && main_def.opt_fn_def_id().is_none()
915        {
916            // There is something at `crate::main`, but it is not a function definition.
917            diag.span_label(main_def.span, fluent::passes_non_function_main);
918        }
919
920        if self.add_teach_note {
921            diag.note(fluent::passes_teach_note);
922        }
923        diag
924    }
925}
926
927pub(crate) struct DuplicateLangItem {
928    pub local_span: Option<Span>,
929    pub lang_item_name: Symbol,
930    pub crate_name: Symbol,
931    pub dependency_of: Option<Symbol>,
932    pub is_local: bool,
933    pub path: String,
934    pub first_defined_span: Option<Span>,
935    pub orig_crate_name: Option<Symbol>,
936    pub orig_dependency_of: Option<Symbol>,
937    pub orig_is_local: bool,
938    pub orig_path: String,
939    pub(crate) duplicate: Duplicate,
940}
941
942impl<G: EmissionGuarantee> Diagnostic<'_, G> for DuplicateLangItem {
943    #[track_caller]
944    fn into_diag(self, dcx: DiagCtxtHandle<'_>, level: Level) -> Diag<'_, G> {
945        let mut diag = Diag::new(
946            dcx,
947            level,
948            match self.duplicate {
949                Duplicate::Plain => fluent::passes_duplicate_lang_item,
950                Duplicate::Crate => fluent::passes_duplicate_lang_item_crate,
951                Duplicate::CrateDepends => fluent::passes_duplicate_lang_item_crate_depends,
952            },
953        );
954        diag.code(E0152);
955        diag.arg("lang_item_name", self.lang_item_name);
956        diag.arg("crate_name", self.crate_name);
957        if let Some(dependency_of) = self.dependency_of {
958            diag.arg("dependency_of", dependency_of);
959        }
960        diag.arg("path", self.path);
961        if let Some(orig_crate_name) = self.orig_crate_name {
962            diag.arg("orig_crate_name", orig_crate_name);
963        }
964        if let Some(orig_dependency_of) = self.orig_dependency_of {
965            diag.arg("orig_dependency_of", orig_dependency_of);
966        }
967        diag.arg("orig_path", self.orig_path);
968        if let Some(span) = self.local_span {
969            diag.span(span);
970        }
971        if let Some(span) = self.first_defined_span {
972            diag.span_note(span, fluent::passes_first_defined_span);
973        } else {
974            if self.orig_dependency_of.is_none() {
975                diag.note(fluent::passes_first_defined_crate);
976            } else {
977                diag.note(fluent::passes_first_defined_crate_depends);
978            }
979
980            if self.orig_is_local {
981                diag.note(fluent::passes_first_definition_local);
982            } else {
983                diag.note(fluent::passes_first_definition_path);
984            }
985
986            if self.is_local {
987                diag.note(fluent::passes_second_definition_local);
988            } else {
989                diag.note(fluent::passes_second_definition_path);
990            }
991        }
992        diag
993    }
994}
995
996#[derive(Diagnostic)]
997#[diag(passes_incorrect_target, code = E0718)]
998pub(crate) struct IncorrectTarget<'a> {
999    #[primary_span]
1000    pub span: Span,
1001    #[label]
1002    pub generics_span: Span,
1003    pub name: &'a str, // cannot be symbol because it renders e.g. `r#fn` instead of `fn`
1004    pub kind: &'static str,
1005    pub num: usize,
1006    pub actual_num: usize,
1007    pub at_least: bool,
1008}
1009
1010#[derive(Diagnostic)]
1011#[diag(passes_incorrect_crate_type)]
1012pub(crate) struct IncorrectCrateType {
1013    #[primary_span]
1014    pub span: Span,
1015}
1016
1017#[derive(LintDiagnostic)]
1018#[diag(passes_useless_assignment)]
1019pub(crate) struct UselessAssignment<'a> {
1020    pub is_field_assign: bool,
1021    pub ty: Ty<'a>,
1022}
1023
1024#[derive(LintDiagnostic)]
1025#[diag(passes_inline_ignored_for_exported)]
1026#[help]
1027pub(crate) struct InlineIgnoredForExported {}
1028
1029#[derive(Diagnostic)]
1030#[diag(passes_object_lifetime_err)]
1031pub(crate) struct ObjectLifetimeErr {
1032    #[primary_span]
1033    pub span: Span,
1034    pub repr: String,
1035}
1036
1037#[derive(Diagnostic)]
1038pub(crate) enum AttrApplication {
1039    #[diag(passes_attr_application_enum, code = E0517)]
1040    Enum {
1041        #[primary_span]
1042        hint_span: Span,
1043        #[label]
1044        span: Span,
1045    },
1046    #[diag(passes_attr_application_struct, code = E0517)]
1047    Struct {
1048        #[primary_span]
1049        hint_span: Span,
1050        #[label]
1051        span: Span,
1052    },
1053    #[diag(passes_attr_application_struct_union, code = E0517)]
1054    StructUnion {
1055        #[primary_span]
1056        hint_span: Span,
1057        #[label]
1058        span: Span,
1059    },
1060    #[diag(passes_attr_application_struct_enum_union, code = E0517)]
1061    StructEnumUnion {
1062        #[primary_span]
1063        hint_span: Span,
1064        #[label]
1065        span: Span,
1066    },
1067}
1068
1069#[derive(Diagnostic)]
1070#[diag(passes_transparent_incompatible, code = E0692)]
1071pub(crate) struct TransparentIncompatible {
1072    #[primary_span]
1073    pub hint_spans: Vec<Span>,
1074    pub target: String,
1075}
1076
1077#[derive(Diagnostic)]
1078#[diag(passes_deprecated_attribute, code = E0549)]
1079pub(crate) struct DeprecatedAttribute {
1080    #[primary_span]
1081    pub span: Span,
1082}
1083
1084#[derive(Diagnostic)]
1085#[diag(passes_useless_stability)]
1086pub(crate) struct UselessStability {
1087    #[primary_span]
1088    #[label]
1089    pub span: Span,
1090    #[label(passes_item)]
1091    pub item_sp: Span,
1092}
1093
1094#[derive(Diagnostic)]
1095#[diag(passes_cannot_stabilize_deprecated)]
1096pub(crate) struct CannotStabilizeDeprecated {
1097    #[primary_span]
1098    #[label]
1099    pub span: Span,
1100    #[label(passes_item)]
1101    pub item_sp: Span,
1102}
1103
1104#[derive(Diagnostic)]
1105#[diag(passes_unstable_attr_for_already_stable_feature)]
1106pub(crate) struct UnstableAttrForAlreadyStableFeature {
1107    #[primary_span]
1108    #[label]
1109    #[help]
1110    pub attr_span: Span,
1111    #[label(passes_item)]
1112    pub item_span: Span,
1113}
1114
1115#[derive(Diagnostic)]
1116#[diag(passes_missing_stability_attr)]
1117pub(crate) struct MissingStabilityAttr<'a> {
1118    #[primary_span]
1119    pub span: Span,
1120    pub descr: &'a str,
1121}
1122
1123#[derive(Diagnostic)]
1124#[diag(passes_missing_const_stab_attr)]
1125pub(crate) struct MissingConstStabAttr<'a> {
1126    #[primary_span]
1127    pub span: Span,
1128    pub descr: &'a str,
1129}
1130
1131#[derive(Diagnostic)]
1132#[diag(passes_trait_impl_const_stable)]
1133#[note]
1134pub(crate) struct TraitImplConstStable {
1135    #[primary_span]
1136    pub span: Span,
1137}
1138
1139#[derive(Diagnostic)]
1140#[diag(passes_trait_impl_const_stability_mismatch)]
1141pub(crate) struct TraitImplConstStabilityMismatch {
1142    #[primary_span]
1143    pub span: Span,
1144    #[subdiagnostic]
1145    pub impl_stability: ImplConstStability,
1146    #[subdiagnostic]
1147    pub trait_stability: TraitConstStability,
1148}
1149
1150#[derive(Subdiagnostic)]
1151pub(crate) enum TraitConstStability {
1152    #[note(passes_trait_impl_const_stability_mismatch_trait_stable)]
1153    Stable {
1154        #[primary_span]
1155        span: Span,
1156    },
1157    #[note(passes_trait_impl_const_stability_mismatch_trait_unstable)]
1158    Unstable {
1159        #[primary_span]
1160        span: Span,
1161    },
1162}
1163
1164#[derive(Subdiagnostic)]
1165pub(crate) enum ImplConstStability {
1166    #[note(passes_trait_impl_const_stability_mismatch_impl_stable)]
1167    Stable {
1168        #[primary_span]
1169        span: Span,
1170    },
1171    #[note(passes_trait_impl_const_stability_mismatch_impl_unstable)]
1172    Unstable {
1173        #[primary_span]
1174        span: Span,
1175    },
1176}
1177
1178#[derive(Diagnostic)]
1179#[diag(passes_unknown_feature, code = E0635)]
1180pub(crate) struct UnknownFeature {
1181    #[primary_span]
1182    pub span: Span,
1183    pub feature: Symbol,
1184}
1185
1186#[derive(Diagnostic)]
1187#[diag(passes_unknown_feature_alias, code = E0635)]
1188pub(crate) struct RenamedFeature {
1189    #[primary_span]
1190    pub span: Span,
1191    pub feature: Symbol,
1192    pub alias: Symbol,
1193}
1194
1195#[derive(Diagnostic)]
1196#[diag(passes_implied_feature_not_exist)]
1197pub(crate) struct ImpliedFeatureNotExist {
1198    #[primary_span]
1199    pub span: Span,
1200    pub feature: Symbol,
1201    pub implied_by: Symbol,
1202}
1203
1204#[derive(Diagnostic)]
1205#[diag(passes_duplicate_feature_err, code = E0636)]
1206pub(crate) struct DuplicateFeatureErr {
1207    #[primary_span]
1208    pub span: Span,
1209    pub feature: Symbol,
1210}
1211
1212#[derive(Diagnostic)]
1213#[diag(passes_missing_const_err)]
1214pub(crate) struct MissingConstErr {
1215    #[primary_span]
1216    #[help]
1217    pub fn_sig_span: Span,
1218}
1219
1220#[derive(Diagnostic)]
1221#[diag(passes_const_stable_not_stable)]
1222pub(crate) struct ConstStableNotStable {
1223    #[primary_span]
1224    pub fn_sig_span: Span,
1225    #[label]
1226    pub const_span: Span,
1227}
1228
1229#[derive(LintDiagnostic)]
1230pub(crate) enum MultipleDeadCodes<'tcx> {
1231    #[diag(passes_dead_codes)]
1232    DeadCodes {
1233        multiple: bool,
1234        num: usize,
1235        descr: &'tcx str,
1236        participle: &'tcx str,
1237        name_list: DiagSymbolList,
1238        #[subdiagnostic]
1239        // only on DeadCodes since it's never a problem for tuple struct fields
1240        enum_variants_with_same_name: Vec<EnumVariantSameName<'tcx>>,
1241        #[subdiagnostic]
1242        parent_info: Option<ParentInfo<'tcx>>,
1243        #[subdiagnostic]
1244        ignored_derived_impls: Option<IgnoredDerivedImpls>,
1245    },
1246    #[diag(passes_dead_codes)]
1247    UnusedTupleStructFields {
1248        multiple: bool,
1249        num: usize,
1250        descr: &'tcx str,
1251        participle: &'tcx str,
1252        name_list: DiagSymbolList,
1253        #[subdiagnostic]
1254        change_fields_suggestion: ChangeFields,
1255        #[subdiagnostic]
1256        parent_info: Option<ParentInfo<'tcx>>,
1257        #[subdiagnostic]
1258        ignored_derived_impls: Option<IgnoredDerivedImpls>,
1259    },
1260}
1261
1262#[derive(Subdiagnostic)]
1263#[note(passes_enum_variant_same_name)]
1264pub(crate) struct EnumVariantSameName<'tcx> {
1265    #[primary_span]
1266    pub variant_span: Span,
1267    pub dead_name: Symbol,
1268    pub dead_descr: &'tcx str,
1269}
1270
1271#[derive(Subdiagnostic)]
1272#[label(passes_parent_info)]
1273pub(crate) struct ParentInfo<'tcx> {
1274    pub num: usize,
1275    pub descr: &'tcx str,
1276    pub parent_descr: &'tcx str,
1277    #[primary_span]
1278    pub span: Span,
1279}
1280
1281#[derive(Subdiagnostic)]
1282#[note(passes_ignored_derived_impls)]
1283pub(crate) struct IgnoredDerivedImpls {
1284    pub name: Symbol,
1285    pub trait_list: DiagSymbolList,
1286    pub trait_list_len: usize,
1287}
1288
1289#[derive(Subdiagnostic)]
1290pub(crate) enum ChangeFields {
1291    #[multipart_suggestion(
1292        passes_change_fields_to_be_of_unit_type,
1293        applicability = "has-placeholders"
1294    )]
1295    ChangeToUnitTypeOrRemove {
1296        num: usize,
1297        #[suggestion_part(code = "()")]
1298        spans: Vec<Span>,
1299    },
1300    #[help(passes_remove_fields)]
1301    Remove { num: usize },
1302}
1303
1304#[derive(Diagnostic)]
1305#[diag(passes_proc_macro_bad_sig)]
1306pub(crate) struct ProcMacroBadSig {
1307    #[primary_span]
1308    pub span: Span,
1309    pub kind: ProcMacroKind,
1310}
1311
1312#[derive(LintDiagnostic)]
1313#[diag(passes_unreachable_due_to_uninhabited)]
1314pub(crate) struct UnreachableDueToUninhabited<'desc, 'tcx> {
1315    pub descr: &'desc str,
1316    #[label]
1317    pub expr: Span,
1318    #[label(passes_label_orig)]
1319    #[note]
1320    pub orig: Span,
1321    pub ty: Ty<'tcx>,
1322}
1323
1324#[derive(LintDiagnostic)]
1325#[diag(passes_unused_var_maybe_capture_ref)]
1326#[help]
1327pub(crate) struct UnusedVarMaybeCaptureRef {
1328    pub name: String,
1329}
1330
1331#[derive(LintDiagnostic)]
1332#[diag(passes_unused_capture_maybe_capture_ref)]
1333#[help]
1334pub(crate) struct UnusedCaptureMaybeCaptureRef {
1335    pub name: String,
1336}
1337
1338#[derive(LintDiagnostic)]
1339#[diag(passes_unused_var_remove_field)]
1340pub(crate) struct UnusedVarRemoveField {
1341    pub name: String,
1342    #[subdiagnostic]
1343    pub sugg: UnusedVarRemoveFieldSugg,
1344}
1345
1346#[derive(Subdiagnostic)]
1347#[multipart_suggestion(
1348    passes_unused_var_remove_field_suggestion,
1349    applicability = "machine-applicable"
1350)]
1351pub(crate) struct UnusedVarRemoveFieldSugg {
1352    #[suggestion_part(code = "")]
1353    pub spans: Vec<Span>,
1354}
1355
1356#[derive(LintDiagnostic)]
1357#[diag(passes_unused_var_assigned_only)]
1358#[note]
1359pub(crate) struct UnusedVarAssignedOnly {
1360    pub name: String,
1361    #[subdiagnostic]
1362    pub typo: Option<PatternTypo>,
1363}
1364
1365#[derive(Subdiagnostic)]
1366#[multipart_suggestion(
1367    passes_unused_var_typo,
1368    style = "verbose",
1369    applicability = "machine-applicable"
1370)]
1371pub(crate) struct PatternTypo {
1372    #[suggestion_part(code = "{code}")]
1373    pub span: Span,
1374    pub code: String,
1375    pub item_name: String,
1376    pub kind: String,
1377}
1378
1379#[derive(LintDiagnostic)]
1380#[diag(passes_unnecessary_stable_feature)]
1381pub(crate) struct UnnecessaryStableFeature {
1382    pub feature: Symbol,
1383    pub since: Symbol,
1384}
1385
1386#[derive(LintDiagnostic)]
1387#[diag(passes_unnecessary_partial_stable_feature)]
1388pub(crate) struct UnnecessaryPartialStableFeature {
1389    #[suggestion(code = "{implies}", applicability = "maybe-incorrect")]
1390    pub span: Span,
1391    #[suggestion(passes_suggestion_remove, code = "", applicability = "maybe-incorrect")]
1392    pub line: Span,
1393    pub feature: Symbol,
1394    pub since: Symbol,
1395    pub implies: Symbol,
1396}
1397
1398#[derive(LintDiagnostic)]
1399#[diag(passes_ineffective_unstable_impl)]
1400#[note]
1401pub(crate) struct IneffectiveUnstableImpl;
1402
1403#[derive(LintDiagnostic)]
1404#[diag(passes_unused_assign)]
1405pub(crate) struct UnusedAssign {
1406    pub name: String,
1407    #[subdiagnostic]
1408    pub suggestion: Option<UnusedAssignSuggestion>,
1409    #[help]
1410    pub help: bool,
1411}
1412
1413#[derive(Subdiagnostic)]
1414#[multipart_suggestion(passes_unused_assign_suggestion, applicability = "maybe-incorrect")]
1415pub(crate) struct UnusedAssignSuggestion {
1416    pub pre: &'static str,
1417    #[suggestion_part(code = "{pre}mut ")]
1418    pub ty_span: Option<Span>,
1419    #[suggestion_part(code = "")]
1420    pub ty_ref_span: Span,
1421    #[suggestion_part(code = "*")]
1422    pub ident_span: Span,
1423    #[suggestion_part(code = "")]
1424    pub expr_ref_span: Span,
1425}
1426
1427#[derive(LintDiagnostic)]
1428#[diag(passes_unused_assign_passed)]
1429#[help]
1430pub(crate) struct UnusedAssignPassed {
1431    pub name: String,
1432}
1433
1434#[derive(LintDiagnostic)]
1435#[diag(passes_unused_variable_try_prefix)]
1436pub(crate) struct UnusedVariableTryPrefix {
1437    #[label]
1438    pub label: Option<Span>,
1439    #[subdiagnostic]
1440    pub string_interp: Vec<UnusedVariableStringInterp>,
1441    #[subdiagnostic]
1442    pub sugg: UnusedVariableSugg,
1443    pub name: String,
1444    #[subdiagnostic]
1445    pub typo: Option<PatternTypo>,
1446}
1447
1448#[derive(Subdiagnostic)]
1449pub(crate) enum UnusedVariableSugg {
1450    #[multipart_suggestion(passes_suggestion, applicability = "maybe-incorrect")]
1451    TryPrefixSugg {
1452        #[suggestion_part(code = "_{name}")]
1453        spans: Vec<Span>,
1454        name: String,
1455    },
1456    #[help(passes_unused_variable_args_in_macro)]
1457    NoSugg {
1458        #[primary_span]
1459        span: Span,
1460        name: String,
1461    },
1462}
1463
1464pub(crate) struct UnusedVariableStringInterp {
1465    pub lit: Span,
1466    pub lo: Span,
1467    pub hi: Span,
1468}
1469
1470impl Subdiagnostic for UnusedVariableStringInterp {
1471    fn add_to_diag<G: EmissionGuarantee>(self, diag: &mut Diag<'_, G>) {
1472        diag.span_label(self.lit, crate::fluent_generated::passes_maybe_string_interpolation);
1473        diag.multipart_suggestion(
1474            crate::fluent_generated::passes_string_interpolation_only_works,
1475            vec![(self.lo, String::from("format!(")), (self.hi, String::from(")"))],
1476            Applicability::MachineApplicable,
1477        );
1478    }
1479}
1480
1481#[derive(LintDiagnostic)]
1482#[diag(passes_unused_variable_try_ignore)]
1483pub(crate) struct UnusedVarTryIgnore {
1484    pub name: String,
1485    #[subdiagnostic]
1486    pub sugg: UnusedVarTryIgnoreSugg,
1487}
1488
1489#[derive(Subdiagnostic)]
1490#[multipart_suggestion(passes_suggestion, applicability = "maybe-incorrect")]
1491pub(crate) struct UnusedVarTryIgnoreSugg {
1492    #[suggestion_part(code = "{name}: _")]
1493    pub shorthands: Vec<Span>,
1494    #[suggestion_part(code = "_")]
1495    pub non_shorthands: Vec<Span>,
1496    pub name: String,
1497}
1498
1499#[derive(LintDiagnostic)]
1500#[diag(passes_attr_crate_level)]
1501#[note]
1502pub(crate) struct AttrCrateLevelOnly {
1503    #[subdiagnostic]
1504    pub sugg: Option<AttrCrateLevelOnlySugg>,
1505}
1506
1507#[derive(Subdiagnostic)]
1508#[suggestion(passes_suggestion, applicability = "maybe-incorrect", code = "!", style = "verbose")]
1509pub(crate) struct AttrCrateLevelOnlySugg {
1510    #[primary_span]
1511    pub attr: Span,
1512}
1513
1514/// "sanitize attribute not allowed here"
1515#[derive(Diagnostic)]
1516#[diag(passes_sanitize_attribute_not_allowed)]
1517pub(crate) struct SanitizeAttributeNotAllowed {
1518    #[primary_span]
1519    pub attr_span: Span,
1520    /// "not a function, impl block, or module"
1521    #[label(passes_not_fn_impl_mod)]
1522    pub not_fn_impl_mod: Option<Span>,
1523    /// "function has no body"
1524    #[label(passes_no_body)]
1525    pub no_body: Option<Span>,
1526    /// "sanitize attribute can be applied to a function (with body), impl block, or module"
1527    #[help]
1528    pub help: (),
1529}
1530
1531// FIXME(jdonszelmann): move back to rustc_attr
1532#[derive(Diagnostic)]
1533#[diag(passes_rustc_const_stable_indirect_pairing)]
1534pub(crate) struct RustcConstStableIndirectPairing {
1535    #[primary_span]
1536    pub span: Span,
1537}
1538
1539#[derive(Diagnostic)]
1540#[diag(passes_unsupported_attributes_in_where)]
1541#[help]
1542pub(crate) struct UnsupportedAttributesInWhere {
1543    #[primary_span]
1544    pub span: MultiSpan,
1545}
1546
1547#[derive(Diagnostic)]
1548pub(crate) enum UnexportableItem<'a> {
1549    #[diag(passes_unexportable_item)]
1550    Item {
1551        #[primary_span]
1552        span: Span,
1553        descr: &'a str,
1554    },
1555
1556    #[diag(passes_unexportable_generic_fn)]
1557    GenericFn(#[primary_span] Span),
1558
1559    #[diag(passes_unexportable_fn_abi)]
1560    FnAbi(#[primary_span] Span),
1561
1562    #[diag(passes_unexportable_type_repr)]
1563    TypeRepr(#[primary_span] Span),
1564
1565    #[diag(passes_unexportable_type_in_interface)]
1566    TypeInInterface {
1567        #[primary_span]
1568        span: Span,
1569        desc: &'a str,
1570        ty: &'a str,
1571        #[label]
1572        ty_span: Span,
1573    },
1574
1575    #[diag(passes_unexportable_priv_item)]
1576    PrivItem {
1577        #[primary_span]
1578        span: Span,
1579        #[note]
1580        vis_note: Span,
1581        vis_descr: &'a str,
1582    },
1583
1584    #[diag(passes_unexportable_adt_with_private_fields)]
1585    AdtWithPrivFields {
1586        #[primary_span]
1587        span: Span,
1588        #[note]
1589        vis_note: Span,
1590        field_name: &'a str,
1591    },
1592}
1593
1594#[derive(Diagnostic)]
1595#[diag(passes_repr_align_should_be_align)]
1596pub(crate) struct ReprAlignShouldBeAlign {
1597    #[primary_span]
1598    #[help]
1599    pub span: Span,
1600    pub item: &'static str,
1601}
1602
1603#[derive(Diagnostic)]
1604#[diag(passes_repr_align_should_be_align_static)]
1605pub(crate) struct ReprAlignShouldBeAlignStatic {
1606    #[primary_span]
1607    #[help]
1608    pub span: Span,
1609    pub item: &'static str,
1610}
1611
1612#[derive(Diagnostic)]
1613#[diag(passes_custom_mir_phase_requires_dialect)]
1614pub(crate) struct CustomMirPhaseRequiresDialect {
1615    #[primary_span]
1616    pub attr_span: Span,
1617    #[label]
1618    pub phase_span: Span,
1619}
1620
1621#[derive(Diagnostic)]
1622#[diag(passes_custom_mir_incompatible_dialect_and_phase)]
1623pub(crate) struct CustomMirIncompatibleDialectAndPhase {
1624    pub dialect: MirDialect,
1625    pub phase: MirPhase,
1626    #[primary_span]
1627    pub attr_span: Span,
1628    #[label]
1629    pub dialect_span: Span,
1630    #[label]
1631    pub phase_span: Span,
1632}