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