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