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