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