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_macros::{Diagnostic, LintDiagnostic, Subdiagnostic};
11use rustc_middle::ty::{MainDefinition, Ty};
12use rustc_span::{DUMMY_SP, Span, Symbol};
13
14use crate::check_attr::ProcMacroKind;
15use crate::fluent_generated as fluent;
16use crate::lang_items::Duplicate;
17
18#[derive(LintDiagnostic)]
19#[diag(passes_incorrect_do_not_recommend_location)]
20pub(crate) struct IncorrectDoNotRecommendLocation;
21
22#[derive(LintDiagnostic)]
23#[diag(passes_incorrect_do_not_recommend_args)]
24pub(crate) struct DoNotRecommendDoesNotExpectArgs;
25
26#[derive(Diagnostic)]
27#[diag(passes_autodiff_attr)]
28pub(crate) struct AutoDiffAttr {
29    #[primary_span]
30    #[label]
31    pub attr_span: Span,
32}
33
34#[derive(Diagnostic)]
35#[diag(passes_loop_match_attr)]
36pub(crate) struct LoopMatchAttr {
37    #[primary_span]
38    pub attr_span: Span,
39    #[label]
40    pub node_span: Span,
41}
42
43#[derive(Diagnostic)]
44#[diag(passes_const_continue_attr)]
45pub(crate) struct ConstContinueAttr {
46    #[primary_span]
47    pub attr_span: Span,
48    #[label]
49    pub node_span: Span,
50}
51
52#[derive(LintDiagnostic)]
53#[diag(passes_mixed_export_name_and_no_mangle)]
54pub(crate) struct MixedExportNameAndNoMangle {
55    #[label]
56    #[suggestion(style = "verbose", code = "", applicability = "machine-applicable")]
57    pub no_mangle_span: Span,
58    #[note]
59    pub export_name_span: Span,
60    pub no_mangle_attr: &'static str,
61    pub export_name_attr: &'static str,
62}
63
64#[derive(LintDiagnostic)]
65#[diag(passes_outer_crate_level_attr)]
66pub(crate) struct OuterCrateLevelAttr;
67
68#[derive(LintDiagnostic)]
69#[diag(passes_inner_crate_level_attr)]
70pub(crate) struct InnerCrateLevelAttr;
71
72#[derive(LintDiagnostic)]
73#[diag(passes_ignored_attr_with_macro)]
74pub(crate) struct IgnoredAttrWithMacro<'a> {
75    pub sym: &'a str,
76}
77
78#[derive(LintDiagnostic)]
79#[diag(passes_ignored_attr)]
80pub(crate) struct IgnoredAttr<'a> {
81    pub sym: &'a str,
82}
83
84#[derive(LintDiagnostic)]
85#[diag(passes_inline_ignored_function_prototype)]
86pub(crate) struct IgnoredInlineAttrFnProto;
87
88#[derive(LintDiagnostic)]
89#[diag(passes_inline_ignored_constants)]
90#[warning]
91#[note]
92pub(crate) struct IgnoredInlineAttrConstants;
93
94#[derive(Diagnostic)]
95#[diag(passes_inline_not_fn_or_closure, code = E0518)]
96pub(crate) struct InlineNotFnOrClosure {
97    #[primary_span]
98    pub attr_span: Span,
99    #[label]
100    pub defn_span: Span,
101}
102
103/// "coverage attribute not allowed here"
104#[derive(Diagnostic)]
105#[diag(passes_coverage_attribute_not_allowed, code = E0788)]
106pub(crate) struct CoverageAttributeNotAllowed {
107    #[primary_span]
108    pub attr_span: Span,
109    /// "not a function, impl block, or module"
110    #[label(passes_not_fn_impl_mod)]
111    pub not_fn_impl_mod: Option<Span>,
112    /// "function has no body"
113    #[label(passes_no_body)]
114    pub no_body: Option<Span>,
115    /// "coverage attribute can be applied to a function (with body), impl block, or module"
116    #[help]
117    pub help: (),
118}
119
120#[derive(Diagnostic)]
121#[diag(passes_optimize_invalid_target)]
122pub(crate) struct OptimizeInvalidTarget {
123    #[primary_span]
124    pub attr_span: Span,
125    #[label]
126    pub defn_span: Span,
127    pub on_crate: bool,
128}
129
130#[derive(Diagnostic)]
131#[diag(passes_should_be_applied_to_fn)]
132pub(crate) struct AttrShouldBeAppliedToFn {
133    #[primary_span]
134    pub attr_span: Span,
135    #[label]
136    pub defn_span: Span,
137    pub on_crate: bool,
138}
139
140#[derive(Diagnostic)]
141#[diag(passes_should_be_applied_to_fn, code = E0739)]
142pub(crate) struct TrackedCallerWrongLocation {
143    #[primary_span]
144    pub attr_span: Span,
145    #[label]
146    pub defn_span: Span,
147    pub on_crate: bool,
148}
149
150#[derive(Diagnostic)]
151#[diag(passes_should_be_applied_to_struct_enum, code = E0701)]
152pub(crate) struct NonExhaustiveWrongLocation {
153    #[primary_span]
154    pub attr_span: Span,
155    #[label]
156    pub defn_span: Span,
157}
158
159#[derive(Diagnostic)]
160#[diag(passes_non_exhaustive_with_default_field_values)]
161pub(crate) struct NonExhaustiveWithDefaultFieldValues {
162    #[primary_span]
163    pub attr_span: Span,
164    #[label]
165    pub defn_span: Span,
166}
167
168#[derive(Diagnostic)]
169#[diag(passes_should_be_applied_to_trait)]
170pub(crate) struct AttrShouldBeAppliedToTrait {
171    #[primary_span]
172    pub attr_span: Span,
173    #[label]
174    pub defn_span: Span,
175}
176
177#[derive(LintDiagnostic)]
178#[diag(passes_target_feature_on_statement)]
179pub(crate) struct TargetFeatureOnStatement;
180
181#[derive(Diagnostic)]
182#[diag(passes_should_be_applied_to_static)]
183pub(crate) struct AttrShouldBeAppliedToStatic {
184    #[primary_span]
185    pub attr_span: Span,
186    #[label]
187    pub defn_span: Span,
188}
189
190#[derive(Diagnostic)]
191#[diag(passes_doc_expect_str)]
192pub(crate) struct DocExpectStr<'a> {
193    #[primary_span]
194    pub attr_span: Span,
195    pub attr_name: &'a str,
196}
197
198#[derive(Diagnostic)]
199#[diag(passes_doc_alias_empty)]
200pub(crate) struct DocAliasEmpty<'a> {
201    #[primary_span]
202    pub span: Span,
203    pub attr_str: &'a str,
204}
205
206#[derive(Diagnostic)]
207#[diag(passes_doc_alias_bad_char)]
208pub(crate) struct DocAliasBadChar<'a> {
209    #[primary_span]
210    pub span: Span,
211    pub attr_str: &'a str,
212    pub char_: char,
213}
214
215#[derive(Diagnostic)]
216#[diag(passes_doc_alias_start_end)]
217pub(crate) struct DocAliasStartEnd<'a> {
218    #[primary_span]
219    pub span: Span,
220    pub attr_str: &'a str,
221}
222
223#[derive(Diagnostic)]
224#[diag(passes_doc_alias_bad_location)]
225pub(crate) struct DocAliasBadLocation<'a> {
226    #[primary_span]
227    pub span: Span,
228    pub attr_str: &'a str,
229    pub location: &'a str,
230}
231
232#[derive(Diagnostic)]
233#[diag(passes_doc_alias_not_an_alias)]
234pub(crate) struct DocAliasNotAnAlias<'a> {
235    #[primary_span]
236    pub span: Span,
237    pub attr_str: &'a str,
238}
239
240#[derive(LintDiagnostic)]
241#[diag(passes_doc_alias_duplicated)]
242pub(crate) struct DocAliasDuplicated {
243    #[label]
244    pub first_defn: Span,
245}
246
247#[derive(Diagnostic)]
248#[diag(passes_doc_alias_not_string_literal)]
249pub(crate) struct DocAliasNotStringLiteral {
250    #[primary_span]
251    pub span: Span,
252}
253
254#[derive(Diagnostic)]
255#[diag(passes_doc_alias_malformed)]
256pub(crate) struct DocAliasMalformed {
257    #[primary_span]
258    pub span: Span,
259}
260
261#[derive(Diagnostic)]
262#[diag(passes_doc_keyword_empty_mod)]
263pub(crate) struct DocKeywordEmptyMod {
264    #[primary_span]
265    pub span: Span,
266}
267
268#[derive(Diagnostic)]
269#[diag(passes_doc_keyword_not_keyword)]
270#[help]
271pub(crate) struct DocKeywordNotKeyword {
272    #[primary_span]
273    pub span: Span,
274    pub keyword: Symbol,
275}
276
277#[derive(Diagnostic)]
278#[diag(passes_doc_keyword_not_mod)]
279pub(crate) struct DocKeywordNotMod {
280    #[primary_span]
281    pub span: Span,
282}
283
284#[derive(Diagnostic)]
285#[diag(passes_doc_fake_variadic_not_valid)]
286pub(crate) struct DocFakeVariadicNotValid {
287    #[primary_span]
288    pub span: Span,
289}
290
291#[derive(Diagnostic)]
292#[diag(passes_doc_keyword_only_impl)]
293pub(crate) struct DocKeywordOnlyImpl {
294    #[primary_span]
295    pub span: Span,
296}
297
298#[derive(Diagnostic)]
299#[diag(passes_doc_search_unbox_invalid)]
300pub(crate) struct DocSearchUnboxInvalid {
301    #[primary_span]
302    pub span: Span,
303}
304
305#[derive(Diagnostic)]
306#[diag(passes_doc_inline_conflict)]
307#[help]
308pub(crate) struct DocKeywordConflict {
309    #[primary_span]
310    pub spans: MultiSpan,
311}
312
313#[derive(LintDiagnostic)]
314#[diag(passes_doc_inline_only_use)]
315#[note]
316pub(crate) struct DocInlineOnlyUse {
317    #[label]
318    pub attr_span: Span,
319    #[label(passes_not_a_use_item_label)]
320    pub item_span: Option<Span>,
321}
322
323#[derive(LintDiagnostic)]
324#[diag(passes_doc_masked_only_extern_crate)]
325#[note]
326pub(crate) struct DocMaskedOnlyExternCrate {
327    #[label]
328    pub attr_span: Span,
329    #[label(passes_not_an_extern_crate_label)]
330    pub item_span: Option<Span>,
331}
332
333#[derive(LintDiagnostic)]
334#[diag(passes_doc_masked_not_extern_crate_self)]
335pub(crate) struct DocMaskedNotExternCrateSelf {
336    #[label]
337    pub attr_span: Span,
338    #[label(passes_extern_crate_self_label)]
339    pub item_span: Option<Span>,
340}
341
342#[derive(Diagnostic)]
343#[diag(passes_doc_attr_not_crate_level)]
344pub(crate) struct DocAttrNotCrateLevel<'a> {
345    #[primary_span]
346    pub span: Span,
347    pub attr_name: &'a str,
348}
349
350#[derive(LintDiagnostic)]
351#[diag(passes_doc_test_unknown)]
352pub(crate) struct DocTestUnknown {
353    pub path: String,
354}
355
356#[derive(LintDiagnostic)]
357#[diag(passes_doc_test_literal)]
358pub(crate) struct DocTestLiteral;
359
360#[derive(LintDiagnostic)]
361#[diag(passes_doc_test_takes_list)]
362pub(crate) struct DocTestTakesList;
363
364#[derive(LintDiagnostic)]
365#[diag(passes_doc_cfg_hide_takes_list)]
366pub(crate) struct DocCfgHideTakesList;
367
368#[derive(LintDiagnostic)]
369#[diag(passes_doc_test_unknown_any)]
370pub(crate) struct DocTestUnknownAny {
371    pub path: String,
372}
373
374#[derive(LintDiagnostic)]
375#[diag(passes_doc_test_unknown_spotlight)]
376#[note]
377#[note(passes_no_op_note)]
378pub(crate) struct DocTestUnknownSpotlight {
379    pub path: String,
380    #[suggestion(style = "short", applicability = "machine-applicable", code = "notable_trait")]
381    pub span: Span,
382}
383
384#[derive(LintDiagnostic)]
385#[diag(passes_doc_test_unknown_passes)]
386#[note]
387#[help]
388#[note(passes_no_op_note)]
389pub(crate) struct DocTestUnknownPasses {
390    pub path: String,
391    #[label]
392    pub span: Span,
393}
394
395#[derive(LintDiagnostic)]
396#[diag(passes_doc_test_unknown_plugins)]
397#[note]
398#[note(passes_no_op_note)]
399pub(crate) struct DocTestUnknownPlugins {
400    pub path: String,
401    #[label]
402    pub span: Span,
403}
404
405#[derive(LintDiagnostic)]
406#[diag(passes_doc_test_unknown_include)]
407pub(crate) struct DocTestUnknownInclude {
408    pub path: String,
409    pub value: String,
410    pub inner: &'static str,
411    #[suggestion(code = "#{inner}[doc = include_str!(\"{value}\")]")]
412    pub sugg: (Span, Applicability),
413}
414
415#[derive(LintDiagnostic)]
416#[diag(passes_doc_invalid)]
417pub(crate) struct DocInvalid;
418
419#[derive(Diagnostic)]
420#[diag(passes_pass_by_value)]
421pub(crate) struct PassByValue {
422    #[primary_span]
423    pub attr_span: Span,
424    #[label]
425    pub span: Span,
426}
427
428#[derive(Diagnostic)]
429#[diag(passes_allow_incoherent_impl)]
430pub(crate) struct AllowIncoherentImpl {
431    #[primary_span]
432    pub attr_span: Span,
433    #[label]
434    pub span: Span,
435}
436
437#[derive(Diagnostic)]
438#[diag(passes_has_incoherent_inherent_impl)]
439pub(crate) struct HasIncoherentInherentImpl {
440    #[primary_span]
441    pub attr_span: Span,
442    #[label]
443    pub span: Span,
444}
445
446#[derive(Diagnostic)]
447#[diag(passes_both_ffi_const_and_pure, code = E0757)]
448pub(crate) struct BothFfiConstAndPure {
449    #[primary_span]
450    pub attr_span: Span,
451}
452
453#[derive(Diagnostic)]
454#[diag(passes_ffi_pure_invalid_target, code = E0755)]
455pub(crate) struct FfiPureInvalidTarget {
456    #[primary_span]
457    pub attr_span: Span,
458}
459
460#[derive(Diagnostic)]
461#[diag(passes_ffi_const_invalid_target, code = E0756)]
462pub(crate) struct FfiConstInvalidTarget {
463    #[primary_span]
464    pub attr_span: Span,
465}
466
467#[derive(LintDiagnostic)]
468#[diag(passes_must_use_no_effect)]
469pub(crate) struct MustUseNoEffect {
470    pub article: &'static str,
471    pub target: rustc_hir::Target,
472}
473
474#[derive(Diagnostic)]
475#[diag(passes_must_not_suspend)]
476pub(crate) struct MustNotSuspend {
477    #[primary_span]
478    pub attr_span: Span,
479    #[label]
480    pub span: Span,
481}
482
483#[derive(LintDiagnostic)]
484#[diag(passes_cold)]
485#[warning]
486pub(crate) struct Cold {
487    #[label]
488    pub span: Span,
489    pub on_crate: bool,
490}
491
492#[derive(LintDiagnostic)]
493#[diag(passes_link)]
494#[warning]
495pub(crate) struct Link {
496    #[label]
497    pub span: Option<Span>,
498}
499
500#[derive(LintDiagnostic)]
501#[diag(passes_link_name)]
502#[warning]
503pub(crate) struct LinkName<'a> {
504    #[help]
505    pub help_span: Option<Span>,
506    #[label]
507    pub span: Span,
508    pub value: &'a str,
509}
510
511#[derive(Diagnostic)]
512#[diag(passes_no_link)]
513pub(crate) struct NoLink {
514    #[primary_span]
515    pub attr_span: Span,
516    #[label]
517    pub span: Span,
518}
519
520#[derive(Diagnostic)]
521#[diag(passes_export_name)]
522pub(crate) struct ExportName {
523    #[primary_span]
524    pub attr_span: Span,
525    #[label]
526    pub span: Span,
527}
528
529#[derive(Diagnostic)]
530#[diag(passes_rustc_layout_scalar_valid_range_not_struct)]
531pub(crate) struct RustcLayoutScalarValidRangeNotStruct {
532    #[primary_span]
533    pub attr_span: Span,
534    #[label]
535    pub span: Span,
536}
537
538#[derive(Diagnostic)]
539#[diag(passes_rustc_legacy_const_generics_only)]
540pub(crate) struct RustcLegacyConstGenericsOnly {
541    #[primary_span]
542    pub attr_span: Span,
543    #[label]
544    pub param_span: Span,
545}
546
547#[derive(Diagnostic)]
548#[diag(passes_rustc_legacy_const_generics_index)]
549pub(crate) struct RustcLegacyConstGenericsIndex {
550    #[primary_span]
551    pub attr_span: Span,
552    #[label]
553    pub generics_span: Span,
554}
555
556#[derive(Diagnostic)]
557#[diag(passes_rustc_legacy_const_generics_index_exceed)]
558pub(crate) struct RustcLegacyConstGenericsIndexExceed {
559    #[primary_span]
560    #[label]
561    pub span: Span,
562    pub arg_count: usize,
563}
564
565#[derive(Diagnostic)]
566#[diag(passes_rustc_legacy_const_generics_index_negative)]
567pub(crate) struct RustcLegacyConstGenericsIndexNegative {
568    #[primary_span]
569    pub invalid_args: Vec<Span>,
570}
571
572#[derive(Diagnostic)]
573#[diag(passes_rustc_dirty_clean)]
574pub(crate) struct RustcDirtyClean {
575    #[primary_span]
576    pub span: Span,
577}
578
579#[derive(LintDiagnostic)]
580#[diag(passes_link_section)]
581#[warning]
582pub(crate) struct LinkSection {
583    #[label]
584    pub span: Span,
585}
586
587#[derive(LintDiagnostic)]
588#[diag(passes_no_mangle_foreign)]
589#[warning]
590#[note]
591pub(crate) struct NoMangleForeign {
592    #[label]
593    pub span: Span,
594    #[suggestion(code = "", applicability = "machine-applicable")]
595    pub attr_span: Span,
596    pub foreign_item_kind: &'static str,
597}
598
599#[derive(LintDiagnostic)]
600#[diag(passes_no_mangle)]
601#[warning]
602pub(crate) struct NoMangle {
603    #[label]
604    pub span: Span,
605}
606
607#[derive(LintDiagnostic)]
608#[diag(passes_align_on_fields)]
609#[warning]
610pub(crate) struct AlignOnFields {
611    #[label]
612    pub span: Span,
613}
614
615#[derive(Diagnostic)]
616#[diag(passes_repr_conflicting, code = E0566)]
617pub(crate) struct ReprConflicting {
618    #[primary_span]
619    pub hint_spans: Vec<Span>,
620}
621
622#[derive(Diagnostic)]
623#[diag(passes_repr_align_greater_than_target_max, code = E0589)]
624#[note]
625pub(crate) struct InvalidReprAlignForTarget {
626    #[primary_span]
627    pub span: Span,
628    pub size: u64,
629}
630
631#[derive(LintDiagnostic)]
632#[diag(passes_repr_conflicting, code = E0566)]
633pub(crate) struct ReprConflictingLint;
634
635#[derive(Diagnostic)]
636#[diag(passes_used_static)]
637pub(crate) struct UsedStatic {
638    #[primary_span]
639    pub attr_span: Span,
640    #[label]
641    pub span: Span,
642    pub target: &'static str,
643}
644
645#[derive(Diagnostic)]
646#[diag(passes_allow_internal_unstable)]
647pub(crate) struct AllowInternalUnstable {
648    #[primary_span]
649    pub attr_span: Span,
650    #[label]
651    pub span: Span,
652}
653
654#[derive(Diagnostic)]
655#[diag(passes_debug_visualizer_placement)]
656pub(crate) struct DebugVisualizerPlacement {
657    #[primary_span]
658    pub span: Span,
659}
660
661#[derive(Diagnostic)]
662#[diag(passes_debug_visualizer_invalid)]
663#[note(passes_note_1)]
664#[note(passes_note_2)]
665#[note(passes_note_3)]
666pub(crate) struct DebugVisualizerInvalid {
667    #[primary_span]
668    pub span: Span,
669}
670
671#[derive(Diagnostic)]
672#[diag(passes_debug_visualizer_unreadable)]
673pub(crate) struct DebugVisualizerUnreadable<'a> {
674    #[primary_span]
675    pub span: Span,
676    pub file: &'a Path,
677    pub error: Error,
678}
679
680#[derive(Diagnostic)]
681#[diag(passes_rustc_allow_const_fn_unstable)]
682pub(crate) struct RustcAllowConstFnUnstable {
683    #[primary_span]
684    pub attr_span: Span,
685    #[label]
686    pub span: Span,
687}
688
689#[derive(Diagnostic)]
690#[diag(passes_rustc_unstable_feature_bound)]
691pub(crate) struct RustcUnstableFeatureBound {
692    #[primary_span]
693    pub attr_span: Span,
694    #[label]
695    pub span: Span,
696}
697
698#[derive(Diagnostic)]
699#[diag(passes_rustc_std_internal_symbol)]
700pub(crate) struct RustcStdInternalSymbol {
701    #[primary_span]
702    pub attr_span: Span,
703    #[label]
704    pub span: Span,
705}
706
707#[derive(Diagnostic)]
708#[diag(passes_rustc_pub_transparent)]
709pub(crate) struct RustcPubTransparent {
710    #[primary_span]
711    pub attr_span: Span,
712    #[label]
713    pub span: Span,
714}
715
716#[derive(Diagnostic)]
717#[diag(passes_rustc_force_inline)]
718pub(crate) struct RustcForceInline {
719    #[primary_span]
720    pub attr_span: Span,
721    #[label]
722    pub span: Span,
723}
724
725#[derive(Diagnostic)]
726#[diag(passes_rustc_force_inline_coro)]
727pub(crate) struct RustcForceInlineCoro {
728    #[primary_span]
729    pub attr_span: Span,
730    #[label]
731    pub span: Span,
732}
733
734#[derive(Diagnostic)]
735#[diag(passes_link_ordinal)]
736pub(crate) struct LinkOrdinal {
737    #[primary_span]
738    pub attr_span: Span,
739}
740
741#[derive(Diagnostic)]
742#[diag(passes_confusables)]
743pub(crate) struct Confusables {
744    #[primary_span]
745    pub attr_span: Span,
746}
747
748#[derive(Diagnostic)]
749#[diag(passes_coroutine_on_non_closure)]
750pub(crate) struct CoroutineOnNonClosure {
751    #[primary_span]
752    pub span: Span,
753}
754
755#[derive(Diagnostic)]
756#[diag(passes_linkage)]
757pub(crate) struct Linkage {
758    #[primary_span]
759    pub attr_span: Span,
760    #[label]
761    pub span: Span,
762}
763
764#[derive(Diagnostic)]
765#[diag(passes_stability_promotable)]
766pub(crate) struct StabilityPromotable {
767    #[primary_span]
768    pub attr_span: Span,
769}
770
771#[derive(LintDiagnostic)]
772#[diag(passes_deprecated)]
773pub(crate) struct Deprecated;
774
775#[derive(LintDiagnostic)]
776#[diag(passes_macro_use)]
777pub(crate) struct MacroUse {
778    pub name: Symbol,
779}
780
781#[derive(LintDiagnostic)]
782pub(crate) enum MacroExport {
783    #[diag(passes_macro_export)]
784    Normal,
785
786    #[diag(passes_macro_export_on_decl_macro)]
787    #[note]
788    OnDeclMacro,
789
790    #[diag(passes_invalid_macro_export_arguments)]
791    InvalidArgument,
792
793    #[diag(passes_invalid_macro_export_arguments_too_many_items)]
794    TooManyItems,
795}
796
797#[derive(Subdiagnostic)]
798pub(crate) enum UnusedNote {
799    #[note(passes_unused_empty_lints_note)]
800    EmptyList { name: Symbol },
801    #[note(passes_unused_no_lints_note)]
802    NoLints { name: Symbol },
803    #[note(passes_unused_default_method_body_const_note)]
804    DefaultMethodBodyConst,
805    #[note(passes_unused_linker_messages_note)]
806    LinkerMessagesBinaryCrateOnly,
807}
808
809#[derive(LintDiagnostic)]
810#[diag(passes_unused)]
811pub(crate) struct Unused {
812    #[suggestion(code = "", applicability = "machine-applicable")]
813    pub attr_span: Span,
814    #[subdiagnostic]
815    pub note: UnusedNote,
816}
817
818#[derive(Diagnostic)]
819#[diag(passes_non_exported_macro_invalid_attrs, code = E0518)]
820pub(crate) struct NonExportedMacroInvalidAttrs {
821    #[primary_span]
822    #[label]
823    pub attr_span: Span,
824}
825
826#[derive(Diagnostic)]
827#[diag(passes_may_dangle)]
828pub(crate) struct InvalidMayDangle {
829    #[primary_span]
830    pub attr_span: Span,
831}
832
833#[derive(LintDiagnostic)]
834#[diag(passes_unused_duplicate)]
835pub(crate) struct UnusedDuplicate {
836    #[suggestion(code = "", applicability = "machine-applicable")]
837    pub this: Span,
838    #[note]
839    pub other: Span,
840    #[warning]
841    pub warning: bool,
842}
843
844#[derive(Diagnostic)]
845#[diag(passes_unused_multiple)]
846pub(crate) struct UnusedMultiple {
847    #[primary_span]
848    #[suggestion(code = "", applicability = "machine-applicable")]
849    pub this: Span,
850    #[note]
851    pub other: Span,
852    pub name: Symbol,
853}
854
855#[derive(Diagnostic)]
856#[diag(passes_rustc_lint_opt_ty)]
857pub(crate) struct RustcLintOptTy {
858    #[primary_span]
859    pub attr_span: Span,
860    #[label]
861    pub span: Span,
862}
863
864#[derive(Diagnostic)]
865#[diag(passes_rustc_lint_opt_deny_field_access)]
866pub(crate) struct RustcLintOptDenyFieldAccess {
867    #[primary_span]
868    pub attr_span: Span,
869    #[label]
870    pub span: Span,
871}
872
873#[derive(Diagnostic)]
874#[diag(passes_collapse_debuginfo)]
875pub(crate) struct CollapseDebuginfo {
876    #[primary_span]
877    pub attr_span: Span,
878    #[label]
879    pub defn_span: Span,
880}
881
882#[derive(LintDiagnostic)]
883#[diag(passes_deprecated_annotation_has_no_effect)]
884pub(crate) struct DeprecatedAnnotationHasNoEffect {
885    #[suggestion(applicability = "machine-applicable", code = "")]
886    pub span: Span,
887}
888
889#[derive(Diagnostic)]
890#[diag(passes_unknown_external_lang_item, code = E0264)]
891pub(crate) struct UnknownExternLangItem {
892    #[primary_span]
893    pub span: Span,
894    pub lang_item: Symbol,
895}
896
897#[derive(Diagnostic)]
898#[diag(passes_missing_panic_handler)]
899pub(crate) struct MissingPanicHandler;
900
901#[derive(Diagnostic)]
902#[diag(passes_panic_unwind_without_std)]
903#[help]
904#[note]
905pub(crate) struct PanicUnwindWithoutStd;
906
907#[derive(Diagnostic)]
908#[diag(passes_missing_lang_item)]
909#[note]
910#[help]
911pub(crate) struct MissingLangItem {
912    pub name: Symbol,
913}
914
915#[derive(Diagnostic)]
916#[diag(passes_lang_item_fn_with_track_caller)]
917pub(crate) struct LangItemWithTrackCaller {
918    #[primary_span]
919    pub attr_span: Span,
920    pub name: Symbol,
921    #[label]
922    pub sig_span: Span,
923}
924
925#[derive(Diagnostic)]
926#[diag(passes_lang_item_fn_with_target_feature)]
927pub(crate) struct LangItemWithTargetFeature {
928    #[primary_span]
929    pub attr_span: Span,
930    pub name: Symbol,
931    #[label]
932    pub sig_span: Span,
933}
934
935#[derive(Diagnostic)]
936#[diag(passes_lang_item_on_incorrect_target, code = E0718)]
937pub(crate) struct LangItemOnIncorrectTarget {
938    #[primary_span]
939    #[label]
940    pub span: Span,
941    pub name: Symbol,
942    pub expected_target: Target,
943    pub actual_target: Target,
944}
945
946#[derive(Diagnostic)]
947#[diag(passes_unknown_lang_item, code = E0522)]
948pub(crate) struct UnknownLangItem {
949    #[primary_span]
950    #[label]
951    pub span: Span,
952    pub name: Symbol,
953}
954
955pub(crate) struct InvalidAttrAtCrateLevel {
956    pub span: Span,
957    pub sugg_span: Option<Span>,
958    pub name: Symbol,
959    pub item: Option<ItemFollowingInnerAttr>,
960}
961
962#[derive(Clone, Copy)]
963pub(crate) struct ItemFollowingInnerAttr {
964    pub span: Span,
965    pub kind: &'static str,
966}
967
968impl<G: EmissionGuarantee> Diagnostic<'_, G> for InvalidAttrAtCrateLevel {
969    #[track_caller]
970    fn into_diag(self, dcx: DiagCtxtHandle<'_>, level: Level) -> Diag<'_, G> {
971        let mut diag = Diag::new(dcx, level, fluent::passes_invalid_attr_at_crate_level);
972        diag.span(self.span);
973        diag.arg("name", self.name);
974        // Only emit an error with a suggestion if we can create a string out
975        // of the attribute span
976        if let Some(span) = self.sugg_span {
977            diag.span_suggestion_verbose(
978                span,
979                fluent::passes_suggestion,
980                String::new(),
981                Applicability::MachineApplicable,
982            );
983        }
984        if let Some(item) = self.item {
985            diag.arg("kind", item.kind);
986            diag.span_label(item.span, fluent::passes_invalid_attr_at_crate_level_item);
987        }
988        diag
989    }
990}
991
992#[derive(Diagnostic)]
993#[diag(passes_duplicate_diagnostic_item_in_crate)]
994pub(crate) struct DuplicateDiagnosticItemInCrate {
995    #[primary_span]
996    pub duplicate_span: Option<Span>,
997    #[note(passes_diagnostic_item_first_defined)]
998    pub orig_span: Option<Span>,
999    #[note]
1000    pub different_crates: bool,
1001    pub crate_name: Symbol,
1002    pub orig_crate_name: Symbol,
1003    pub name: Symbol,
1004}
1005
1006#[derive(Diagnostic)]
1007#[diag(passes_layout_abi)]
1008pub(crate) struct LayoutAbi {
1009    #[primary_span]
1010    pub span: Span,
1011    pub abi: String,
1012}
1013
1014#[derive(Diagnostic)]
1015#[diag(passes_layout_align)]
1016pub(crate) struct LayoutAlign {
1017    #[primary_span]
1018    pub span: Span,
1019    pub align: String,
1020}
1021
1022#[derive(Diagnostic)]
1023#[diag(passes_layout_size)]
1024pub(crate) struct LayoutSize {
1025    #[primary_span]
1026    pub span: Span,
1027    pub size: String,
1028}
1029
1030#[derive(Diagnostic)]
1031#[diag(passes_layout_homogeneous_aggregate)]
1032pub(crate) struct LayoutHomogeneousAggregate {
1033    #[primary_span]
1034    pub span: Span,
1035    pub homogeneous_aggregate: String,
1036}
1037
1038#[derive(Diagnostic)]
1039#[diag(passes_layout_of)]
1040pub(crate) struct LayoutOf<'tcx> {
1041    #[primary_span]
1042    pub span: Span,
1043    pub normalized_ty: Ty<'tcx>,
1044    pub ty_layout: String,
1045}
1046
1047#[derive(Diagnostic)]
1048#[diag(passes_layout_invalid_attribute)]
1049pub(crate) struct LayoutInvalidAttribute {
1050    #[primary_span]
1051    pub span: Span,
1052}
1053
1054#[derive(Diagnostic)]
1055#[diag(passes_abi_of)]
1056pub(crate) struct AbiOf {
1057    #[primary_span]
1058    pub span: Span,
1059    pub fn_name: Symbol,
1060    pub fn_abi: String,
1061}
1062
1063#[derive(Diagnostic)]
1064#[diag(passes_abi_ne)]
1065pub(crate) struct AbiNe {
1066    #[primary_span]
1067    pub span: Span,
1068    pub left: String,
1069    pub right: String,
1070}
1071
1072#[derive(Diagnostic)]
1073#[diag(passes_abi_invalid_attribute)]
1074pub(crate) struct AbiInvalidAttribute {
1075    #[primary_span]
1076    pub span: Span,
1077}
1078
1079#[derive(Diagnostic)]
1080#[diag(passes_unrecognized_argument)]
1081pub(crate) struct UnrecognizedArgument {
1082    #[primary_span]
1083    pub span: Span,
1084}
1085
1086#[derive(Diagnostic)]
1087#[diag(passes_feature_stable_twice, code = E0711)]
1088pub(crate) struct FeatureStableTwice {
1089    #[primary_span]
1090    pub span: Span,
1091    pub feature: Symbol,
1092    pub since: Symbol,
1093    pub prev_since: Symbol,
1094}
1095
1096#[derive(Diagnostic)]
1097#[diag(passes_feature_previously_declared, code = E0711)]
1098pub(crate) struct FeaturePreviouslyDeclared<'a> {
1099    #[primary_span]
1100    pub span: Span,
1101    pub feature: Symbol,
1102    pub declared: &'a str,
1103    pub prev_declared: &'a str,
1104}
1105
1106#[derive(Diagnostic)]
1107#[diag(passes_attr_only_in_functions)]
1108pub(crate) struct AttrOnlyInFunctions {
1109    #[primary_span]
1110    pub span: Span,
1111    pub attr: Symbol,
1112}
1113
1114#[derive(Diagnostic)]
1115#[diag(passes_multiple_rustc_main, code = E0137)]
1116pub(crate) struct MultipleRustcMain {
1117    #[primary_span]
1118    pub span: Span,
1119    #[label(passes_first)]
1120    pub first: Span,
1121    #[label(passes_additional)]
1122    pub additional: Span,
1123}
1124
1125#[derive(Diagnostic)]
1126#[diag(passes_extern_main)]
1127pub(crate) struct ExternMain {
1128    #[primary_span]
1129    pub span: Span,
1130}
1131
1132pub(crate) struct NoMainErr {
1133    pub sp: Span,
1134    pub crate_name: Symbol,
1135    pub has_filename: bool,
1136    pub filename: PathBuf,
1137    pub file_empty: bool,
1138    pub non_main_fns: Vec<Span>,
1139    pub main_def_opt: Option<MainDefinition>,
1140    pub add_teach_note: bool,
1141}
1142
1143impl<'a, G: EmissionGuarantee> Diagnostic<'a, G> for NoMainErr {
1144    #[track_caller]
1145    fn into_diag(self, dcx: DiagCtxtHandle<'a>, level: Level) -> Diag<'a, G> {
1146        let mut diag = Diag::new(dcx, level, fluent::passes_no_main_function);
1147        diag.span(DUMMY_SP);
1148        diag.code(E0601);
1149        diag.arg("crate_name", self.crate_name);
1150        diag.arg("filename", self.filename);
1151        diag.arg("has_filename", self.has_filename);
1152        let note = if !self.non_main_fns.is_empty() {
1153            for &span in &self.non_main_fns {
1154                diag.span_note(span, fluent::passes_here_is_main);
1155            }
1156            diag.note(fluent::passes_one_or_more_possible_main);
1157            diag.help(fluent::passes_consider_moving_main);
1158            // There were some functions named `main` though. Try to give the user a hint.
1159            fluent::passes_main_must_be_defined_at_crate
1160        } else if self.has_filename {
1161            fluent::passes_consider_adding_main_to_file
1162        } else {
1163            fluent::passes_consider_adding_main_at_crate
1164        };
1165        if self.file_empty {
1166            diag.note(note);
1167        } else {
1168            diag.span(self.sp.shrink_to_hi());
1169            diag.span_label(self.sp.shrink_to_hi(), note);
1170        }
1171
1172        if let Some(main_def) = self.main_def_opt
1173            && main_def.opt_fn_def_id().is_none()
1174        {
1175            // There is something at `crate::main`, but it is not a function definition.
1176            diag.span_label(main_def.span, fluent::passes_non_function_main);
1177        }
1178
1179        if self.add_teach_note {
1180            diag.note(fluent::passes_teach_note);
1181        }
1182        diag
1183    }
1184}
1185
1186pub(crate) struct DuplicateLangItem {
1187    pub local_span: Option<Span>,
1188    pub lang_item_name: Symbol,
1189    pub crate_name: Symbol,
1190    pub dependency_of: Option<Symbol>,
1191    pub is_local: bool,
1192    pub path: String,
1193    pub first_defined_span: Option<Span>,
1194    pub orig_crate_name: Option<Symbol>,
1195    pub orig_dependency_of: Option<Symbol>,
1196    pub orig_is_local: bool,
1197    pub orig_path: String,
1198    pub(crate) duplicate: Duplicate,
1199}
1200
1201impl<G: EmissionGuarantee> Diagnostic<'_, G> for DuplicateLangItem {
1202    #[track_caller]
1203    fn into_diag(self, dcx: DiagCtxtHandle<'_>, level: Level) -> Diag<'_, G> {
1204        let mut diag = Diag::new(
1205            dcx,
1206            level,
1207            match self.duplicate {
1208                Duplicate::Plain => fluent::passes_duplicate_lang_item,
1209                Duplicate::Crate => fluent::passes_duplicate_lang_item_crate,
1210                Duplicate::CrateDepends => fluent::passes_duplicate_lang_item_crate_depends,
1211            },
1212        );
1213        diag.code(E0152);
1214        diag.arg("lang_item_name", self.lang_item_name);
1215        diag.arg("crate_name", self.crate_name);
1216        if let Some(dependency_of) = self.dependency_of {
1217            diag.arg("dependency_of", dependency_of);
1218        }
1219        diag.arg("path", self.path);
1220        if let Some(orig_crate_name) = self.orig_crate_name {
1221            diag.arg("orig_crate_name", orig_crate_name);
1222        }
1223        if let Some(orig_dependency_of) = self.orig_dependency_of {
1224            diag.arg("orig_dependency_of", orig_dependency_of);
1225        }
1226        diag.arg("orig_path", self.orig_path);
1227        if let Some(span) = self.local_span {
1228            diag.span(span);
1229        }
1230        if let Some(span) = self.first_defined_span {
1231            diag.span_note(span, fluent::passes_first_defined_span);
1232        } else {
1233            if self.orig_dependency_of.is_none() {
1234                diag.note(fluent::passes_first_defined_crate);
1235            } else {
1236                diag.note(fluent::passes_first_defined_crate_depends);
1237            }
1238
1239            if self.orig_is_local {
1240                diag.note(fluent::passes_first_definition_local);
1241            } else {
1242                diag.note(fluent::passes_first_definition_path);
1243            }
1244
1245            if self.is_local {
1246                diag.note(fluent::passes_second_definition_local);
1247            } else {
1248                diag.note(fluent::passes_second_definition_path);
1249            }
1250        }
1251        diag
1252    }
1253}
1254
1255#[derive(Diagnostic)]
1256#[diag(passes_incorrect_target, code = E0718)]
1257pub(crate) struct IncorrectTarget<'a> {
1258    #[primary_span]
1259    pub span: Span,
1260    #[label]
1261    pub generics_span: Span,
1262    pub name: &'a str, // cannot be symbol because it renders e.g. `r#fn` instead of `fn`
1263    pub kind: &'static str,
1264    pub num: usize,
1265    pub actual_num: usize,
1266    pub at_least: bool,
1267}
1268
1269#[derive(Diagnostic)]
1270#[diag(passes_incorrect_crate_type)]
1271pub(crate) struct IncorrectCrateType {
1272    #[primary_span]
1273    pub span: Span,
1274}
1275
1276#[derive(LintDiagnostic)]
1277#[diag(passes_useless_assignment)]
1278pub(crate) struct UselessAssignment<'a> {
1279    pub is_field_assign: bool,
1280    pub ty: Ty<'a>,
1281}
1282
1283#[derive(LintDiagnostic)]
1284#[diag(passes_only_has_effect_on)]
1285pub(crate) struct OnlyHasEffectOn {
1286    pub attr_name: String,
1287    pub target_name: String,
1288}
1289
1290#[derive(LintDiagnostic)]
1291#[diag(passes_inline_ignored_for_exported)]
1292#[help]
1293pub(crate) struct InlineIgnoredForExported {}
1294
1295#[derive(Diagnostic)]
1296#[diag(passes_object_lifetime_err)]
1297pub(crate) struct ObjectLifetimeErr {
1298    #[primary_span]
1299    pub span: Span,
1300    pub repr: String,
1301}
1302
1303#[derive(Diagnostic)]
1304pub(crate) enum AttrApplication {
1305    #[diag(passes_attr_application_enum, code = E0517)]
1306    Enum {
1307        #[primary_span]
1308        hint_span: Span,
1309        #[label]
1310        span: Span,
1311    },
1312    #[diag(passes_attr_application_struct, code = E0517)]
1313    Struct {
1314        #[primary_span]
1315        hint_span: Span,
1316        #[label]
1317        span: Span,
1318    },
1319    #[diag(passes_attr_application_struct_union, code = E0517)]
1320    StructUnion {
1321        #[primary_span]
1322        hint_span: Span,
1323        #[label]
1324        span: Span,
1325    },
1326    #[diag(passes_attr_application_struct_enum_union, code = E0517)]
1327    StructEnumUnion {
1328        #[primary_span]
1329        hint_span: Span,
1330        #[label]
1331        span: Span,
1332    },
1333}
1334
1335#[derive(Diagnostic)]
1336#[diag(passes_transparent_incompatible, code = E0692)]
1337pub(crate) struct TransparentIncompatible {
1338    #[primary_span]
1339    pub hint_spans: Vec<Span>,
1340    pub target: String,
1341}
1342
1343#[derive(Diagnostic)]
1344#[diag(passes_deprecated_attribute, code = E0549)]
1345pub(crate) struct DeprecatedAttribute {
1346    #[primary_span]
1347    pub span: Span,
1348}
1349
1350#[derive(Diagnostic)]
1351#[diag(passes_useless_stability)]
1352pub(crate) struct UselessStability {
1353    #[primary_span]
1354    #[label]
1355    pub span: Span,
1356    #[label(passes_item)]
1357    pub item_sp: Span,
1358}
1359
1360#[derive(Diagnostic)]
1361#[diag(passes_cannot_stabilize_deprecated)]
1362pub(crate) struct CannotStabilizeDeprecated {
1363    #[primary_span]
1364    #[label]
1365    pub span: Span,
1366    #[label(passes_item)]
1367    pub item_sp: Span,
1368}
1369
1370#[derive(Diagnostic)]
1371#[diag(passes_unstable_attr_for_already_stable_feature)]
1372pub(crate) struct UnstableAttrForAlreadyStableFeature {
1373    #[primary_span]
1374    #[label]
1375    #[help]
1376    pub attr_span: Span,
1377    #[label(passes_item)]
1378    pub item_span: Span,
1379}
1380
1381#[derive(Diagnostic)]
1382#[diag(passes_missing_stability_attr)]
1383pub(crate) struct MissingStabilityAttr<'a> {
1384    #[primary_span]
1385    pub span: Span,
1386    pub descr: &'a str,
1387}
1388
1389#[derive(Diagnostic)]
1390#[diag(passes_missing_const_stab_attr)]
1391pub(crate) struct MissingConstStabAttr<'a> {
1392    #[primary_span]
1393    pub span: Span,
1394    pub descr: &'a str,
1395}
1396
1397#[derive(Diagnostic)]
1398#[diag(passes_trait_impl_const_stable)]
1399#[note]
1400pub(crate) struct TraitImplConstStable {
1401    #[primary_span]
1402    pub span: Span,
1403}
1404
1405#[derive(Diagnostic)]
1406#[diag(passes_trait_impl_const_stability_mismatch)]
1407pub(crate) struct TraitImplConstStabilityMismatch {
1408    #[primary_span]
1409    pub span: Span,
1410    #[subdiagnostic]
1411    pub impl_stability: ImplConstStability,
1412    #[subdiagnostic]
1413    pub trait_stability: TraitConstStability,
1414}
1415
1416#[derive(Subdiagnostic)]
1417pub(crate) enum TraitConstStability {
1418    #[note(passes_trait_impl_const_stability_mismatch_trait_stable)]
1419    Stable {
1420        #[primary_span]
1421        span: Span,
1422    },
1423    #[note(passes_trait_impl_const_stability_mismatch_trait_unstable)]
1424    Unstable {
1425        #[primary_span]
1426        span: Span,
1427    },
1428}
1429
1430#[derive(Subdiagnostic)]
1431pub(crate) enum ImplConstStability {
1432    #[note(passes_trait_impl_const_stability_mismatch_impl_stable)]
1433    Stable {
1434        #[primary_span]
1435        span: Span,
1436    },
1437    #[note(passes_trait_impl_const_stability_mismatch_impl_unstable)]
1438    Unstable {
1439        #[primary_span]
1440        span: Span,
1441    },
1442}
1443
1444#[derive(Diagnostic)]
1445#[diag(passes_unknown_feature, code = E0635)]
1446pub(crate) struct UnknownFeature {
1447    #[primary_span]
1448    pub span: Span,
1449    pub feature: Symbol,
1450}
1451
1452#[derive(Diagnostic)]
1453#[diag(passes_unknown_feature_alias, code = E0635)]
1454pub(crate) struct RenamedFeature {
1455    #[primary_span]
1456    pub span: Span,
1457    pub feature: Symbol,
1458    pub alias: Symbol,
1459}
1460
1461#[derive(Diagnostic)]
1462#[diag(passes_implied_feature_not_exist)]
1463pub(crate) struct ImpliedFeatureNotExist {
1464    #[primary_span]
1465    pub span: Span,
1466    pub feature: Symbol,
1467    pub implied_by: Symbol,
1468}
1469
1470#[derive(Diagnostic)]
1471#[diag(passes_duplicate_feature_err, code = E0636)]
1472pub(crate) struct DuplicateFeatureErr {
1473    #[primary_span]
1474    pub span: Span,
1475    pub feature: Symbol,
1476}
1477
1478#[derive(Diagnostic)]
1479#[diag(passes_missing_const_err)]
1480pub(crate) struct MissingConstErr {
1481    #[primary_span]
1482    #[help]
1483    pub fn_sig_span: Span,
1484}
1485
1486#[derive(Diagnostic)]
1487#[diag(passes_const_stable_not_stable)]
1488pub(crate) struct ConstStableNotStable {
1489    #[primary_span]
1490    pub fn_sig_span: Span,
1491    #[label]
1492    pub const_span: Span,
1493}
1494
1495#[derive(LintDiagnostic)]
1496pub(crate) enum MultipleDeadCodes<'tcx> {
1497    #[diag(passes_dead_codes)]
1498    DeadCodes {
1499        multiple: bool,
1500        num: usize,
1501        descr: &'tcx str,
1502        participle: &'tcx str,
1503        name_list: DiagSymbolList,
1504        #[subdiagnostic]
1505        // only on DeadCodes since it's never a problem for tuple struct fields
1506        enum_variants_with_same_name: Vec<EnumVariantSameName<'tcx>>,
1507        #[subdiagnostic]
1508        parent_info: Option<ParentInfo<'tcx>>,
1509        #[subdiagnostic]
1510        ignored_derived_impls: Option<IgnoredDerivedImpls>,
1511    },
1512    #[diag(passes_dead_codes)]
1513    UnusedTupleStructFields {
1514        multiple: bool,
1515        num: usize,
1516        descr: &'tcx str,
1517        participle: &'tcx str,
1518        name_list: DiagSymbolList,
1519        #[subdiagnostic]
1520        change_fields_suggestion: ChangeFields,
1521        #[subdiagnostic]
1522        parent_info: Option<ParentInfo<'tcx>>,
1523        #[subdiagnostic]
1524        ignored_derived_impls: Option<IgnoredDerivedImpls>,
1525    },
1526}
1527
1528#[derive(Subdiagnostic)]
1529#[note(passes_enum_variant_same_name)]
1530pub(crate) struct EnumVariantSameName<'tcx> {
1531    #[primary_span]
1532    pub variant_span: Span,
1533    pub dead_name: Symbol,
1534    pub dead_descr: &'tcx str,
1535}
1536
1537#[derive(Subdiagnostic)]
1538#[label(passes_parent_info)]
1539pub(crate) struct ParentInfo<'tcx> {
1540    pub num: usize,
1541    pub descr: &'tcx str,
1542    pub parent_descr: &'tcx str,
1543    #[primary_span]
1544    pub span: Span,
1545}
1546
1547#[derive(Subdiagnostic)]
1548#[note(passes_ignored_derived_impls)]
1549pub(crate) struct IgnoredDerivedImpls {
1550    pub name: Symbol,
1551    pub trait_list: DiagSymbolList,
1552    pub trait_list_len: usize,
1553}
1554
1555#[derive(Subdiagnostic)]
1556pub(crate) enum ChangeFields {
1557    #[multipart_suggestion(
1558        passes_change_fields_to_be_of_unit_type,
1559        applicability = "has-placeholders"
1560    )]
1561    ChangeToUnitTypeOrRemove {
1562        num: usize,
1563        #[suggestion_part(code = "()")]
1564        spans: Vec<Span>,
1565    },
1566    #[help(passes_remove_fields)]
1567    Remove { num: usize },
1568}
1569
1570#[derive(Diagnostic)]
1571#[diag(passes_proc_macro_bad_sig)]
1572pub(crate) struct ProcMacroBadSig {
1573    #[primary_span]
1574    pub span: Span,
1575    pub kind: ProcMacroKind,
1576}
1577
1578#[derive(LintDiagnostic)]
1579#[diag(passes_unreachable_due_to_uninhabited)]
1580pub(crate) struct UnreachableDueToUninhabited<'desc, 'tcx> {
1581    pub descr: &'desc str,
1582    #[label]
1583    pub expr: Span,
1584    #[label(passes_label_orig)]
1585    #[note]
1586    pub orig: Span,
1587    pub ty: Ty<'tcx>,
1588}
1589
1590#[derive(LintDiagnostic)]
1591#[diag(passes_unused_var_maybe_capture_ref)]
1592#[help]
1593pub(crate) struct UnusedVarMaybeCaptureRef {
1594    pub name: String,
1595}
1596
1597#[derive(LintDiagnostic)]
1598#[diag(passes_unused_capture_maybe_capture_ref)]
1599#[help]
1600pub(crate) struct UnusedCaptureMaybeCaptureRef {
1601    pub name: String,
1602}
1603
1604#[derive(LintDiagnostic)]
1605#[diag(passes_unused_var_remove_field)]
1606pub(crate) struct UnusedVarRemoveField {
1607    pub name: String,
1608    #[subdiagnostic]
1609    pub sugg: UnusedVarRemoveFieldSugg,
1610}
1611
1612#[derive(Subdiagnostic)]
1613#[multipart_suggestion(
1614    passes_unused_var_remove_field_suggestion,
1615    applicability = "machine-applicable"
1616)]
1617pub(crate) struct UnusedVarRemoveFieldSugg {
1618    #[suggestion_part(code = "")]
1619    pub spans: Vec<Span>,
1620}
1621
1622#[derive(LintDiagnostic)]
1623#[diag(passes_unused_var_assigned_only)]
1624#[note]
1625pub(crate) struct UnusedVarAssignedOnly {
1626    pub name: String,
1627}
1628
1629#[derive(LintDiagnostic)]
1630#[diag(passes_unnecessary_stable_feature)]
1631pub(crate) struct UnnecessaryStableFeature {
1632    pub feature: Symbol,
1633    pub since: Symbol,
1634}
1635
1636#[derive(LintDiagnostic)]
1637#[diag(passes_unnecessary_partial_stable_feature)]
1638pub(crate) struct UnnecessaryPartialStableFeature {
1639    #[suggestion(code = "{implies}", applicability = "maybe-incorrect")]
1640    pub span: Span,
1641    #[suggestion(passes_suggestion_remove, code = "", applicability = "maybe-incorrect")]
1642    pub line: Span,
1643    pub feature: Symbol,
1644    pub since: Symbol,
1645    pub implies: Symbol,
1646}
1647
1648#[derive(LintDiagnostic)]
1649#[diag(passes_ineffective_unstable_impl)]
1650#[note]
1651pub(crate) struct IneffectiveUnstableImpl;
1652
1653#[derive(LintDiagnostic)]
1654#[diag(passes_unused_assign)]
1655pub(crate) struct UnusedAssign {
1656    pub name: String,
1657    #[subdiagnostic]
1658    pub suggestion: Option<UnusedAssignSuggestion>,
1659    #[help]
1660    pub help: bool,
1661}
1662
1663#[derive(Subdiagnostic)]
1664#[multipart_suggestion(passes_unused_assign_suggestion, applicability = "maybe-incorrect")]
1665pub(crate) struct UnusedAssignSuggestion {
1666    pub pre: &'static str,
1667    #[suggestion_part(code = "{pre}mut ")]
1668    pub ty_span: Option<Span>,
1669    #[suggestion_part(code = "")]
1670    pub ty_ref_span: Span,
1671    #[suggestion_part(code = "*")]
1672    pub ident_span: Span,
1673    #[suggestion_part(code = "")]
1674    pub expr_ref_span: Span,
1675}
1676
1677#[derive(LintDiagnostic)]
1678#[diag(passes_unused_assign_passed)]
1679#[help]
1680pub(crate) struct UnusedAssignPassed {
1681    pub name: String,
1682}
1683
1684#[derive(LintDiagnostic)]
1685#[diag(passes_unused_variable_try_prefix)]
1686pub(crate) struct UnusedVariableTryPrefix {
1687    #[label]
1688    pub label: Option<Span>,
1689    #[subdiagnostic]
1690    pub string_interp: Vec<UnusedVariableStringInterp>,
1691    #[subdiagnostic]
1692    pub sugg: UnusedVariableSugg,
1693    pub name: String,
1694}
1695
1696#[derive(Subdiagnostic)]
1697pub(crate) enum UnusedVariableSugg {
1698    #[multipart_suggestion(passes_suggestion, applicability = "maybe-incorrect")]
1699    TryPrefixSugg {
1700        #[suggestion_part(code = "_{name}")]
1701        spans: Vec<Span>,
1702        name: String,
1703    },
1704    #[help(passes_unused_variable_args_in_macro)]
1705    NoSugg {
1706        #[primary_span]
1707        span: Span,
1708        name: String,
1709    },
1710}
1711
1712pub(crate) struct UnusedVariableStringInterp {
1713    pub lit: Span,
1714    pub lo: Span,
1715    pub hi: Span,
1716}
1717
1718impl Subdiagnostic for UnusedVariableStringInterp {
1719    fn add_to_diag<G: EmissionGuarantee>(self, diag: &mut Diag<'_, G>) {
1720        diag.span_label(self.lit, crate::fluent_generated::passes_maybe_string_interpolation);
1721        diag.multipart_suggestion(
1722            crate::fluent_generated::passes_string_interpolation_only_works,
1723            vec![(self.lo, String::from("format!(")), (self.hi, String::from(")"))],
1724            Applicability::MachineApplicable,
1725        );
1726    }
1727}
1728
1729#[derive(LintDiagnostic)]
1730#[diag(passes_unused_variable_try_ignore)]
1731pub(crate) struct UnusedVarTryIgnore {
1732    pub name: String,
1733    #[subdiagnostic]
1734    pub sugg: UnusedVarTryIgnoreSugg,
1735}
1736
1737#[derive(Subdiagnostic)]
1738#[multipart_suggestion(passes_suggestion, applicability = "maybe-incorrect")]
1739pub(crate) struct UnusedVarTryIgnoreSugg {
1740    #[suggestion_part(code = "{name}: _")]
1741    pub shorthands: Vec<Span>,
1742    #[suggestion_part(code = "_")]
1743    pub non_shorthands: Vec<Span>,
1744    pub name: String,
1745}
1746
1747#[derive(LintDiagnostic)]
1748#[diag(passes_attr_crate_level)]
1749#[note]
1750pub(crate) struct AttrCrateLevelOnly {
1751    #[subdiagnostic]
1752    pub sugg: Option<AttrCrateLevelOnlySugg>,
1753}
1754
1755#[derive(Subdiagnostic)]
1756#[suggestion(passes_suggestion, applicability = "maybe-incorrect", code = "!", style = "verbose")]
1757pub(crate) struct AttrCrateLevelOnlySugg {
1758    #[primary_span]
1759    pub attr: Span,
1760}
1761
1762#[derive(Diagnostic)]
1763#[diag(passes_no_sanitize)]
1764pub(crate) struct NoSanitize<'a> {
1765    #[primary_span]
1766    pub attr_span: Span,
1767    #[label]
1768    pub defn_span: Span,
1769    pub accepted_kind: &'a str,
1770    pub attr_str: &'a str,
1771}
1772
1773// FIXME(jdonszelmann): move back to rustc_attr
1774#[derive(Diagnostic)]
1775#[diag(passes_rustc_const_stable_indirect_pairing)]
1776pub(crate) struct RustcConstStableIndirectPairing {
1777    #[primary_span]
1778    pub span: Span,
1779}
1780
1781#[derive(Diagnostic)]
1782#[diag(passes_unsupported_attributes_in_where)]
1783#[help]
1784pub(crate) struct UnsupportedAttributesInWhere {
1785    #[primary_span]
1786    pub span: MultiSpan,
1787}
1788
1789#[derive(Diagnostic)]
1790pub(crate) enum UnexportableItem<'a> {
1791    #[diag(passes_unexportable_item)]
1792    Item {
1793        #[primary_span]
1794        span: Span,
1795        descr: &'a str,
1796    },
1797
1798    #[diag(passes_unexportable_generic_fn)]
1799    GenericFn(#[primary_span] Span),
1800
1801    #[diag(passes_unexportable_fn_abi)]
1802    FnAbi(#[primary_span] Span),
1803
1804    #[diag(passes_unexportable_type_repr)]
1805    TypeRepr(#[primary_span] Span),
1806
1807    #[diag(passes_unexportable_type_in_interface)]
1808    TypeInInterface {
1809        #[primary_span]
1810        span: Span,
1811        desc: &'a str,
1812        ty: &'a str,
1813        #[label]
1814        ty_span: Span,
1815    },
1816
1817    #[diag(passes_unexportable_priv_item)]
1818    PrivItem {
1819        #[primary_span]
1820        span: Span,
1821        #[note]
1822        vis_note: Span,
1823        vis_descr: &'a str,
1824    },
1825
1826    #[diag(passes_unexportable_adt_with_private_fields)]
1827    AdtWithPrivFields {
1828        #[primary_span]
1829        span: Span,
1830        #[note]
1831        vis_note: Span,
1832        field_name: &'a str,
1833    },
1834}
1835
1836#[derive(Diagnostic)]
1837#[diag(passes_repr_align_should_be_align)]
1838pub(crate) struct ReprAlignShouldBeAlign {
1839    #[primary_span]
1840    #[help]
1841    pub span: Span,
1842    pub item: &'static str,
1843}
1844
1845#[derive(Diagnostic)]
1846#[diag(passes_align_should_be_repr_align)]
1847pub(crate) struct AlignShouldBeReprAlign {
1848    #[primary_span]
1849    #[suggestion(
1850        style = "verbose",
1851        applicability = "machine-applicable",
1852        code = "#[repr(align({align_bytes}))]"
1853    )]
1854    pub span: Span,
1855    pub item: &'static str,
1856    pub align_bytes: u64,
1857}
1858
1859#[derive(Diagnostic)]
1860#[diag(passes_align_attr_application)]
1861pub(crate) struct AlignAttrApplication {
1862    #[primary_span]
1863    pub hint_span: Span,
1864    #[label]
1865    pub span: Span,
1866}