rustc_lint/
lints.rs

1// ignore-tidy-filelength
2
3#![allow(rustc::untranslatable_diagnostic)]
4use std::num::NonZero;
5
6use rustc_errors::codes::*;
7use rustc_errors::{
8    Applicability, Diag, DiagArgValue, DiagMessage, DiagStyledString, ElidedLifetimeInPathSubdiag,
9    EmissionGuarantee, LintDiagnostic, MultiSpan, Subdiagnostic, SuggestionStyle,
10};
11use rustc_hir as hir;
12use rustc_hir::def_id::DefId;
13use rustc_hir::intravisit::VisitorExt;
14use rustc_macros::{LintDiagnostic, Subdiagnostic};
15use rustc_middle::ty::inhabitedness::InhabitedPredicate;
16use rustc_middle::ty::{Clause, PolyExistentialTraitRef, Ty, TyCtxt};
17use rustc_session::Session;
18use rustc_span::edition::Edition;
19use rustc_span::{Ident, Span, Symbol, sym};
20
21use crate::builtin::{InitError, ShorthandAssocTyCollector, TypeAliasBounds};
22use crate::errors::{OverruledAttributeSub, RequestedLevel};
23use crate::lifetime_syntax::LifetimeSyntaxCategories;
24use crate::{LateContext, fluent_generated as fluent};
25
26// array_into_iter.rs
27#[derive(LintDiagnostic)]
28#[diag(lint_shadowed_into_iter)]
29pub(crate) struct ShadowedIntoIterDiag {
30    pub target: &'static str,
31    pub edition: &'static str,
32    #[suggestion(lint_use_iter_suggestion, code = "iter", applicability = "machine-applicable")]
33    pub suggestion: Span,
34    #[subdiagnostic]
35    pub sub: Option<ShadowedIntoIterDiagSub>,
36}
37
38#[derive(Subdiagnostic)]
39pub(crate) enum ShadowedIntoIterDiagSub {
40    #[suggestion(lint_remove_into_iter_suggestion, code = "", applicability = "maybe-incorrect")]
41    RemoveIntoIter {
42        #[primary_span]
43        span: Span,
44    },
45    #[multipart_suggestion(
46        lint_use_explicit_into_iter_suggestion,
47        applicability = "maybe-incorrect"
48    )]
49    UseExplicitIntoIter {
50        #[suggestion_part(code = "IntoIterator::into_iter(")]
51        start_span: Span,
52        #[suggestion_part(code = ")")]
53        end_span: Span,
54    },
55}
56
57// autorefs.rs
58#[derive(LintDiagnostic)]
59#[diag(lint_implicit_unsafe_autorefs)]
60#[note]
61pub(crate) struct ImplicitUnsafeAutorefsDiag<'a> {
62    #[label(lint_raw_ptr)]
63    pub raw_ptr_span: Span,
64    pub raw_ptr_ty: Ty<'a>,
65    #[subdiagnostic]
66    pub origin: ImplicitUnsafeAutorefsOrigin<'a>,
67    #[subdiagnostic]
68    pub method: Option<ImplicitUnsafeAutorefsMethodNote>,
69    #[subdiagnostic]
70    pub suggestion: ImplicitUnsafeAutorefsSuggestion,
71}
72
73#[derive(Subdiagnostic)]
74pub(crate) enum ImplicitUnsafeAutorefsOrigin<'a> {
75    #[note(lint_autoref)]
76    Autoref {
77        #[primary_span]
78        autoref_span: Span,
79        autoref_ty: Ty<'a>,
80    },
81    #[note(lint_overloaded_deref)]
82    OverloadedDeref,
83}
84
85#[derive(Subdiagnostic)]
86#[note(lint_method_def)]
87pub(crate) struct ImplicitUnsafeAutorefsMethodNote {
88    #[primary_span]
89    pub def_span: Span,
90    pub method_name: Symbol,
91}
92
93#[derive(Subdiagnostic)]
94#[multipart_suggestion(lint_suggestion, applicability = "maybe-incorrect")]
95pub(crate) struct ImplicitUnsafeAutorefsSuggestion {
96    pub mutbl: &'static str,
97    pub deref: &'static str,
98    #[suggestion_part(code = "({mutbl}{deref}")]
99    pub start_span: Span,
100    #[suggestion_part(code = ")")]
101    pub end_span: Span,
102}
103
104// builtin.rs
105#[derive(LintDiagnostic)]
106#[diag(lint_builtin_while_true)]
107pub(crate) struct BuiltinWhileTrue {
108    #[suggestion(style = "short", code = "{replace}", applicability = "machine-applicable")]
109    pub suggestion: Span,
110    pub replace: String,
111}
112
113#[derive(LintDiagnostic)]
114#[diag(lint_builtin_non_shorthand_field_patterns)]
115pub(crate) struct BuiltinNonShorthandFieldPatterns {
116    pub ident: Ident,
117    #[suggestion(code = "{prefix}{ident}", applicability = "machine-applicable")]
118    pub suggestion: Span,
119    pub prefix: &'static str,
120}
121
122#[derive(LintDiagnostic)]
123pub(crate) enum BuiltinUnsafe {
124    #[diag(lint_builtin_allow_internal_unsafe)]
125    AllowInternalUnsafe,
126    #[diag(lint_builtin_unsafe_block)]
127    UnsafeBlock,
128    #[diag(lint_builtin_unsafe_extern_block)]
129    UnsafeExternBlock,
130    #[diag(lint_builtin_unsafe_trait)]
131    UnsafeTrait,
132    #[diag(lint_builtin_unsafe_impl)]
133    UnsafeImpl,
134    #[diag(lint_builtin_no_mangle_fn)]
135    #[note(lint_builtin_overridden_symbol_name)]
136    NoMangleFn,
137    #[diag(lint_builtin_export_name_fn)]
138    #[note(lint_builtin_overridden_symbol_name)]
139    ExportNameFn,
140    #[diag(lint_builtin_link_section_fn)]
141    #[note(lint_builtin_overridden_symbol_section)]
142    LinkSectionFn,
143    #[diag(lint_builtin_no_mangle_static)]
144    #[note(lint_builtin_overridden_symbol_name)]
145    NoMangleStatic,
146    #[diag(lint_builtin_export_name_static)]
147    #[note(lint_builtin_overridden_symbol_name)]
148    ExportNameStatic,
149    #[diag(lint_builtin_link_section_static)]
150    #[note(lint_builtin_overridden_symbol_section)]
151    LinkSectionStatic,
152    #[diag(lint_builtin_no_mangle_method)]
153    #[note(lint_builtin_overridden_symbol_name)]
154    NoMangleMethod,
155    #[diag(lint_builtin_export_name_method)]
156    #[note(lint_builtin_overridden_symbol_name)]
157    ExportNameMethod,
158    #[diag(lint_builtin_decl_unsafe_fn)]
159    DeclUnsafeFn,
160    #[diag(lint_builtin_decl_unsafe_method)]
161    DeclUnsafeMethod,
162    #[diag(lint_builtin_impl_unsafe_method)]
163    ImplUnsafeMethod,
164    #[diag(lint_builtin_global_asm)]
165    #[note(lint_builtin_global_macro_unsafety)]
166    GlobalAsm,
167}
168
169#[derive(LintDiagnostic)]
170#[diag(lint_builtin_missing_doc)]
171pub(crate) struct BuiltinMissingDoc<'a> {
172    pub article: &'a str,
173    pub desc: &'a str,
174}
175
176#[derive(LintDiagnostic)]
177#[diag(lint_builtin_missing_copy_impl)]
178pub(crate) struct BuiltinMissingCopyImpl;
179
180pub(crate) struct BuiltinMissingDebugImpl<'a> {
181    pub tcx: TyCtxt<'a>,
182    pub def_id: DefId,
183}
184
185// Needed for def_path_str
186impl<'a> LintDiagnostic<'a, ()> for BuiltinMissingDebugImpl<'_> {
187    fn decorate_lint<'b>(self, diag: &'b mut rustc_errors::Diag<'a, ()>) {
188        diag.primary_message(fluent::lint_builtin_missing_debug_impl);
189        diag.arg("debug", self.tcx.def_path_str(self.def_id));
190    }
191}
192
193#[derive(LintDiagnostic)]
194#[diag(lint_builtin_anonymous_params)]
195pub(crate) struct BuiltinAnonymousParams<'a> {
196    #[suggestion(code = "_: {ty_snip}")]
197    pub suggestion: (Span, Applicability),
198    pub ty_snip: &'a str,
199}
200
201#[derive(LintDiagnostic)]
202#[diag(lint_builtin_unused_doc_comment)]
203pub(crate) struct BuiltinUnusedDocComment<'a> {
204    pub kind: &'a str,
205    #[label]
206    pub label: Span,
207    #[subdiagnostic]
208    pub sub: BuiltinUnusedDocCommentSub,
209}
210
211#[derive(Subdiagnostic)]
212pub(crate) enum BuiltinUnusedDocCommentSub {
213    #[help(lint_plain_help)]
214    PlainHelp,
215    #[help(lint_block_help)]
216    BlockHelp,
217}
218
219#[derive(LintDiagnostic)]
220#[diag(lint_builtin_no_mangle_generic)]
221pub(crate) struct BuiltinNoMangleGeneric {
222    // Use of `#[no_mangle]` suggests FFI intent; correct
223    // fix may be to monomorphize source by hand
224    #[suggestion(style = "short", code = "", applicability = "maybe-incorrect")]
225    pub suggestion: Span,
226}
227
228#[derive(LintDiagnostic)]
229#[diag(lint_builtin_const_no_mangle)]
230pub(crate) struct BuiltinConstNoMangle {
231    #[suggestion(code = "pub static ", applicability = "machine-applicable")]
232    pub suggestion: Option<Span>,
233}
234
235#[derive(LintDiagnostic)]
236#[diag(lint_builtin_mutable_transmutes)]
237pub(crate) struct BuiltinMutablesTransmutes;
238
239#[derive(LintDiagnostic)]
240#[diag(lint_builtin_unstable_features)]
241pub(crate) struct BuiltinUnstableFeatures;
242
243// lint_ungated_async_fn_track_caller
244pub(crate) struct BuiltinUngatedAsyncFnTrackCaller<'a> {
245    pub label: Span,
246    pub session: &'a Session,
247}
248
249impl<'a> LintDiagnostic<'a, ()> for BuiltinUngatedAsyncFnTrackCaller<'_> {
250    fn decorate_lint<'b>(self, diag: &'b mut Diag<'a, ()>) {
251        diag.primary_message(fluent::lint_ungated_async_fn_track_caller);
252        diag.span_label(self.label, fluent::lint_label);
253        rustc_session::parse::add_feature_diagnostics(
254            diag,
255            self.session,
256            sym::async_fn_track_caller,
257        );
258    }
259}
260
261#[derive(LintDiagnostic)]
262#[diag(lint_builtin_unreachable_pub)]
263pub(crate) struct BuiltinUnreachablePub<'a> {
264    pub what: &'a str,
265    pub new_vis: &'a str,
266    #[suggestion(code = "{new_vis}")]
267    pub suggestion: (Span, Applicability),
268    #[help]
269    pub help: bool,
270}
271
272#[derive(LintDiagnostic)]
273#[diag(lint_macro_expr_fragment_specifier_2024_migration)]
274pub(crate) struct MacroExprFragment2024 {
275    #[suggestion(code = "expr_2021", applicability = "machine-applicable")]
276    pub suggestion: Span,
277}
278
279pub(crate) struct BuiltinTypeAliasBounds<'hir> {
280    pub in_where_clause: bool,
281    pub label: Span,
282    pub enable_feat_help: bool,
283    pub suggestions: Vec<(Span, String)>,
284    pub preds: &'hir [hir::WherePredicate<'hir>],
285    pub ty: Option<&'hir hir::Ty<'hir>>,
286}
287
288impl<'a> LintDiagnostic<'a, ()> for BuiltinTypeAliasBounds<'_> {
289    fn decorate_lint<'b>(self, diag: &'b mut Diag<'a, ()>) {
290        diag.primary_message(if self.in_where_clause {
291            fluent::lint_builtin_type_alias_bounds_where_clause
292        } else {
293            fluent::lint_builtin_type_alias_bounds_param_bounds
294        });
295        diag.span_label(self.label, fluent::lint_builtin_type_alias_bounds_label);
296        diag.note(fluent::lint_builtin_type_alias_bounds_limitation_note);
297        if self.enable_feat_help {
298            diag.help(fluent::lint_builtin_type_alias_bounds_enable_feat_help);
299        }
300
301        // We perform the walk in here instead of in `<TypeAliasBounds as LateLintPass>` to
302        // avoid doing throwaway work in case the lint ends up getting suppressed.
303        let mut collector = ShorthandAssocTyCollector { qselves: Vec::new() };
304        if let Some(ty) = self.ty {
305            collector.visit_ty_unambig(ty);
306        }
307
308        let affect_object_lifetime_defaults = self
309            .preds
310            .iter()
311            .filter(|pred| pred.kind.in_where_clause() == self.in_where_clause)
312            .any(|pred| TypeAliasBounds::affects_object_lifetime_defaults(pred));
313
314        // If there are any shorthand assoc tys, then the bounds can't be removed automatically.
315        // The user first needs to fully qualify the assoc tys.
316        let applicability = if !collector.qselves.is_empty() || affect_object_lifetime_defaults {
317            Applicability::MaybeIncorrect
318        } else {
319            Applicability::MachineApplicable
320        };
321
322        diag.arg("count", self.suggestions.len());
323        diag.multipart_suggestion(fluent::lint_suggestion, self.suggestions, applicability);
324
325        // Suggest fully qualifying paths of the form `T::Assoc` with `T` type param via
326        // `<T as /* Trait */>::Assoc` to remove their reliance on any type param bounds.
327        //
328        // Instead of attempting to figure out the necessary trait ref, just use a
329        // placeholder. Since we don't record type-dependent resolutions for non-body
330        // items like type aliases, we can't simply deduce the corresp. trait from
331        // the HIR path alone without rerunning parts of HIR ty lowering here
332        // (namely `probe_single_ty_param_bound_for_assoc_ty`) which is infeasible.
333        //
334        // (We could employ some simple heuristics but that's likely not worth it).
335        for qself in collector.qselves {
336            diag.multipart_suggestion(
337                fluent::lint_builtin_type_alias_bounds_qualify_assoc_tys_sugg,
338                vec![
339                    (qself.shrink_to_lo(), "<".into()),
340                    (qself.shrink_to_hi(), " as /* Trait */>".into()),
341                ],
342                Applicability::HasPlaceholders,
343            );
344        }
345    }
346}
347
348#[derive(LintDiagnostic)]
349#[diag(lint_builtin_trivial_bounds)]
350pub(crate) struct BuiltinTrivialBounds<'a> {
351    pub predicate_kind_name: &'a str,
352    pub predicate: Clause<'a>,
353}
354
355#[derive(LintDiagnostic)]
356#[diag(lint_builtin_double_negations)]
357#[note(lint_note)]
358#[note(lint_note_decrement)]
359pub(crate) struct BuiltinDoubleNegations {
360    #[subdiagnostic]
361    pub add_parens: BuiltinDoubleNegationsAddParens,
362}
363
364#[derive(Subdiagnostic)]
365#[multipart_suggestion(lint_add_parens_suggestion, applicability = "maybe-incorrect")]
366pub(crate) struct BuiltinDoubleNegationsAddParens {
367    #[suggestion_part(code = "(")]
368    pub start_span: Span,
369    #[suggestion_part(code = ")")]
370    pub end_span: Span,
371}
372
373#[derive(LintDiagnostic)]
374pub(crate) enum BuiltinEllipsisInclusiveRangePatternsLint {
375    #[diag(lint_builtin_ellipsis_inclusive_range_patterns)]
376    Parenthesise {
377        #[suggestion(code = "{replace}", applicability = "machine-applicable")]
378        suggestion: Span,
379        replace: String,
380    },
381    #[diag(lint_builtin_ellipsis_inclusive_range_patterns)]
382    NonParenthesise {
383        #[suggestion(style = "short", code = "..=", applicability = "machine-applicable")]
384        suggestion: Span,
385    },
386}
387
388#[derive(LintDiagnostic)]
389#[diag(lint_builtin_keyword_idents)]
390pub(crate) struct BuiltinKeywordIdents {
391    pub kw: Ident,
392    pub next: Edition,
393    #[suggestion(code = "{prefix}r#{kw}", applicability = "machine-applicable")]
394    pub suggestion: Span,
395    pub prefix: &'static str,
396}
397
398#[derive(LintDiagnostic)]
399#[diag(lint_builtin_explicit_outlives)]
400pub(crate) struct BuiltinExplicitOutlives {
401    pub count: usize,
402    #[subdiagnostic]
403    pub suggestion: BuiltinExplicitOutlivesSuggestion,
404}
405
406#[derive(Subdiagnostic)]
407#[multipart_suggestion(lint_suggestion)]
408pub(crate) struct BuiltinExplicitOutlivesSuggestion {
409    #[suggestion_part(code = "")]
410    pub spans: Vec<Span>,
411    #[applicability]
412    pub applicability: Applicability,
413}
414
415#[derive(LintDiagnostic)]
416#[diag(lint_builtin_incomplete_features)]
417pub(crate) struct BuiltinIncompleteFeatures {
418    pub name: Symbol,
419    #[subdiagnostic]
420    pub note: Option<BuiltinFeatureIssueNote>,
421    #[subdiagnostic]
422    pub help: Option<BuiltinIncompleteFeaturesHelp>,
423}
424
425#[derive(LintDiagnostic)]
426#[diag(lint_builtin_internal_features)]
427#[note]
428pub(crate) struct BuiltinInternalFeatures {
429    pub name: Symbol,
430}
431
432#[derive(Subdiagnostic)]
433#[help(lint_help)]
434pub(crate) struct BuiltinIncompleteFeaturesHelp;
435
436#[derive(Subdiagnostic)]
437#[note(lint_note)]
438pub(crate) struct BuiltinFeatureIssueNote {
439    pub n: NonZero<u32>,
440}
441
442pub(crate) struct BuiltinUnpermittedTypeInit<'a> {
443    pub msg: DiagMessage,
444    pub ty: Ty<'a>,
445    pub label: Span,
446    pub sub: BuiltinUnpermittedTypeInitSub,
447    pub tcx: TyCtxt<'a>,
448}
449
450impl<'a> LintDiagnostic<'a, ()> for BuiltinUnpermittedTypeInit<'_> {
451    fn decorate_lint<'b>(self, diag: &'b mut Diag<'a, ()>) {
452        diag.primary_message(self.msg);
453        diag.arg("ty", self.ty);
454        diag.span_label(self.label, fluent::lint_builtin_unpermitted_type_init_label);
455        if let InhabitedPredicate::True = self.ty.inhabited_predicate(self.tcx) {
456            // Only suggest late `MaybeUninit::assume_init` initialization if the type is inhabited.
457            diag.span_label(
458                self.label,
459                fluent::lint_builtin_unpermitted_type_init_label_suggestion,
460            );
461        }
462        self.sub.add_to_diag(diag);
463    }
464}
465
466// FIXME(davidtwco): make translatable
467pub(crate) struct BuiltinUnpermittedTypeInitSub {
468    pub err: InitError,
469}
470
471impl Subdiagnostic for BuiltinUnpermittedTypeInitSub {
472    fn add_to_diag<G: EmissionGuarantee>(self, diag: &mut Diag<'_, G>) {
473        let mut err = self.err;
474        loop {
475            if let Some(span) = err.span {
476                diag.span_note(span, err.message);
477            } else {
478                diag.note(err.message);
479            }
480            if let Some(e) = err.nested {
481                err = *e;
482            } else {
483                break;
484            }
485        }
486    }
487}
488
489#[derive(LintDiagnostic)]
490pub(crate) enum BuiltinClashingExtern<'a> {
491    #[diag(lint_builtin_clashing_extern_same_name)]
492    SameName {
493        this: Symbol,
494        orig: Symbol,
495        #[label(lint_previous_decl_label)]
496        previous_decl_label: Span,
497        #[label(lint_mismatch_label)]
498        mismatch_label: Span,
499        #[subdiagnostic]
500        sub: BuiltinClashingExternSub<'a>,
501    },
502    #[diag(lint_builtin_clashing_extern_diff_name)]
503    DiffName {
504        this: Symbol,
505        orig: Symbol,
506        #[label(lint_previous_decl_label)]
507        previous_decl_label: Span,
508        #[label(lint_mismatch_label)]
509        mismatch_label: Span,
510        #[subdiagnostic]
511        sub: BuiltinClashingExternSub<'a>,
512    },
513}
514
515// FIXME(davidtwco): translatable expected/found
516pub(crate) struct BuiltinClashingExternSub<'a> {
517    pub tcx: TyCtxt<'a>,
518    pub expected: Ty<'a>,
519    pub found: Ty<'a>,
520}
521
522impl Subdiagnostic for BuiltinClashingExternSub<'_> {
523    fn add_to_diag<G: EmissionGuarantee>(self, diag: &mut Diag<'_, G>) {
524        let mut expected_str = DiagStyledString::new();
525        expected_str.push(self.expected.fn_sig(self.tcx).to_string(), false);
526        let mut found_str = DiagStyledString::new();
527        found_str.push(self.found.fn_sig(self.tcx).to_string(), true);
528        diag.note_expected_found("", expected_str, "", found_str);
529    }
530}
531
532#[derive(LintDiagnostic)]
533#[diag(lint_builtin_deref_nullptr)]
534pub(crate) struct BuiltinDerefNullptr {
535    #[label]
536    pub label: Span,
537}
538
539// FIXME: migrate fluent::lint::builtin_asm_labels
540
541#[derive(LintDiagnostic)]
542pub(crate) enum BuiltinSpecialModuleNameUsed {
543    #[diag(lint_builtin_special_module_name_used_lib)]
544    #[note]
545    #[help]
546    Lib,
547    #[diag(lint_builtin_special_module_name_used_main)]
548    #[note]
549    Main,
550}
551
552// deref_into_dyn_supertrait.rs
553#[derive(LintDiagnostic)]
554#[diag(lint_supertrait_as_deref_target)]
555pub(crate) struct SupertraitAsDerefTarget<'a> {
556    pub self_ty: Ty<'a>,
557    pub supertrait_principal: PolyExistentialTraitRef<'a>,
558    pub target_principal: PolyExistentialTraitRef<'a>,
559    #[label]
560    pub label: Span,
561    #[subdiagnostic]
562    pub label2: Option<SupertraitAsDerefTargetLabel>,
563}
564
565#[derive(Subdiagnostic)]
566#[label(lint_label2)]
567pub(crate) struct SupertraitAsDerefTargetLabel {
568    #[primary_span]
569    pub label: Span,
570}
571
572// enum_intrinsics_non_enums.rs
573#[derive(LintDiagnostic)]
574#[diag(lint_enum_intrinsics_mem_discriminant)]
575pub(crate) struct EnumIntrinsicsMemDiscriminate<'a> {
576    pub ty_param: Ty<'a>,
577    #[note]
578    pub note: Span,
579}
580
581#[derive(LintDiagnostic)]
582#[diag(lint_enum_intrinsics_mem_variant)]
583#[note]
584pub(crate) struct EnumIntrinsicsMemVariant<'a> {
585    pub ty_param: Ty<'a>,
586}
587
588// expect.rs
589#[derive(LintDiagnostic)]
590#[diag(lint_expectation)]
591pub(crate) struct Expectation {
592    #[subdiagnostic]
593    pub rationale: Option<ExpectationNote>,
594    #[note]
595    pub note: bool,
596}
597
598#[derive(Subdiagnostic)]
599#[note(lint_rationale)]
600pub(crate) struct ExpectationNote {
601    pub rationale: Symbol,
602}
603
604// ptr_nulls.rs
605#[derive(LintDiagnostic)]
606pub(crate) enum UselessPtrNullChecksDiag<'a> {
607    #[diag(lint_useless_ptr_null_checks_fn_ptr)]
608    #[help]
609    FnPtr {
610        orig_ty: Ty<'a>,
611        #[label]
612        label: Span,
613    },
614    #[diag(lint_useless_ptr_null_checks_ref)]
615    Ref {
616        orig_ty: Ty<'a>,
617        #[label]
618        label: Span,
619    },
620    #[diag(lint_useless_ptr_null_checks_fn_ret)]
621    FnRet { fn_name: Ident },
622}
623
624#[derive(LintDiagnostic)]
625pub(crate) enum InvalidNullArgumentsDiag {
626    #[diag(lint_invalid_null_arguments)]
627    #[help(lint_doc)]
628    NullPtrInline {
629        #[label(lint_origin)]
630        null_span: Span,
631    },
632    #[diag(lint_invalid_null_arguments)]
633    #[help(lint_doc)]
634    NullPtrThroughBinding {
635        #[note(lint_origin)]
636        null_span: Span,
637    },
638}
639
640// for_loops_over_fallibles.rs
641#[derive(LintDiagnostic)]
642#[diag(lint_for_loops_over_fallibles)]
643pub(crate) struct ForLoopsOverFalliblesDiag<'a> {
644    pub article: &'static str,
645    pub ref_prefix: &'static str,
646    pub ty: &'static str,
647    #[subdiagnostic]
648    pub sub: ForLoopsOverFalliblesLoopSub<'a>,
649    #[subdiagnostic]
650    pub question_mark: Option<ForLoopsOverFalliblesQuestionMark>,
651    #[subdiagnostic]
652    pub suggestion: ForLoopsOverFalliblesSuggestion<'a>,
653}
654
655#[derive(Subdiagnostic)]
656pub(crate) enum ForLoopsOverFalliblesLoopSub<'a> {
657    #[suggestion(lint_remove_next, code = ".by_ref()", applicability = "maybe-incorrect")]
658    RemoveNext {
659        #[primary_span]
660        suggestion: Span,
661        recv_snip: String,
662    },
663    #[multipart_suggestion(lint_use_while_let, applicability = "maybe-incorrect")]
664    UseWhileLet {
665        #[suggestion_part(code = "while let {var}(")]
666        start_span: Span,
667        #[suggestion_part(code = ") = ")]
668        end_span: Span,
669        var: &'a str,
670    },
671}
672
673#[derive(Subdiagnostic)]
674#[suggestion(lint_use_question_mark, code = "?", applicability = "maybe-incorrect")]
675pub(crate) struct ForLoopsOverFalliblesQuestionMark {
676    #[primary_span]
677    pub suggestion: Span,
678}
679
680#[derive(Subdiagnostic)]
681#[multipart_suggestion(lint_suggestion, applicability = "maybe-incorrect")]
682pub(crate) struct ForLoopsOverFalliblesSuggestion<'a> {
683    pub var: &'a str,
684    #[suggestion_part(code = "if let {var}(")]
685    pub start_span: Span,
686    #[suggestion_part(code = ") = ")]
687    pub end_span: Span,
688}
689
690#[derive(Subdiagnostic)]
691pub(crate) enum UseLetUnderscoreIgnoreSuggestion {
692    #[note(lint_use_let_underscore_ignore_suggestion)]
693    Note,
694    #[multipart_suggestion(
695        lint_use_let_underscore_ignore_suggestion,
696        style = "verbose",
697        applicability = "maybe-incorrect"
698    )]
699    Suggestion {
700        #[suggestion_part(code = "let _ = ")]
701        start_span: Span,
702        #[suggestion_part(code = "")]
703        end_span: Span,
704    },
705}
706
707// drop_forget_useless.rs
708#[derive(LintDiagnostic)]
709#[diag(lint_dropping_references)]
710pub(crate) struct DropRefDiag<'a> {
711    pub arg_ty: Ty<'a>,
712    #[label]
713    pub label: Span,
714    #[subdiagnostic]
715    pub sugg: UseLetUnderscoreIgnoreSuggestion,
716}
717
718#[derive(LintDiagnostic)]
719#[diag(lint_dropping_copy_types)]
720pub(crate) struct DropCopyDiag<'a> {
721    pub arg_ty: Ty<'a>,
722    #[label]
723    pub label: Span,
724    #[subdiagnostic]
725    pub sugg: UseLetUnderscoreIgnoreSuggestion,
726}
727
728#[derive(LintDiagnostic)]
729#[diag(lint_forgetting_references)]
730pub(crate) struct ForgetRefDiag<'a> {
731    pub arg_ty: Ty<'a>,
732    #[label]
733    pub label: Span,
734    #[subdiagnostic]
735    pub sugg: UseLetUnderscoreIgnoreSuggestion,
736}
737
738#[derive(LintDiagnostic)]
739#[diag(lint_forgetting_copy_types)]
740pub(crate) struct ForgetCopyDiag<'a> {
741    pub arg_ty: Ty<'a>,
742    #[label]
743    pub label: Span,
744    #[subdiagnostic]
745    pub sugg: UseLetUnderscoreIgnoreSuggestion,
746}
747
748#[derive(LintDiagnostic)]
749#[diag(lint_undropped_manually_drops)]
750pub(crate) struct UndroppedManuallyDropsDiag<'a> {
751    pub arg_ty: Ty<'a>,
752    #[label]
753    pub label: Span,
754    #[subdiagnostic]
755    pub suggestion: UndroppedManuallyDropsSuggestion,
756}
757
758#[derive(Subdiagnostic)]
759#[multipart_suggestion(lint_suggestion, applicability = "machine-applicable")]
760pub(crate) struct UndroppedManuallyDropsSuggestion {
761    #[suggestion_part(code = "std::mem::ManuallyDrop::into_inner(")]
762    pub start_span: Span,
763    #[suggestion_part(code = ")")]
764    pub end_span: Span,
765}
766
767// invalid_from_utf8.rs
768#[derive(LintDiagnostic)]
769pub(crate) enum InvalidFromUtf8Diag {
770    #[diag(lint_invalid_from_utf8_unchecked)]
771    Unchecked {
772        method: String,
773        valid_up_to: usize,
774        #[label]
775        label: Span,
776    },
777    #[diag(lint_invalid_from_utf8_checked)]
778    Checked {
779        method: String,
780        valid_up_to: usize,
781        #[label]
782        label: Span,
783    },
784}
785
786// interior_mutable_consts.rs
787#[derive(LintDiagnostic)]
788#[diag(lint_const_item_interior_mutations)]
789#[note(lint_temporary)]
790#[note(lint_never_original)]
791#[help]
792pub(crate) struct ConstItemInteriorMutationsDiag<'tcx> {
793    pub method_name: Ident,
794    pub const_name: Ident,
795    pub const_ty: Ty<'tcx>,
796    #[label]
797    pub receiver_span: Span,
798    #[subdiagnostic]
799    pub sugg_static: Option<ConstItemInteriorMutationsSuggestionStatic>,
800}
801
802#[derive(Subdiagnostic)]
803pub(crate) enum ConstItemInteriorMutationsSuggestionStatic {
804    #[suggestion(
805        lint_suggestion_static,
806        code = "{before}static ",
807        style = "verbose",
808        applicability = "maybe-incorrect"
809    )]
810    Spanful {
811        #[primary_span]
812        const_: Span,
813        before: &'static str,
814    },
815    #[help(lint_suggestion_static)]
816    Spanless,
817}
818
819// reference_casting.rs
820#[derive(LintDiagnostic)]
821pub(crate) enum InvalidReferenceCastingDiag<'tcx> {
822    #[diag(lint_invalid_reference_casting_borrow_as_mut)]
823    #[note(lint_invalid_reference_casting_note_book)]
824    BorrowAsMut {
825        #[label]
826        orig_cast: Option<Span>,
827        #[note(lint_invalid_reference_casting_note_ty_has_interior_mutability)]
828        ty_has_interior_mutability: bool,
829    },
830    #[diag(lint_invalid_reference_casting_assign_to_ref)]
831    #[note(lint_invalid_reference_casting_note_book)]
832    AssignToRef {
833        #[label]
834        orig_cast: Option<Span>,
835        #[note(lint_invalid_reference_casting_note_ty_has_interior_mutability)]
836        ty_has_interior_mutability: bool,
837    },
838    #[diag(lint_invalid_reference_casting_bigger_layout)]
839    #[note(lint_layout)]
840    BiggerLayout {
841        #[label]
842        orig_cast: Option<Span>,
843        #[label(lint_alloc)]
844        alloc: Span,
845        from_ty: Ty<'tcx>,
846        from_size: u64,
847        to_ty: Ty<'tcx>,
848        to_size: u64,
849    },
850}
851
852// map_unit_fn.rs
853#[derive(LintDiagnostic)]
854#[diag(lint_map_unit_fn)]
855#[note]
856pub(crate) struct MappingToUnit {
857    #[label(lint_function_label)]
858    pub function_label: Span,
859    #[label(lint_argument_label)]
860    pub argument_label: Span,
861    #[label(lint_map_label)]
862    pub map_label: Span,
863    #[suggestion(style = "verbose", code = "for_each", applicability = "maybe-incorrect")]
864    pub suggestion: Span,
865}
866
867// internal.rs
868#[derive(LintDiagnostic)]
869#[diag(lint_default_hash_types)]
870#[note]
871pub(crate) struct DefaultHashTypesDiag<'a> {
872    pub preferred: &'a str,
873    pub used: Symbol,
874}
875
876#[derive(LintDiagnostic)]
877#[diag(lint_query_instability)]
878#[note]
879pub(crate) struct QueryInstability {
880    pub query: Symbol,
881}
882
883#[derive(LintDiagnostic)]
884#[diag(lint_query_untracked)]
885#[note]
886pub(crate) struct QueryUntracked {
887    pub method: Symbol,
888}
889
890#[derive(LintDiagnostic)]
891#[diag(lint_span_use_eq_ctxt)]
892pub(crate) struct SpanUseEqCtxtDiag;
893
894#[derive(LintDiagnostic)]
895#[diag(lint_symbol_intern_string_literal)]
896#[help]
897pub(crate) struct SymbolInternStringLiteralDiag;
898
899#[derive(LintDiagnostic)]
900#[diag(lint_tykind_kind)]
901pub(crate) struct TykindKind {
902    #[suggestion(code = "ty", applicability = "maybe-incorrect")]
903    pub suggestion: Span,
904}
905
906#[derive(LintDiagnostic)]
907#[diag(lint_tykind)]
908#[help]
909pub(crate) struct TykindDiag;
910
911#[derive(LintDiagnostic)]
912#[diag(lint_ty_qualified)]
913pub(crate) struct TyQualified {
914    pub ty: String,
915    #[suggestion(code = "{ty}", applicability = "maybe-incorrect")]
916    pub suggestion: Span,
917}
918
919#[derive(LintDiagnostic)]
920#[diag(lint_type_ir_inherent_usage)]
921#[note]
922pub(crate) struct TypeIrInherentUsage;
923
924#[derive(LintDiagnostic)]
925#[diag(lint_type_ir_trait_usage)]
926#[note]
927pub(crate) struct TypeIrTraitUsage;
928
929#[derive(LintDiagnostic)]
930#[diag(lint_type_ir_direct_use)]
931#[note]
932pub(crate) struct TypeIrDirectUse;
933
934#[derive(LintDiagnostic)]
935#[diag(lint_non_glob_import_type_ir_inherent)]
936pub(crate) struct NonGlobImportTypeIrInherent {
937    #[suggestion(code = "{snippet}", applicability = "maybe-incorrect")]
938    pub suggestion: Option<Span>,
939    pub snippet: &'static str,
940}
941
942#[derive(LintDiagnostic)]
943#[diag(lint_lintpass_by_hand)]
944#[help]
945pub(crate) struct LintPassByHand;
946
947#[derive(LintDiagnostic)]
948#[diag(lint_diag_out_of_impl)]
949pub(crate) struct DiagOutOfImpl;
950
951#[derive(LintDiagnostic)]
952#[diag(lint_untranslatable_diag)]
953pub(crate) struct UntranslatableDiag;
954
955#[derive(LintDiagnostic)]
956#[diag(lint_bad_opt_access)]
957pub(crate) struct BadOptAccessDiag<'a> {
958    pub msg: &'a str,
959}
960
961#[derive(LintDiagnostic)]
962#[diag(lint_implicit_sysroot_crate_import)]
963#[help]
964pub(crate) struct ImplicitSysrootCrateImportDiag<'a> {
965    pub name: &'a str,
966}
967
968// let_underscore.rs
969#[derive(LintDiagnostic)]
970pub(crate) enum NonBindingLet {
971    #[diag(lint_non_binding_let_on_sync_lock)]
972    SyncLock {
973        #[label]
974        pat: Span,
975        #[subdiagnostic]
976        sub: NonBindingLetSub,
977    },
978    #[diag(lint_non_binding_let_on_drop_type)]
979    DropType {
980        #[subdiagnostic]
981        sub: NonBindingLetSub,
982    },
983}
984
985pub(crate) struct NonBindingLetSub {
986    pub suggestion: Span,
987    pub drop_fn_start_end: Option<(Span, Span)>,
988    pub is_assign_desugar: bool,
989}
990
991impl Subdiagnostic for NonBindingLetSub {
992    fn add_to_diag<G: EmissionGuarantee>(self, diag: &mut Diag<'_, G>) {
993        let can_suggest_binding = self.drop_fn_start_end.is_some() || !self.is_assign_desugar;
994
995        if can_suggest_binding {
996            let prefix = if self.is_assign_desugar { "let " } else { "" };
997            diag.span_suggestion_verbose(
998                self.suggestion,
999                fluent::lint_non_binding_let_suggestion,
1000                format!("{prefix}_unused"),
1001                Applicability::MachineApplicable,
1002            );
1003        } else {
1004            diag.span_help(self.suggestion, fluent::lint_non_binding_let_suggestion);
1005        }
1006        if let Some(drop_fn_start_end) = self.drop_fn_start_end {
1007            diag.multipart_suggestion(
1008                fluent::lint_non_binding_let_multi_suggestion,
1009                vec![
1010                    (drop_fn_start_end.0, "drop(".to_string()),
1011                    (drop_fn_start_end.1, ")".to_string()),
1012                ],
1013                Applicability::MachineApplicable,
1014            );
1015        } else {
1016            diag.help(fluent::lint_non_binding_let_multi_drop_fn);
1017        }
1018    }
1019}
1020
1021// levels.rs
1022#[derive(LintDiagnostic)]
1023#[diag(lint_overruled_attribute)]
1024pub(crate) struct OverruledAttributeLint<'a> {
1025    #[label]
1026    pub overruled: Span,
1027    pub lint_level: &'a str,
1028    pub lint_source: Symbol,
1029    #[subdiagnostic]
1030    pub sub: OverruledAttributeSub,
1031}
1032
1033#[derive(LintDiagnostic)]
1034#[diag(lint_deprecated_lint_name)]
1035pub(crate) struct DeprecatedLintName<'a> {
1036    pub name: String,
1037    #[suggestion(code = "{replace}", applicability = "machine-applicable")]
1038    pub suggestion: Span,
1039    pub replace: &'a str,
1040}
1041
1042#[derive(LintDiagnostic)]
1043#[diag(lint_deprecated_lint_name)]
1044#[help]
1045pub(crate) struct DeprecatedLintNameFromCommandLine<'a> {
1046    pub name: String,
1047    pub replace: &'a str,
1048    #[subdiagnostic]
1049    pub requested_level: RequestedLevel<'a>,
1050}
1051
1052#[derive(LintDiagnostic)]
1053#[diag(lint_renamed_lint)]
1054pub(crate) struct RenamedLint<'a> {
1055    pub name: &'a str,
1056    pub replace: &'a str,
1057    #[subdiagnostic]
1058    pub suggestion: RenamedLintSuggestion<'a>,
1059}
1060
1061#[derive(Subdiagnostic)]
1062pub(crate) enum RenamedLintSuggestion<'a> {
1063    #[suggestion(lint_suggestion, code = "{replace}", applicability = "machine-applicable")]
1064    WithSpan {
1065        #[primary_span]
1066        suggestion: Span,
1067        replace: &'a str,
1068    },
1069    #[help(lint_help)]
1070    WithoutSpan { replace: &'a str },
1071}
1072
1073#[derive(LintDiagnostic)]
1074#[diag(lint_renamed_lint)]
1075pub(crate) struct RenamedLintFromCommandLine<'a> {
1076    pub name: &'a str,
1077    pub replace: &'a str,
1078    #[subdiagnostic]
1079    pub suggestion: RenamedLintSuggestion<'a>,
1080    #[subdiagnostic]
1081    pub requested_level: RequestedLevel<'a>,
1082}
1083
1084#[derive(LintDiagnostic)]
1085#[diag(lint_removed_lint)]
1086pub(crate) struct RemovedLint<'a> {
1087    pub name: &'a str,
1088    pub reason: &'a str,
1089}
1090
1091#[derive(LintDiagnostic)]
1092#[diag(lint_removed_lint)]
1093pub(crate) struct RemovedLintFromCommandLine<'a> {
1094    pub name: &'a str,
1095    pub reason: &'a str,
1096    #[subdiagnostic]
1097    pub requested_level: RequestedLevel<'a>,
1098}
1099
1100#[derive(LintDiagnostic)]
1101#[diag(lint_unknown_lint)]
1102pub(crate) struct UnknownLint {
1103    pub name: String,
1104    #[subdiagnostic]
1105    pub suggestion: Option<UnknownLintSuggestion>,
1106}
1107
1108#[derive(Subdiagnostic)]
1109pub(crate) enum UnknownLintSuggestion {
1110    #[suggestion(lint_suggestion, code = "{replace}", applicability = "maybe-incorrect")]
1111    WithSpan {
1112        #[primary_span]
1113        suggestion: Span,
1114        replace: Symbol,
1115        from_rustc: bool,
1116    },
1117    #[help(lint_help)]
1118    WithoutSpan { replace: Symbol, from_rustc: bool },
1119}
1120
1121#[derive(LintDiagnostic)]
1122#[diag(lint_unknown_lint, code = E0602)]
1123pub(crate) struct UnknownLintFromCommandLine<'a> {
1124    pub name: String,
1125    #[subdiagnostic]
1126    pub suggestion: Option<UnknownLintSuggestion>,
1127    #[subdiagnostic]
1128    pub requested_level: RequestedLevel<'a>,
1129}
1130
1131#[derive(LintDiagnostic)]
1132#[diag(lint_ignored_unless_crate_specified)]
1133pub(crate) struct IgnoredUnlessCrateSpecified<'a> {
1134    pub level: &'a str,
1135    pub name: Symbol,
1136}
1137
1138// dangling.rs
1139#[derive(LintDiagnostic)]
1140#[diag(lint_dangling_pointers_from_temporaries)]
1141#[help(lint_help_bind)]
1142#[note(lint_note_safe)]
1143#[note(lint_note_return)]
1144#[note(lint_note_more_info)]
1145// FIXME: put #[primary_span] on `ptr_span` once it does not cause conflicts
1146pub(crate) struct DanglingPointersFromTemporaries<'tcx> {
1147    pub callee: Ident,
1148    pub ty: Ty<'tcx>,
1149    #[label(lint_label_ptr)]
1150    pub ptr_span: Span,
1151    #[label(lint_label_temporary)]
1152    pub temporary_span: Span,
1153}
1154
1155#[derive(LintDiagnostic)]
1156#[diag(lint_dangling_pointers_from_locals)]
1157#[note(lint_note_safe)]
1158#[note(lint_note_more_info)]
1159pub(crate) struct DanglingPointersFromLocals<'tcx> {
1160    pub ret_ty: Ty<'tcx>,
1161    #[label(lint_ret_ty)]
1162    pub ret_ty_span: Span,
1163    pub fn_kind: &'static str,
1164    #[label(lint_local_var)]
1165    pub local_var: Span,
1166    pub local_var_name: Ident,
1167    pub local_var_ty: Ty<'tcx>,
1168    #[label(lint_created_at)]
1169    pub created_at: Option<Span>,
1170}
1171
1172// multiple_supertrait_upcastable.rs
1173#[derive(LintDiagnostic)]
1174#[diag(lint_multiple_supertrait_upcastable)]
1175pub(crate) struct MultipleSupertraitUpcastable {
1176    pub ident: Ident,
1177}
1178
1179// non_ascii_idents.rs
1180#[derive(LintDiagnostic)]
1181#[diag(lint_identifier_non_ascii_char)]
1182pub(crate) struct IdentifierNonAsciiChar;
1183
1184#[derive(LintDiagnostic)]
1185#[diag(lint_identifier_uncommon_codepoints)]
1186#[note]
1187pub(crate) struct IdentifierUncommonCodepoints {
1188    pub codepoints: Vec<char>,
1189    pub codepoints_len: usize,
1190    pub identifier_type: &'static str,
1191}
1192
1193#[derive(LintDiagnostic)]
1194#[diag(lint_confusable_identifier_pair)]
1195pub(crate) struct ConfusableIdentifierPair {
1196    pub existing_sym: Symbol,
1197    pub sym: Symbol,
1198    #[label(lint_other_use)]
1199    pub label: Span,
1200    #[label(lint_current_use)]
1201    pub main_label: Span,
1202}
1203
1204#[derive(LintDiagnostic)]
1205#[diag(lint_mixed_script_confusables)]
1206#[note(lint_includes_note)]
1207#[note]
1208pub(crate) struct MixedScriptConfusables {
1209    pub set: String,
1210    pub includes: String,
1211}
1212
1213// non_fmt_panic.rs
1214pub(crate) struct NonFmtPanicUnused {
1215    pub count: usize,
1216    pub suggestion: Option<Span>,
1217}
1218
1219// Used because of two suggestions based on one Option<Span>
1220impl<'a> LintDiagnostic<'a, ()> for NonFmtPanicUnused {
1221    fn decorate_lint<'b>(self, diag: &'b mut Diag<'a, ()>) {
1222        diag.primary_message(fluent::lint_non_fmt_panic_unused);
1223        diag.arg("count", self.count);
1224        diag.note(fluent::lint_note);
1225        if let Some(span) = self.suggestion {
1226            diag.span_suggestion(
1227                span.shrink_to_hi(),
1228                fluent::lint_add_args_suggestion,
1229                ", ...",
1230                Applicability::HasPlaceholders,
1231            );
1232            diag.span_suggestion(
1233                span.shrink_to_lo(),
1234                fluent::lint_add_fmt_suggestion,
1235                "\"{}\", ",
1236                Applicability::MachineApplicable,
1237            );
1238        }
1239    }
1240}
1241
1242#[derive(LintDiagnostic)]
1243#[diag(lint_non_fmt_panic_braces)]
1244#[note]
1245pub(crate) struct NonFmtPanicBraces {
1246    pub count: usize,
1247    #[suggestion(code = "\"{{}}\", ", applicability = "machine-applicable")]
1248    pub suggestion: Option<Span>,
1249}
1250
1251// nonstandard_style.rs
1252#[derive(LintDiagnostic)]
1253#[diag(lint_non_camel_case_type)]
1254pub(crate) struct NonCamelCaseType<'a> {
1255    pub sort: &'a str,
1256    pub name: &'a str,
1257    #[subdiagnostic]
1258    pub sub: NonCamelCaseTypeSub,
1259}
1260
1261#[derive(Subdiagnostic)]
1262pub(crate) enum NonCamelCaseTypeSub {
1263    #[label(lint_label)]
1264    Label {
1265        #[primary_span]
1266        span: Span,
1267    },
1268    #[suggestion(lint_suggestion, code = "{replace}", applicability = "maybe-incorrect")]
1269    Suggestion {
1270        #[primary_span]
1271        span: Span,
1272        replace: String,
1273    },
1274}
1275
1276#[derive(LintDiagnostic)]
1277#[diag(lint_non_snake_case)]
1278pub(crate) struct NonSnakeCaseDiag<'a> {
1279    pub sort: &'a str,
1280    pub name: &'a str,
1281    pub sc: String,
1282    #[subdiagnostic]
1283    pub sub: NonSnakeCaseDiagSub,
1284}
1285
1286pub(crate) enum NonSnakeCaseDiagSub {
1287    Label { span: Span },
1288    Help,
1289    RenameOrConvertSuggestion { span: Span, suggestion: Ident },
1290    ConvertSuggestion { span: Span, suggestion: String },
1291    SuggestionAndNote { span: Span },
1292}
1293
1294impl Subdiagnostic for NonSnakeCaseDiagSub {
1295    fn add_to_diag<G: EmissionGuarantee>(self, diag: &mut Diag<'_, G>) {
1296        match self {
1297            NonSnakeCaseDiagSub::Label { span } => {
1298                diag.span_label(span, fluent::lint_label);
1299            }
1300            NonSnakeCaseDiagSub::Help => {
1301                diag.help(fluent::lint_help);
1302            }
1303            NonSnakeCaseDiagSub::ConvertSuggestion { span, suggestion } => {
1304                diag.span_suggestion(
1305                    span,
1306                    fluent::lint_convert_suggestion,
1307                    suggestion,
1308                    Applicability::MaybeIncorrect,
1309                );
1310            }
1311            NonSnakeCaseDiagSub::RenameOrConvertSuggestion { span, suggestion } => {
1312                diag.span_suggestion(
1313                    span,
1314                    fluent::lint_rename_or_convert_suggestion,
1315                    suggestion,
1316                    Applicability::MaybeIncorrect,
1317                );
1318            }
1319            NonSnakeCaseDiagSub::SuggestionAndNote { span } => {
1320                diag.note(fluent::lint_cannot_convert_note);
1321                diag.span_suggestion(
1322                    span,
1323                    fluent::lint_rename_suggestion,
1324                    "",
1325                    Applicability::MaybeIncorrect,
1326                );
1327            }
1328        }
1329    }
1330}
1331
1332#[derive(LintDiagnostic)]
1333#[diag(lint_non_upper_case_global)]
1334pub(crate) struct NonUpperCaseGlobal<'a> {
1335    pub sort: &'a str,
1336    pub name: &'a str,
1337    #[subdiagnostic]
1338    pub sub: NonUpperCaseGlobalSub,
1339    #[subdiagnostic]
1340    pub usages: Vec<NonUpperCaseGlobalSubTool>,
1341}
1342
1343#[derive(Subdiagnostic)]
1344pub(crate) enum NonUpperCaseGlobalSub {
1345    #[label(lint_label)]
1346    Label {
1347        #[primary_span]
1348        span: Span,
1349    },
1350    #[suggestion(lint_suggestion, code = "{replace}")]
1351    Suggestion {
1352        #[primary_span]
1353        span: Span,
1354        #[applicability]
1355        applicability: Applicability,
1356        replace: String,
1357    },
1358}
1359
1360#[derive(Subdiagnostic)]
1361#[suggestion(
1362    lint_suggestion,
1363    code = "{replace}",
1364    applicability = "machine-applicable",
1365    style = "tool-only"
1366)]
1367pub(crate) struct NonUpperCaseGlobalSubTool {
1368    #[primary_span]
1369    pub(crate) span: Span,
1370    pub(crate) replace: String,
1371}
1372
1373// noop_method_call.rs
1374#[derive(LintDiagnostic)]
1375#[diag(lint_noop_method_call)]
1376#[note]
1377pub(crate) struct NoopMethodCallDiag<'a> {
1378    pub method: Ident,
1379    pub orig_ty: Ty<'a>,
1380    pub trait_: Symbol,
1381    #[suggestion(code = "", applicability = "machine-applicable")]
1382    pub label: Span,
1383    #[suggestion(
1384        lint_derive_suggestion,
1385        code = "#[derive(Clone)]\n",
1386        applicability = "maybe-incorrect"
1387    )]
1388    pub suggest_derive: Option<Span>,
1389}
1390
1391#[derive(LintDiagnostic)]
1392#[diag(lint_suspicious_double_ref_deref)]
1393pub(crate) struct SuspiciousDoubleRefDerefDiag<'a> {
1394    pub ty: Ty<'a>,
1395}
1396
1397#[derive(LintDiagnostic)]
1398#[diag(lint_suspicious_double_ref_clone)]
1399pub(crate) struct SuspiciousDoubleRefCloneDiag<'a> {
1400    pub ty: Ty<'a>,
1401}
1402
1403// non_local_defs.rs
1404pub(crate) enum NonLocalDefinitionsDiag {
1405    Impl {
1406        depth: u32,
1407        body_kind_descr: &'static str,
1408        body_name: String,
1409        cargo_update: Option<NonLocalDefinitionsCargoUpdateNote>,
1410        const_anon: Option<Option<Span>>,
1411        doctest: bool,
1412        macro_to_change: Option<(String, &'static str)>,
1413    },
1414    MacroRules {
1415        depth: u32,
1416        body_kind_descr: &'static str,
1417        body_name: String,
1418        doctest: bool,
1419        cargo_update: Option<NonLocalDefinitionsCargoUpdateNote>,
1420    },
1421}
1422
1423impl<'a> LintDiagnostic<'a, ()> for NonLocalDefinitionsDiag {
1424    fn decorate_lint<'b>(self, diag: &'b mut Diag<'a, ()>) {
1425        match self {
1426            NonLocalDefinitionsDiag::Impl {
1427                depth,
1428                body_kind_descr,
1429                body_name,
1430                cargo_update,
1431                const_anon,
1432                doctest,
1433                macro_to_change,
1434            } => {
1435                diag.primary_message(fluent::lint_non_local_definitions_impl);
1436                diag.arg("depth", depth);
1437                diag.arg("body_kind_descr", body_kind_descr);
1438                diag.arg("body_name", body_name);
1439
1440                if let Some((macro_to_change, macro_kind)) = macro_to_change {
1441                    diag.arg("macro_to_change", macro_to_change);
1442                    diag.arg("macro_kind", macro_kind);
1443                    diag.note(fluent::lint_macro_to_change);
1444                }
1445                if let Some(cargo_update) = cargo_update {
1446                    diag.subdiagnostic(cargo_update);
1447                }
1448
1449                diag.note(fluent::lint_non_local);
1450
1451                if doctest {
1452                    diag.help(fluent::lint_doctest);
1453                }
1454
1455                if let Some(const_anon) = const_anon {
1456                    diag.note(fluent::lint_exception);
1457                    if let Some(const_anon) = const_anon {
1458                        diag.span_suggestion(
1459                            const_anon,
1460                            fluent::lint_const_anon,
1461                            "_",
1462                            Applicability::MachineApplicable,
1463                        );
1464                    }
1465                }
1466            }
1467            NonLocalDefinitionsDiag::MacroRules {
1468                depth,
1469                body_kind_descr,
1470                body_name,
1471                doctest,
1472                cargo_update,
1473            } => {
1474                diag.primary_message(fluent::lint_non_local_definitions_macro_rules);
1475                diag.arg("depth", depth);
1476                diag.arg("body_kind_descr", body_kind_descr);
1477                diag.arg("body_name", body_name);
1478
1479                if doctest {
1480                    diag.help(fluent::lint_help_doctest);
1481                } else {
1482                    diag.help(fluent::lint_help);
1483                }
1484
1485                diag.note(fluent::lint_non_local);
1486
1487                if let Some(cargo_update) = cargo_update {
1488                    diag.subdiagnostic(cargo_update);
1489                }
1490            }
1491        }
1492    }
1493}
1494
1495#[derive(Subdiagnostic)]
1496#[note(lint_non_local_definitions_cargo_update)]
1497pub(crate) struct NonLocalDefinitionsCargoUpdateNote {
1498    pub macro_kind: &'static str,
1499    pub macro_name: Symbol,
1500    pub crate_name: Symbol,
1501}
1502
1503// precedence.rs
1504#[derive(LintDiagnostic)]
1505#[diag(lint_ambiguous_negative_literals)]
1506#[note(lint_example)]
1507pub(crate) struct AmbiguousNegativeLiteralsDiag {
1508    #[subdiagnostic]
1509    pub negative_literal: AmbiguousNegativeLiteralsNegativeLiteralSuggestion,
1510    #[subdiagnostic]
1511    pub current_behavior: AmbiguousNegativeLiteralsCurrentBehaviorSuggestion,
1512}
1513
1514#[derive(Subdiagnostic)]
1515#[multipart_suggestion(lint_negative_literal, applicability = "maybe-incorrect")]
1516pub(crate) struct AmbiguousNegativeLiteralsNegativeLiteralSuggestion {
1517    #[suggestion_part(code = "(")]
1518    pub start_span: Span,
1519    #[suggestion_part(code = ")")]
1520    pub end_span: Span,
1521}
1522
1523#[derive(Subdiagnostic)]
1524#[multipart_suggestion(lint_current_behavior, applicability = "maybe-incorrect")]
1525pub(crate) struct AmbiguousNegativeLiteralsCurrentBehaviorSuggestion {
1526    #[suggestion_part(code = "(")]
1527    pub start_span: Span,
1528    #[suggestion_part(code = ")")]
1529    pub end_span: Span,
1530}
1531
1532// pass_by_value.rs
1533#[derive(LintDiagnostic)]
1534#[diag(lint_pass_by_value)]
1535pub(crate) struct PassByValueDiag {
1536    pub ty: String,
1537    #[suggestion(code = "{ty}", applicability = "maybe-incorrect")]
1538    pub suggestion: Span,
1539}
1540
1541// redundant_semicolon.rs
1542#[derive(LintDiagnostic)]
1543#[diag(lint_redundant_semicolons)]
1544pub(crate) struct RedundantSemicolonsDiag {
1545    pub multiple: bool,
1546    #[subdiagnostic]
1547    pub suggestion: Option<RedundantSemicolonsSuggestion>,
1548}
1549
1550#[derive(Subdiagnostic)]
1551#[suggestion(lint_redundant_semicolons_suggestion, code = "", applicability = "maybe-incorrect")]
1552pub(crate) struct RedundantSemicolonsSuggestion {
1553    pub multiple_semicolons: bool,
1554    #[primary_span]
1555    pub span: Span,
1556}
1557
1558// traits.rs
1559pub(crate) struct DropTraitConstraintsDiag<'a> {
1560    pub predicate: Clause<'a>,
1561    pub tcx: TyCtxt<'a>,
1562    pub def_id: DefId,
1563}
1564
1565// Needed for def_path_str
1566impl<'a> LintDiagnostic<'a, ()> for DropTraitConstraintsDiag<'_> {
1567    fn decorate_lint<'b>(self, diag: &'b mut Diag<'a, ()>) {
1568        diag.primary_message(fluent::lint_drop_trait_constraints);
1569        diag.arg("predicate", self.predicate);
1570        diag.arg("needs_drop", self.tcx.def_path_str(self.def_id));
1571    }
1572}
1573
1574pub(crate) struct DropGlue<'a> {
1575    pub tcx: TyCtxt<'a>,
1576    pub def_id: DefId,
1577}
1578
1579// Needed for def_path_str
1580impl<'a> LintDiagnostic<'a, ()> for DropGlue<'_> {
1581    fn decorate_lint<'b>(self, diag: &'b mut Diag<'a, ()>) {
1582        diag.primary_message(fluent::lint_drop_glue);
1583        diag.arg("needs_drop", self.tcx.def_path_str(self.def_id));
1584    }
1585}
1586
1587// transmute.rs
1588#[derive(LintDiagnostic)]
1589#[diag(lint_int_to_ptr_transmutes)]
1590#[note]
1591#[note(lint_note_exposed_provenance)]
1592#[help(lint_suggestion_without_provenance_mut)]
1593#[help(lint_help_transmute)]
1594#[help(lint_help_exposed_provenance)]
1595pub(crate) struct IntegerToPtrTransmutes<'tcx> {
1596    #[subdiagnostic]
1597    pub suggestion: Option<IntegerToPtrTransmutesSuggestion<'tcx>>,
1598}
1599
1600#[derive(Subdiagnostic)]
1601pub(crate) enum IntegerToPtrTransmutesSuggestion<'tcx> {
1602    #[multipart_suggestion(
1603        lint_suggestion_with_exposed_provenance,
1604        applicability = "machine-applicable",
1605        style = "verbose"
1606    )]
1607    ToPtr {
1608        dst: Ty<'tcx>,
1609        suffix: &'static str,
1610        #[suggestion_part(code = "std::ptr::with_exposed_provenance{suffix}::<{dst}>(")]
1611        start_call: Span,
1612    },
1613    #[multipart_suggestion(
1614        lint_suggestion_with_exposed_provenance,
1615        applicability = "machine-applicable",
1616        style = "verbose"
1617    )]
1618    ToRef {
1619        dst: Ty<'tcx>,
1620        suffix: &'static str,
1621        ref_mutbl: &'static str,
1622        #[suggestion_part(
1623            code = "&{ref_mutbl}*std::ptr::with_exposed_provenance{suffix}::<{dst}>("
1624        )]
1625        start_call: Span,
1626    },
1627}
1628
1629// types.rs
1630#[derive(LintDiagnostic)]
1631#[diag(lint_range_endpoint_out_of_range)]
1632pub(crate) struct RangeEndpointOutOfRange<'a> {
1633    pub ty: &'a str,
1634    #[subdiagnostic]
1635    pub sub: UseInclusiveRange<'a>,
1636}
1637
1638#[derive(Subdiagnostic)]
1639pub(crate) enum UseInclusiveRange<'a> {
1640    #[suggestion(
1641        lint_range_use_inclusive_range,
1642        code = "{start}..={literal}{suffix}",
1643        applicability = "machine-applicable"
1644    )]
1645    WithoutParen {
1646        #[primary_span]
1647        sugg: Span,
1648        start: String,
1649        literal: u128,
1650        suffix: &'a str,
1651    },
1652    #[multipart_suggestion(lint_range_use_inclusive_range, applicability = "machine-applicable")]
1653    WithParen {
1654        #[suggestion_part(code = "=")]
1655        eq_sugg: Span,
1656        #[suggestion_part(code = "{literal}{suffix}")]
1657        lit_sugg: Span,
1658        literal: u128,
1659        suffix: &'a str,
1660    },
1661}
1662
1663#[derive(LintDiagnostic)]
1664#[diag(lint_overflowing_bin_hex)]
1665pub(crate) struct OverflowingBinHex<'a> {
1666    pub ty: &'a str,
1667    pub lit: String,
1668    pub dec: u128,
1669    pub actually: String,
1670    #[subdiagnostic]
1671    pub sign: OverflowingBinHexSign,
1672    #[subdiagnostic]
1673    pub sub: Option<OverflowingBinHexSub<'a>>,
1674    #[subdiagnostic]
1675    pub sign_bit_sub: Option<OverflowingBinHexSignBitSub<'a>>,
1676}
1677
1678pub(crate) enum OverflowingBinHexSign {
1679    Positive,
1680    Negative,
1681}
1682
1683impl Subdiagnostic for OverflowingBinHexSign {
1684    fn add_to_diag<G: EmissionGuarantee>(self, diag: &mut Diag<'_, G>) {
1685        match self {
1686            OverflowingBinHexSign::Positive => {
1687                diag.note(fluent::lint_positive_note);
1688            }
1689            OverflowingBinHexSign::Negative => {
1690                diag.note(fluent::lint_negative_note);
1691                diag.note(fluent::lint_negative_becomes_note);
1692            }
1693        }
1694    }
1695}
1696
1697#[derive(Subdiagnostic)]
1698pub(crate) enum OverflowingBinHexSub<'a> {
1699    #[suggestion(
1700        lint_suggestion,
1701        code = "{sans_suffix}{suggestion_ty}",
1702        applicability = "machine-applicable"
1703    )]
1704    Suggestion {
1705        #[primary_span]
1706        span: Span,
1707        suggestion_ty: &'a str,
1708        sans_suffix: &'a str,
1709    },
1710    #[help(lint_help)]
1711    Help { suggestion_ty: &'a str },
1712}
1713
1714#[derive(Subdiagnostic)]
1715#[suggestion(
1716    lint_sign_bit_suggestion,
1717    code = "{lit_no_suffix}{uint_ty} as {int_ty}",
1718    applicability = "maybe-incorrect"
1719)]
1720pub(crate) struct OverflowingBinHexSignBitSub<'a> {
1721    #[primary_span]
1722    pub span: Span,
1723    pub lit_no_suffix: &'a str,
1724    pub negative_val: String,
1725    pub uint_ty: &'a str,
1726    pub int_ty: &'a str,
1727}
1728
1729#[derive(LintDiagnostic)]
1730#[diag(lint_overflowing_int)]
1731#[note]
1732pub(crate) struct OverflowingInt<'a> {
1733    pub ty: &'a str,
1734    pub lit: String,
1735    pub min: i128,
1736    pub max: u128,
1737    #[subdiagnostic]
1738    pub help: Option<OverflowingIntHelp<'a>>,
1739}
1740
1741#[derive(Subdiagnostic)]
1742#[help(lint_help)]
1743pub(crate) struct OverflowingIntHelp<'a> {
1744    pub suggestion_ty: &'a str,
1745}
1746
1747#[derive(LintDiagnostic)]
1748#[diag(lint_only_cast_u8_to_char)]
1749pub(crate) struct OnlyCastu8ToChar {
1750    #[suggestion(code = "'\\u{{{literal:X}}}'", applicability = "machine-applicable")]
1751    pub span: Span,
1752    pub literal: u128,
1753}
1754
1755#[derive(LintDiagnostic)]
1756#[diag(lint_overflowing_uint)]
1757#[note]
1758pub(crate) struct OverflowingUInt<'a> {
1759    pub ty: &'a str,
1760    pub lit: String,
1761    pub min: u128,
1762    pub max: u128,
1763}
1764
1765#[derive(LintDiagnostic)]
1766#[diag(lint_overflowing_literal)]
1767#[note]
1768pub(crate) struct OverflowingLiteral<'a> {
1769    pub ty: &'a str,
1770    pub lit: String,
1771}
1772
1773#[derive(LintDiagnostic)]
1774#[diag(lint_surrogate_char_cast)]
1775#[note]
1776pub(crate) struct SurrogateCharCast {
1777    pub literal: u128,
1778}
1779
1780#[derive(LintDiagnostic)]
1781#[diag(lint_too_large_char_cast)]
1782#[note]
1783pub(crate) struct TooLargeCharCast {
1784    pub literal: u128,
1785}
1786
1787#[derive(LintDiagnostic)]
1788#[diag(lint_uses_power_alignment)]
1789pub(crate) struct UsesPowerAlignment;
1790
1791#[derive(LintDiagnostic)]
1792#[diag(lint_unused_comparisons)]
1793pub(crate) struct UnusedComparisons;
1794
1795#[derive(LintDiagnostic)]
1796pub(crate) enum InvalidNanComparisons {
1797    #[diag(lint_invalid_nan_comparisons_eq_ne)]
1798    EqNe {
1799        #[subdiagnostic]
1800        suggestion: InvalidNanComparisonsSuggestion,
1801    },
1802    #[diag(lint_invalid_nan_comparisons_lt_le_gt_ge)]
1803    LtLeGtGe,
1804}
1805
1806#[derive(Subdiagnostic)]
1807pub(crate) enum InvalidNanComparisonsSuggestion {
1808    #[multipart_suggestion(
1809        lint_suggestion,
1810        style = "verbose",
1811        applicability = "machine-applicable"
1812    )]
1813    Spanful {
1814        #[suggestion_part(code = "!")]
1815        neg: Option<Span>,
1816        #[suggestion_part(code = ".is_nan()")]
1817        float: Span,
1818        #[suggestion_part(code = "")]
1819        nan_plus_binop: Span,
1820    },
1821    #[help(lint_suggestion)]
1822    Spanless,
1823}
1824
1825#[derive(LintDiagnostic)]
1826pub(crate) enum AmbiguousWidePointerComparisons<'a> {
1827    #[diag(lint_ambiguous_wide_pointer_comparisons)]
1828    SpanfulEq {
1829        #[subdiagnostic]
1830        addr_suggestion: AmbiguousWidePointerComparisonsAddrSuggestion<'a>,
1831        #[subdiagnostic]
1832        addr_metadata_suggestion: Option<AmbiguousWidePointerComparisonsAddrMetadataSuggestion<'a>>,
1833    },
1834    #[diag(lint_ambiguous_wide_pointer_comparisons)]
1835    SpanfulCmp {
1836        #[subdiagnostic]
1837        cast_suggestion: AmbiguousWidePointerComparisonsCastSuggestion<'a>,
1838        #[subdiagnostic]
1839        expect_suggestion: AmbiguousWidePointerComparisonsExpectSuggestion<'a>,
1840    },
1841    #[diag(lint_ambiguous_wide_pointer_comparisons)]
1842    #[help(lint_addr_metadata_suggestion)]
1843    #[help(lint_addr_suggestion)]
1844    Spanless,
1845}
1846
1847#[derive(Subdiagnostic)]
1848#[multipart_suggestion(
1849    lint_addr_metadata_suggestion,
1850    style = "verbose",
1851    // FIXME(#53934): make machine-applicable again
1852    applicability = "maybe-incorrect"
1853)]
1854pub(crate) struct AmbiguousWidePointerComparisonsAddrMetadataSuggestion<'a> {
1855    pub ne: &'a str,
1856    pub deref_left: &'a str,
1857    pub deref_right: &'a str,
1858    pub l_modifiers: &'a str,
1859    pub r_modifiers: &'a str,
1860    #[suggestion_part(code = "{ne}std::ptr::eq({deref_left}")]
1861    pub left: Span,
1862    #[suggestion_part(code = "{l_modifiers}, {deref_right}")]
1863    pub middle: Span,
1864    #[suggestion_part(code = "{r_modifiers})")]
1865    pub right: Span,
1866}
1867
1868#[derive(Subdiagnostic)]
1869#[multipart_suggestion(
1870    lint_addr_suggestion,
1871    style = "verbose",
1872    // FIXME(#53934): make machine-applicable again
1873    applicability = "maybe-incorrect"
1874)]
1875pub(crate) struct AmbiguousWidePointerComparisonsAddrSuggestion<'a> {
1876    pub(crate) ne: &'a str,
1877    pub(crate) deref_left: &'a str,
1878    pub(crate) deref_right: &'a str,
1879    pub(crate) l_modifiers: &'a str,
1880    pub(crate) r_modifiers: &'a str,
1881    #[suggestion_part(code = "{ne}std::ptr::addr_eq({deref_left}")]
1882    pub(crate) left: Span,
1883    #[suggestion_part(code = "{l_modifiers}, {deref_right}")]
1884    pub(crate) middle: Span,
1885    #[suggestion_part(code = "{r_modifiers})")]
1886    pub(crate) right: Span,
1887}
1888
1889#[derive(Subdiagnostic)]
1890#[multipart_suggestion(
1891    lint_cast_suggestion,
1892    style = "verbose",
1893    // FIXME(#53934): make machine-applicable again
1894    applicability = "maybe-incorrect"
1895)]
1896pub(crate) struct AmbiguousWidePointerComparisonsCastSuggestion<'a> {
1897    pub(crate) deref_left: &'a str,
1898    pub(crate) deref_right: &'a str,
1899    pub(crate) paren_left: &'a str,
1900    pub(crate) paren_right: &'a str,
1901    pub(crate) l_modifiers: &'a str,
1902    pub(crate) r_modifiers: &'a str,
1903    #[suggestion_part(code = "({deref_left}")]
1904    pub(crate) left_before: Option<Span>,
1905    #[suggestion_part(code = "{l_modifiers}{paren_left}.cast::<()>()")]
1906    pub(crate) left_after: Span,
1907    #[suggestion_part(code = "({deref_right}")]
1908    pub(crate) right_before: Option<Span>,
1909    #[suggestion_part(code = "{r_modifiers}{paren_right}.cast::<()>()")]
1910    pub(crate) right_after: Span,
1911}
1912
1913#[derive(Subdiagnostic)]
1914#[multipart_suggestion(
1915    lint_expect_suggestion,
1916    style = "verbose",
1917    // FIXME(#53934): make machine-applicable again
1918    applicability = "maybe-incorrect"
1919)]
1920pub(crate) struct AmbiguousWidePointerComparisonsExpectSuggestion<'a> {
1921    pub(crate) paren_left: &'a str,
1922    pub(crate) paren_right: &'a str,
1923    // FIXME(#127436): Adjust once resolved
1924    #[suggestion_part(
1925        code = r#"{{ #[expect(ambiguous_wide_pointer_comparisons, reason = "...")] {paren_left}"#
1926    )]
1927    pub(crate) before: Span,
1928    #[suggestion_part(code = "{paren_right} }}")]
1929    pub(crate) after: Span,
1930}
1931
1932#[derive(LintDiagnostic)]
1933pub(crate) enum UnpredictableFunctionPointerComparisons<'a, 'tcx> {
1934    #[diag(lint_unpredictable_fn_pointer_comparisons)]
1935    #[note(lint_note_duplicated_fn)]
1936    #[note(lint_note_deduplicated_fn)]
1937    #[note(lint_note_visit_fn_addr_eq)]
1938    Suggestion {
1939        #[subdiagnostic]
1940        sugg: UnpredictableFunctionPointerComparisonsSuggestion<'a, 'tcx>,
1941    },
1942    #[diag(lint_unpredictable_fn_pointer_comparisons)]
1943    #[note(lint_note_duplicated_fn)]
1944    #[note(lint_note_deduplicated_fn)]
1945    #[note(lint_note_visit_fn_addr_eq)]
1946    Warn,
1947}
1948
1949#[derive(Subdiagnostic)]
1950pub(crate) enum UnpredictableFunctionPointerComparisonsSuggestion<'a, 'tcx> {
1951    #[multipart_suggestion(
1952        lint_fn_addr_eq_suggestion,
1953        style = "verbose",
1954        applicability = "maybe-incorrect"
1955    )]
1956    FnAddrEq {
1957        ne: &'a str,
1958        deref_left: &'a str,
1959        deref_right: &'a str,
1960        #[suggestion_part(code = "{ne}std::ptr::fn_addr_eq({deref_left}")]
1961        left: Span,
1962        #[suggestion_part(code = ", {deref_right}")]
1963        middle: Span,
1964        #[suggestion_part(code = ")")]
1965        right: Span,
1966    },
1967    #[multipart_suggestion(
1968        lint_fn_addr_eq_suggestion,
1969        style = "verbose",
1970        applicability = "maybe-incorrect"
1971    )]
1972    FnAddrEqWithCast {
1973        ne: &'a str,
1974        deref_left: &'a str,
1975        deref_right: &'a str,
1976        fn_sig: rustc_middle::ty::PolyFnSig<'tcx>,
1977        #[suggestion_part(code = "{ne}std::ptr::fn_addr_eq({deref_left}")]
1978        left: Span,
1979        #[suggestion_part(code = ", {deref_right}")]
1980        middle: Span,
1981        #[suggestion_part(code = " as {fn_sig})")]
1982        right: Span,
1983    },
1984}
1985
1986pub(crate) struct ImproperCTypes<'a> {
1987    pub ty: Ty<'a>,
1988    pub desc: &'a str,
1989    pub label: Span,
1990    pub help: Option<DiagMessage>,
1991    pub note: DiagMessage,
1992    pub span_note: Option<Span>,
1993}
1994
1995// Used because of the complexity of Option<DiagMessage>, DiagMessage, and Option<Span>
1996impl<'a> LintDiagnostic<'a, ()> for ImproperCTypes<'_> {
1997    fn decorate_lint<'b>(self, diag: &'b mut Diag<'a, ()>) {
1998        diag.primary_message(fluent::lint_improper_ctypes);
1999        diag.arg("ty", self.ty);
2000        diag.arg("desc", self.desc);
2001        diag.span_label(self.label, fluent::lint_label);
2002        if let Some(help) = self.help {
2003            diag.help(help);
2004        }
2005        diag.note(self.note);
2006        if let Some(note) = self.span_note {
2007            diag.span_note(note, fluent::lint_note);
2008        }
2009    }
2010}
2011
2012#[derive(LintDiagnostic)]
2013#[diag(lint_improper_gpu_kernel_arg)]
2014#[help]
2015pub(crate) struct ImproperGpuKernelArg<'a> {
2016    pub ty: Ty<'a>,
2017}
2018
2019#[derive(LintDiagnostic)]
2020#[diag(lint_missing_gpu_kernel_export_name)]
2021#[help]
2022#[note]
2023pub(crate) struct MissingGpuKernelExportName;
2024
2025#[derive(LintDiagnostic)]
2026#[diag(lint_variant_size_differences)]
2027pub(crate) struct VariantSizeDifferencesDiag {
2028    pub largest: u64,
2029}
2030
2031#[derive(LintDiagnostic)]
2032#[diag(lint_atomic_ordering_load)]
2033#[help]
2034pub(crate) struct AtomicOrderingLoad;
2035
2036#[derive(LintDiagnostic)]
2037#[diag(lint_atomic_ordering_store)]
2038#[help]
2039pub(crate) struct AtomicOrderingStore;
2040
2041#[derive(LintDiagnostic)]
2042#[diag(lint_atomic_ordering_fence)]
2043#[help]
2044pub(crate) struct AtomicOrderingFence;
2045
2046#[derive(LintDiagnostic)]
2047#[diag(lint_atomic_ordering_invalid)]
2048#[help]
2049pub(crate) struct InvalidAtomicOrderingDiag {
2050    pub method: Symbol,
2051    #[label]
2052    pub fail_order_arg_span: Span,
2053}
2054
2055// unused.rs
2056#[derive(LintDiagnostic)]
2057#[diag(lint_unused_op)]
2058pub(crate) struct UnusedOp<'a> {
2059    pub op: &'a str,
2060    #[label]
2061    pub label: Span,
2062    #[subdiagnostic]
2063    pub suggestion: UnusedOpSuggestion,
2064}
2065
2066#[derive(Subdiagnostic)]
2067pub(crate) enum UnusedOpSuggestion {
2068    #[suggestion(
2069        lint_suggestion,
2070        style = "verbose",
2071        code = "let _ = ",
2072        applicability = "maybe-incorrect"
2073    )]
2074    NormalExpr {
2075        #[primary_span]
2076        span: Span,
2077    },
2078    #[multipart_suggestion(lint_suggestion, style = "verbose", applicability = "maybe-incorrect")]
2079    BlockTailExpr {
2080        #[suggestion_part(code = "let _ = ")]
2081        before_span: Span,
2082        #[suggestion_part(code = ";")]
2083        after_span: Span,
2084    },
2085}
2086
2087#[derive(LintDiagnostic)]
2088#[diag(lint_unused_result)]
2089pub(crate) struct UnusedResult<'a> {
2090    pub ty: Ty<'a>,
2091}
2092
2093// FIXME(davidtwco): this isn't properly translatable because of the
2094// pre/post strings
2095#[derive(LintDiagnostic)]
2096#[diag(lint_unused_closure)]
2097#[note]
2098pub(crate) struct UnusedClosure<'a> {
2099    pub count: usize,
2100    pub pre: &'a str,
2101    pub post: &'a str,
2102}
2103
2104// FIXME(davidtwco): this isn't properly translatable because of the
2105// pre/post strings
2106#[derive(LintDiagnostic)]
2107#[diag(lint_unused_coroutine)]
2108#[note]
2109pub(crate) struct UnusedCoroutine<'a> {
2110    pub count: usize,
2111    pub pre: &'a str,
2112    pub post: &'a str,
2113}
2114
2115// FIXME(davidtwco): this isn't properly translatable because of the pre/post
2116// strings
2117pub(crate) struct UnusedDef<'a, 'b> {
2118    pub pre: &'a str,
2119    pub post: &'a str,
2120    pub cx: &'a LateContext<'b>,
2121    pub def_id: DefId,
2122    pub note: Option<Symbol>,
2123    pub suggestion: Option<UnusedDefSuggestion>,
2124}
2125
2126#[derive(Subdiagnostic)]
2127
2128pub(crate) enum UnusedDefSuggestion {
2129    #[suggestion(
2130        lint_suggestion,
2131        style = "verbose",
2132        code = "let _ = ",
2133        applicability = "maybe-incorrect"
2134    )]
2135    NormalExpr {
2136        #[primary_span]
2137        span: Span,
2138    },
2139    #[multipart_suggestion(lint_suggestion, style = "verbose", applicability = "maybe-incorrect")]
2140    BlockTailExpr {
2141        #[suggestion_part(code = "let _ = ")]
2142        before_span: Span,
2143        #[suggestion_part(code = ";")]
2144        after_span: Span,
2145    },
2146}
2147
2148// Needed because of def_path_str
2149impl<'a> LintDiagnostic<'a, ()> for UnusedDef<'_, '_> {
2150    fn decorate_lint<'b>(self, diag: &'b mut Diag<'a, ()>) {
2151        diag.primary_message(fluent::lint_unused_def);
2152        diag.arg("pre", self.pre);
2153        diag.arg("post", self.post);
2154        diag.arg("def", self.cx.tcx.def_path_str(self.def_id));
2155        // check for #[must_use = "..."]
2156        if let Some(note) = self.note {
2157            diag.note(note.to_string());
2158        }
2159        if let Some(sugg) = self.suggestion {
2160            diag.subdiagnostic(sugg);
2161        }
2162    }
2163}
2164
2165#[derive(LintDiagnostic)]
2166#[diag(lint_path_statement_drop)]
2167pub(crate) struct PathStatementDrop {
2168    #[subdiagnostic]
2169    pub sub: PathStatementDropSub,
2170}
2171
2172#[derive(Subdiagnostic)]
2173pub(crate) enum PathStatementDropSub {
2174    #[suggestion(lint_suggestion, code = "drop({snippet});", applicability = "machine-applicable")]
2175    Suggestion {
2176        #[primary_span]
2177        span: Span,
2178        snippet: String,
2179    },
2180    #[help(lint_help)]
2181    Help {
2182        #[primary_span]
2183        span: Span,
2184    },
2185}
2186
2187#[derive(LintDiagnostic)]
2188#[diag(lint_path_statement_no_effect)]
2189pub(crate) struct PathStatementNoEffect;
2190
2191#[derive(LintDiagnostic)]
2192#[diag(lint_unused_delim)]
2193pub(crate) struct UnusedDelim<'a> {
2194    pub delim: &'static str,
2195    pub item: &'a str,
2196    #[subdiagnostic]
2197    pub suggestion: Option<UnusedDelimSuggestion>,
2198}
2199
2200#[derive(Subdiagnostic)]
2201#[multipart_suggestion(lint_suggestion, applicability = "machine-applicable")]
2202pub(crate) struct UnusedDelimSuggestion {
2203    #[suggestion_part(code = "{start_replace}")]
2204    pub start_span: Span,
2205    pub start_replace: &'static str,
2206    #[suggestion_part(code = "{end_replace}")]
2207    pub end_span: Span,
2208    pub end_replace: &'static str,
2209}
2210
2211#[derive(LintDiagnostic)]
2212#[diag(lint_unused_import_braces)]
2213pub(crate) struct UnusedImportBracesDiag {
2214    pub node: Symbol,
2215}
2216
2217#[derive(LintDiagnostic)]
2218#[diag(lint_unused_allocation)]
2219pub(crate) struct UnusedAllocationDiag;
2220
2221#[derive(LintDiagnostic)]
2222#[diag(lint_unused_allocation_mut)]
2223pub(crate) struct UnusedAllocationMutDiag;
2224
2225pub(crate) struct AsyncFnInTraitDiag {
2226    pub sugg: Option<Vec<(Span, String)>>,
2227}
2228
2229impl<'a> LintDiagnostic<'a, ()> for AsyncFnInTraitDiag {
2230    fn decorate_lint<'b>(self, diag: &'b mut Diag<'a, ()>) {
2231        diag.primary_message(fluent::lint_async_fn_in_trait);
2232        diag.note(fluent::lint_note);
2233        if let Some(sugg) = self.sugg {
2234            diag.multipart_suggestion(fluent::lint_suggestion, sugg, Applicability::MaybeIncorrect);
2235        }
2236    }
2237}
2238
2239#[derive(LintDiagnostic)]
2240#[diag(lint_unit_bindings)]
2241pub(crate) struct UnitBindingsDiag {
2242    #[label]
2243    pub label: Span,
2244}
2245
2246#[derive(LintDiagnostic)]
2247pub(crate) enum InvalidAsmLabel {
2248    #[diag(lint_invalid_asm_label_named)]
2249    #[help]
2250    #[note]
2251    Named {
2252        #[note(lint_invalid_asm_label_no_span)]
2253        missing_precise_span: bool,
2254    },
2255    #[diag(lint_invalid_asm_label_format_arg)]
2256    #[help]
2257    #[note(lint_note1)]
2258    #[note(lint_note2)]
2259    FormatArg {
2260        #[note(lint_invalid_asm_label_no_span)]
2261        missing_precise_span: bool,
2262    },
2263    #[diag(lint_invalid_asm_label_binary)]
2264    #[help]
2265    #[note(lint_note1)]
2266    #[note(lint_note2)]
2267    Binary {
2268        #[note(lint_invalid_asm_label_no_span)]
2269        missing_precise_span: bool,
2270        // hack to get a label on the whole span, must match the emitted span
2271        #[label]
2272        span: Span,
2273    },
2274}
2275
2276#[derive(Subdiagnostic)]
2277pub(crate) enum UnexpectedCfgCargoHelp {
2278    #[help(lint_unexpected_cfg_add_cargo_feature)]
2279    #[help(lint_unexpected_cfg_add_cargo_toml_lint_cfg)]
2280    LintCfg { cargo_toml_lint_cfg: String },
2281    #[help(lint_unexpected_cfg_add_cargo_feature)]
2282    #[help(lint_unexpected_cfg_add_cargo_toml_lint_cfg)]
2283    #[help(lint_unexpected_cfg_add_build_rs_println)]
2284    LintCfgAndBuildRs { cargo_toml_lint_cfg: String, build_rs_println: String },
2285}
2286
2287impl UnexpectedCfgCargoHelp {
2288    fn cargo_toml_lint_cfg(unescaped: &str) -> String {
2289        format!(
2290            "\n [lints.rust]\n unexpected_cfgs = {{ level = \"warn\", check-cfg = ['{unescaped}'] }}"
2291        )
2292    }
2293
2294    pub(crate) fn lint_cfg(unescaped: &str) -> Self {
2295        UnexpectedCfgCargoHelp::LintCfg {
2296            cargo_toml_lint_cfg: Self::cargo_toml_lint_cfg(unescaped),
2297        }
2298    }
2299
2300    pub(crate) fn lint_cfg_and_build_rs(unescaped: &str, escaped: &str) -> Self {
2301        UnexpectedCfgCargoHelp::LintCfgAndBuildRs {
2302            cargo_toml_lint_cfg: Self::cargo_toml_lint_cfg(unescaped),
2303            build_rs_println: format!("println!(\"cargo::rustc-check-cfg={escaped}\");"),
2304        }
2305    }
2306}
2307
2308#[derive(Subdiagnostic)]
2309#[help(lint_unexpected_cfg_add_cmdline_arg)]
2310pub(crate) struct UnexpectedCfgRustcHelp {
2311    pub cmdline_arg: String,
2312}
2313
2314impl UnexpectedCfgRustcHelp {
2315    pub(crate) fn new(unescaped: &str) -> Self {
2316        Self { cmdline_arg: format!("--check-cfg={unescaped}") }
2317    }
2318}
2319
2320#[derive(Subdiagnostic)]
2321#[note(lint_unexpected_cfg_from_external_macro_origin)]
2322#[help(lint_unexpected_cfg_from_external_macro_refer)]
2323pub(crate) struct UnexpectedCfgRustcMacroHelp {
2324    pub macro_kind: &'static str,
2325    pub macro_name: Symbol,
2326}
2327
2328#[derive(Subdiagnostic)]
2329#[note(lint_unexpected_cfg_from_external_macro_origin)]
2330#[help(lint_unexpected_cfg_from_external_macro_refer)]
2331#[help(lint_unexpected_cfg_cargo_update)]
2332pub(crate) struct UnexpectedCfgCargoMacroHelp {
2333    pub macro_kind: &'static str,
2334    pub macro_name: Symbol,
2335    pub crate_name: Symbol,
2336}
2337
2338#[derive(LintDiagnostic)]
2339#[diag(lint_unexpected_cfg_name)]
2340pub(crate) struct UnexpectedCfgName {
2341    #[subdiagnostic]
2342    pub code_sugg: unexpected_cfg_name::CodeSuggestion,
2343    #[subdiagnostic]
2344    pub invocation_help: unexpected_cfg_name::InvocationHelp,
2345
2346    pub name: Symbol,
2347}
2348
2349pub(crate) mod unexpected_cfg_name {
2350    use rustc_errors::DiagSymbolList;
2351    use rustc_macros::Subdiagnostic;
2352    use rustc_span::{Ident, Span, Symbol};
2353
2354    #[derive(Subdiagnostic)]
2355    pub(crate) enum CodeSuggestion {
2356        #[help(lint_unexpected_cfg_define_features)]
2357        DefineFeatures,
2358        #[multipart_suggestion(
2359            lint_unexpected_cfg_name_version_syntax,
2360            applicability = "machine-applicable"
2361        )]
2362        VersionSyntax {
2363            #[suggestion_part(code = "(")]
2364            between_name_and_value: Span,
2365            #[suggestion_part(code = ")")]
2366            after_value: Span,
2367        },
2368        #[suggestion(
2369            lint_unexpected_cfg_name_similar_name_value,
2370            applicability = "maybe-incorrect",
2371            code = "{code}"
2372        )]
2373        SimilarNameAndValue {
2374            #[primary_span]
2375            span: Span,
2376            code: String,
2377        },
2378        #[suggestion(
2379            lint_unexpected_cfg_name_similar_name_no_value,
2380            applicability = "maybe-incorrect",
2381            code = "{code}"
2382        )]
2383        SimilarNameNoValue {
2384            #[primary_span]
2385            span: Span,
2386            code: String,
2387        },
2388        #[suggestion(
2389            lint_unexpected_cfg_name_similar_name_different_values,
2390            applicability = "maybe-incorrect",
2391            code = "{code}"
2392        )]
2393        SimilarNameDifferentValues {
2394            #[primary_span]
2395            span: Span,
2396            code: String,
2397            #[subdiagnostic]
2398            expected: Option<ExpectedValues>,
2399        },
2400        #[suggestion(
2401            lint_unexpected_cfg_name_similar_name,
2402            applicability = "maybe-incorrect",
2403            code = "{code}"
2404        )]
2405        SimilarName {
2406            #[primary_span]
2407            span: Span,
2408            code: String,
2409            #[subdiagnostic]
2410            expected: Option<ExpectedValues>,
2411        },
2412        SimilarValues {
2413            #[subdiagnostic]
2414            with_similar_values: Vec<FoundWithSimilarValue>,
2415            #[subdiagnostic]
2416            expected_names: Option<ExpectedNames>,
2417        },
2418        #[suggestion(
2419            lint_unexpected_cfg_boolean,
2420            applicability = "machine-applicable",
2421            style = "verbose",
2422            code = "{literal}"
2423        )]
2424        BooleanLiteral {
2425            #[primary_span]
2426            span: Span,
2427            literal: bool,
2428        },
2429    }
2430
2431    #[derive(Subdiagnostic)]
2432    #[help(lint_unexpected_cfg_name_expected_values)]
2433    pub(crate) struct ExpectedValues {
2434        pub best_match: Symbol,
2435        pub possibilities: DiagSymbolList,
2436    }
2437
2438    #[derive(Subdiagnostic)]
2439    #[suggestion(
2440        lint_unexpected_cfg_name_with_similar_value,
2441        applicability = "maybe-incorrect",
2442        code = "{code}"
2443    )]
2444    pub(crate) struct FoundWithSimilarValue {
2445        #[primary_span]
2446        pub span: Span,
2447        pub code: String,
2448    }
2449
2450    #[derive(Subdiagnostic)]
2451    #[help_once(lint_unexpected_cfg_name_expected_names)]
2452    pub(crate) struct ExpectedNames {
2453        pub possibilities: DiagSymbolList<Ident>,
2454        pub and_more: usize,
2455    }
2456
2457    #[derive(Subdiagnostic)]
2458    pub(crate) enum InvocationHelp {
2459        #[note(lint_unexpected_cfg_doc_cargo)]
2460        Cargo {
2461            #[subdiagnostic]
2462            macro_help: Option<super::UnexpectedCfgCargoMacroHelp>,
2463            #[subdiagnostic]
2464            help: Option<super::UnexpectedCfgCargoHelp>,
2465        },
2466        #[note(lint_unexpected_cfg_doc_rustc)]
2467        Rustc {
2468            #[subdiagnostic]
2469            macro_help: Option<super::UnexpectedCfgRustcMacroHelp>,
2470            #[subdiagnostic]
2471            help: super::UnexpectedCfgRustcHelp,
2472        },
2473    }
2474}
2475
2476#[derive(LintDiagnostic)]
2477#[diag(lint_unexpected_cfg_value)]
2478pub(crate) struct UnexpectedCfgValue {
2479    #[subdiagnostic]
2480    pub code_sugg: unexpected_cfg_value::CodeSuggestion,
2481    #[subdiagnostic]
2482    pub invocation_help: unexpected_cfg_value::InvocationHelp,
2483
2484    pub has_value: bool,
2485    pub value: String,
2486}
2487
2488pub(crate) mod unexpected_cfg_value {
2489    use rustc_errors::DiagSymbolList;
2490    use rustc_macros::Subdiagnostic;
2491    use rustc_span::{Span, Symbol};
2492
2493    #[derive(Subdiagnostic)]
2494    pub(crate) enum CodeSuggestion {
2495        ChangeValue {
2496            #[subdiagnostic]
2497            expected_values: ExpectedValues,
2498            #[subdiagnostic]
2499            suggestion: Option<ChangeValueSuggestion>,
2500        },
2501        #[note(lint_unexpected_cfg_value_no_expected_value)]
2502        RemoveValue {
2503            #[subdiagnostic]
2504            suggestion: Option<RemoveValueSuggestion>,
2505
2506            name: Symbol,
2507        },
2508        #[note(lint_unexpected_cfg_value_no_expected_values)]
2509        RemoveCondition {
2510            #[subdiagnostic]
2511            suggestion: RemoveConditionSuggestion,
2512
2513            name: Symbol,
2514        },
2515    }
2516
2517    #[derive(Subdiagnostic)]
2518    pub(crate) enum ChangeValueSuggestion {
2519        #[suggestion(
2520            lint_unexpected_cfg_value_similar_name,
2521            code = r#""{best_match}""#,
2522            applicability = "maybe-incorrect"
2523        )]
2524        SimilarName {
2525            #[primary_span]
2526            span: Span,
2527            best_match: Symbol,
2528        },
2529        #[suggestion(
2530            lint_unexpected_cfg_value_specify_value,
2531            code = r#" = "{first_possibility}""#,
2532            applicability = "maybe-incorrect"
2533        )]
2534        SpecifyValue {
2535            #[primary_span]
2536            span: Span,
2537            first_possibility: Symbol,
2538        },
2539    }
2540
2541    #[derive(Subdiagnostic)]
2542    #[suggestion(
2543        lint_unexpected_cfg_value_remove_value,
2544        code = "",
2545        applicability = "maybe-incorrect"
2546    )]
2547    pub(crate) struct RemoveValueSuggestion {
2548        #[primary_span]
2549        pub span: Span,
2550    }
2551
2552    #[derive(Subdiagnostic)]
2553    #[suggestion(
2554        lint_unexpected_cfg_value_remove_condition,
2555        code = "",
2556        applicability = "maybe-incorrect"
2557    )]
2558    pub(crate) struct RemoveConditionSuggestion {
2559        #[primary_span]
2560        pub span: Span,
2561    }
2562
2563    #[derive(Subdiagnostic)]
2564    #[note(lint_unexpected_cfg_value_expected_values)]
2565    pub(crate) struct ExpectedValues {
2566        pub name: Symbol,
2567        pub have_none_possibility: bool,
2568        pub possibilities: DiagSymbolList,
2569        pub and_more: usize,
2570    }
2571
2572    #[derive(Subdiagnostic)]
2573    pub(crate) enum InvocationHelp {
2574        #[note(lint_unexpected_cfg_doc_cargo)]
2575        Cargo {
2576            #[subdiagnostic]
2577            help: Option<CargoHelp>,
2578            #[subdiagnostic]
2579            macro_help: Option<super::UnexpectedCfgCargoMacroHelp>,
2580        },
2581        #[note(lint_unexpected_cfg_doc_rustc)]
2582        Rustc {
2583            #[subdiagnostic]
2584            help: Option<super::UnexpectedCfgRustcHelp>,
2585            #[subdiagnostic]
2586            macro_help: Option<super::UnexpectedCfgRustcMacroHelp>,
2587        },
2588    }
2589
2590    #[derive(Subdiagnostic)]
2591    pub(crate) enum CargoHelp {
2592        #[help(lint_unexpected_cfg_value_add_feature)]
2593        AddFeature {
2594            value: Symbol,
2595        },
2596        #[help(lint_unexpected_cfg_define_features)]
2597        DefineFeatures,
2598        Other(#[subdiagnostic] super::UnexpectedCfgCargoHelp),
2599    }
2600}
2601
2602#[derive(LintDiagnostic)]
2603#[diag(lint_unused_crate_dependency)]
2604#[help]
2605pub(crate) struct UnusedCrateDependency {
2606    pub extern_crate: Symbol,
2607    pub local_crate: Symbol,
2608}
2609
2610// FIXME(jdonszelmann): duplicated in rustc_attr_parsing, should be moved there completely.
2611#[derive(LintDiagnostic)]
2612#[diag(lint_ill_formed_attribute_input)]
2613pub(crate) struct IllFormedAttributeInput {
2614    pub num_suggestions: usize,
2615    pub suggestions: DiagArgValue,
2616    #[note]
2617    pub has_docs: bool,
2618    pub docs: &'static str,
2619}
2620
2621#[derive(LintDiagnostic)]
2622#[diag(lint_unicode_text_flow)]
2623#[note]
2624pub(crate) struct UnicodeTextFlow {
2625    #[label]
2626    pub comment_span: Span,
2627    #[subdiagnostic]
2628    pub characters: Vec<UnicodeCharNoteSub>,
2629    #[subdiagnostic]
2630    pub suggestions: Option<UnicodeTextFlowSuggestion>,
2631
2632    pub num_codepoints: usize,
2633}
2634
2635#[derive(Subdiagnostic)]
2636#[label(lint_label_comment_char)]
2637pub(crate) struct UnicodeCharNoteSub {
2638    #[primary_span]
2639    pub span: Span,
2640    pub c_debug: String,
2641}
2642
2643#[derive(Subdiagnostic)]
2644#[multipart_suggestion(lint_suggestion, applicability = "machine-applicable", style = "hidden")]
2645pub(crate) struct UnicodeTextFlowSuggestion {
2646    #[suggestion_part(code = "")]
2647    pub spans: Vec<Span>,
2648}
2649
2650#[derive(LintDiagnostic)]
2651#[diag(lint_abs_path_with_module)]
2652pub(crate) struct AbsPathWithModule {
2653    #[subdiagnostic]
2654    pub sugg: AbsPathWithModuleSugg,
2655}
2656
2657#[derive(Subdiagnostic)]
2658#[suggestion(lint_suggestion, code = "{replacement}")]
2659pub(crate) struct AbsPathWithModuleSugg {
2660    #[primary_span]
2661    pub span: Span,
2662    #[applicability]
2663    pub applicability: Applicability,
2664    pub replacement: String,
2665}
2666
2667#[derive(LintDiagnostic)]
2668#[diag(lint_hidden_lifetime_parameters)]
2669pub(crate) struct ElidedLifetimesInPaths {
2670    #[subdiagnostic]
2671    pub subdiag: ElidedLifetimeInPathSubdiag,
2672}
2673
2674#[derive(LintDiagnostic)]
2675#[diag(lint_unused_imports)]
2676pub(crate) struct UnusedImports {
2677    #[subdiagnostic]
2678    pub sugg: UnusedImportsSugg,
2679    #[help]
2680    pub test_module_span: Option<Span>,
2681
2682    pub span_snippets: DiagArgValue,
2683    pub num_snippets: usize,
2684}
2685
2686#[derive(Subdiagnostic)]
2687pub(crate) enum UnusedImportsSugg {
2688    #[suggestion(
2689        lint_suggestion_remove_whole_use,
2690        applicability = "machine-applicable",
2691        code = "",
2692        style = "tool-only"
2693    )]
2694    RemoveWholeUse {
2695        #[primary_span]
2696        span: Span,
2697    },
2698    #[multipart_suggestion(
2699        lint_suggestion_remove_imports,
2700        applicability = "machine-applicable",
2701        style = "tool-only"
2702    )]
2703    RemoveImports {
2704        #[suggestion_part(code = "")]
2705        remove_spans: Vec<Span>,
2706        num_to_remove: usize,
2707    },
2708}
2709
2710#[derive(LintDiagnostic)]
2711#[diag(lint_redundant_import)]
2712pub(crate) struct RedundantImport {
2713    #[subdiagnostic]
2714    pub subs: Vec<RedundantImportSub>,
2715
2716    pub ident: Ident,
2717}
2718
2719#[derive(Subdiagnostic)]
2720pub(crate) enum RedundantImportSub {
2721    #[label(lint_label_imported_here)]
2722    ImportedHere(#[primary_span] Span),
2723    #[label(lint_label_defined_here)]
2724    DefinedHere(#[primary_span] Span),
2725    #[label(lint_label_imported_prelude)]
2726    ImportedPrelude(#[primary_span] Span),
2727    #[label(lint_label_defined_prelude)]
2728    DefinedPrelude(#[primary_span] Span),
2729}
2730
2731#[derive(LintDiagnostic)]
2732pub(crate) enum PatternsInFnsWithoutBody {
2733    #[diag(lint_pattern_in_foreign)]
2734    Foreign {
2735        #[subdiagnostic]
2736        sub: PatternsInFnsWithoutBodySub,
2737    },
2738    #[diag(lint_pattern_in_bodiless)]
2739    Bodiless {
2740        #[subdiagnostic]
2741        sub: PatternsInFnsWithoutBodySub,
2742    },
2743}
2744
2745#[derive(Subdiagnostic)]
2746#[suggestion(lint_remove_mut_from_pattern, code = "{ident}", applicability = "machine-applicable")]
2747pub(crate) struct PatternsInFnsWithoutBodySub {
2748    #[primary_span]
2749    pub span: Span,
2750
2751    pub ident: Ident,
2752}
2753
2754#[derive(LintDiagnostic)]
2755#[diag(lint_reserved_prefix)]
2756pub(crate) struct ReservedPrefix {
2757    #[label]
2758    pub label: Span,
2759    #[suggestion(code = " ", applicability = "machine-applicable")]
2760    pub suggestion: Span,
2761
2762    pub prefix: String,
2763}
2764
2765#[derive(LintDiagnostic)]
2766#[diag(lint_raw_prefix)]
2767pub(crate) struct RawPrefix {
2768    #[label]
2769    pub label: Span,
2770    #[suggestion(code = " ", applicability = "machine-applicable")]
2771    pub suggestion: Span,
2772}
2773
2774#[derive(LintDiagnostic)]
2775#[diag(lint_break_with_label_and_loop)]
2776pub(crate) struct BreakWithLabelAndLoop {
2777    #[subdiagnostic]
2778    pub sub: BreakWithLabelAndLoopSub,
2779}
2780
2781#[derive(Subdiagnostic)]
2782#[multipart_suggestion(lint_suggestion, applicability = "machine-applicable")]
2783pub(crate) struct BreakWithLabelAndLoopSub {
2784    #[suggestion_part(code = "(")]
2785    pub left: Span,
2786    #[suggestion_part(code = ")")]
2787    pub right: Span,
2788}
2789
2790#[derive(LintDiagnostic)]
2791#[diag(lint_deprecated_where_clause_location)]
2792#[note]
2793pub(crate) struct DeprecatedWhereClauseLocation {
2794    #[subdiagnostic]
2795    pub suggestion: DeprecatedWhereClauseLocationSugg,
2796}
2797
2798#[derive(Subdiagnostic)]
2799pub(crate) enum DeprecatedWhereClauseLocationSugg {
2800    #[multipart_suggestion(lint_suggestion_move_to_end, applicability = "machine-applicable")]
2801    MoveToEnd {
2802        #[suggestion_part(code = "")]
2803        left: Span,
2804        #[suggestion_part(code = "{sugg}")]
2805        right: Span,
2806
2807        sugg: String,
2808    },
2809    #[suggestion(lint_suggestion_remove_where, code = "", applicability = "machine-applicable")]
2810    RemoveWhere {
2811        #[primary_span]
2812        span: Span,
2813    },
2814}
2815
2816#[derive(LintDiagnostic)]
2817#[diag(lint_single_use_lifetime)]
2818pub(crate) struct SingleUseLifetime {
2819    #[label(lint_label_param)]
2820    pub param_span: Span,
2821    #[label(lint_label_use)]
2822    pub use_span: Span,
2823    #[subdiagnostic]
2824    pub suggestion: Option<SingleUseLifetimeSugg>,
2825
2826    pub ident: Ident,
2827}
2828
2829#[derive(Subdiagnostic)]
2830#[multipart_suggestion(lint_suggestion, applicability = "machine-applicable")]
2831pub(crate) struct SingleUseLifetimeSugg {
2832    #[suggestion_part(code = "")]
2833    pub deletion_span: Option<Span>,
2834    #[suggestion_part(code = "{replace_lt}")]
2835    pub use_span: Span,
2836
2837    pub replace_lt: String,
2838}
2839
2840#[derive(LintDiagnostic)]
2841#[diag(lint_unused_lifetime)]
2842pub(crate) struct UnusedLifetime {
2843    #[suggestion(code = "", applicability = "machine-applicable")]
2844    pub deletion_span: Option<Span>,
2845
2846    pub ident: Ident,
2847}
2848
2849#[derive(LintDiagnostic)]
2850#[diag(lint_named_argument_used_positionally)]
2851pub(crate) struct NamedArgumentUsedPositionally {
2852    #[label(lint_label_named_arg)]
2853    pub named_arg_sp: Span,
2854    #[label(lint_label_position_arg)]
2855    pub position_label_sp: Option<Span>,
2856    #[suggestion(style = "verbose", code = "{name}", applicability = "maybe-incorrect")]
2857    pub suggestion: Option<Span>,
2858
2859    pub name: String,
2860    pub named_arg_name: String,
2861}
2862
2863#[derive(LintDiagnostic)]
2864#[diag(lint_ambiguous_glob_reexport)]
2865pub(crate) struct AmbiguousGlobReexports {
2866    #[label(lint_label_first_reexport)]
2867    pub first_reexport: Span,
2868    #[label(lint_label_duplicate_reexport)]
2869    pub duplicate_reexport: Span,
2870
2871    pub name: String,
2872    // FIXME: make this translatable
2873    pub namespace: String,
2874}
2875
2876#[derive(LintDiagnostic)]
2877#[diag(lint_hidden_glob_reexport)]
2878pub(crate) struct HiddenGlobReexports {
2879    #[note(lint_note_glob_reexport)]
2880    pub glob_reexport: Span,
2881    #[note(lint_note_private_item)]
2882    pub private_item: Span,
2883
2884    pub name: String,
2885    // FIXME: make this translatable
2886    pub namespace: String,
2887}
2888
2889#[derive(LintDiagnostic)]
2890#[diag(lint_unnecessary_qualification)]
2891pub(crate) struct UnusedQualifications {
2892    #[suggestion(style = "verbose", code = "", applicability = "machine-applicable")]
2893    pub removal_span: Span,
2894}
2895
2896#[derive(LintDiagnostic)]
2897#[diag(lint_associated_const_elided_lifetime)]
2898pub(crate) struct AssociatedConstElidedLifetime {
2899    #[suggestion(style = "verbose", code = "{code}", applicability = "machine-applicable")]
2900    pub span: Span,
2901
2902    pub code: &'static str,
2903    pub elided: bool,
2904    #[note]
2905    pub lifetimes_in_scope: MultiSpan,
2906}
2907
2908#[derive(LintDiagnostic)]
2909#[diag(lint_static_mut_refs_lint)]
2910pub(crate) struct RefOfMutStatic<'a> {
2911    #[label]
2912    pub span: Span,
2913    #[subdiagnostic]
2914    pub sugg: Option<MutRefSugg>,
2915    pub shared_label: &'a str,
2916    #[note(lint_shared_note)]
2917    pub shared_note: bool,
2918    #[note(lint_mut_note)]
2919    pub mut_note: bool,
2920}
2921
2922#[derive(Subdiagnostic)]
2923pub(crate) enum MutRefSugg {
2924    #[multipart_suggestion(lint_suggestion, style = "verbose", applicability = "maybe-incorrect")]
2925    Shared {
2926        #[suggestion_part(code = "&raw const ")]
2927        span: Span,
2928    },
2929    #[multipart_suggestion(
2930        lint_suggestion_mut,
2931        style = "verbose",
2932        applicability = "maybe-incorrect"
2933    )]
2934    Mut {
2935        #[suggestion_part(code = "&raw mut ")]
2936        span: Span,
2937    },
2938}
2939
2940#[derive(LintDiagnostic)]
2941#[diag(lint_unqualified_local_imports)]
2942pub(crate) struct UnqualifiedLocalImportsDiag {}
2943
2944#[derive(LintDiagnostic)]
2945#[diag(lint_reserved_string)]
2946pub(crate) struct ReservedString {
2947    #[suggestion(code = " ", applicability = "machine-applicable")]
2948    pub suggestion: Span,
2949}
2950
2951#[derive(LintDiagnostic)]
2952#[diag(lint_reserved_multihash)]
2953pub(crate) struct ReservedMultihash {
2954    #[suggestion(code = " ", applicability = "machine-applicable")]
2955    pub suggestion: Span,
2956}
2957
2958#[derive(LintDiagnostic)]
2959#[diag(lint_function_casts_as_integer)]
2960pub(crate) struct FunctionCastsAsIntegerDiag<'tcx> {
2961    #[subdiagnostic]
2962    pub(crate) sugg: FunctionCastsAsIntegerSugg<'tcx>,
2963}
2964
2965#[derive(Subdiagnostic)]
2966#[suggestion(
2967    lint_cast_as_fn,
2968    code = " as *const ()",
2969    applicability = "machine-applicable",
2970    style = "verbose"
2971)]
2972pub(crate) struct FunctionCastsAsIntegerSugg<'tcx> {
2973    #[primary_span]
2974    pub suggestion: Span,
2975    pub cast_to_ty: Ty<'tcx>,
2976}
2977
2978#[derive(Debug)]
2979pub(crate) struct MismatchedLifetimeSyntaxes {
2980    pub inputs: LifetimeSyntaxCategories<Vec<Span>>,
2981    pub outputs: LifetimeSyntaxCategories<Vec<Span>>,
2982
2983    pub suggestions: Vec<MismatchedLifetimeSyntaxesSuggestion>,
2984}
2985
2986impl<'a, G: EmissionGuarantee> LintDiagnostic<'a, G> for MismatchedLifetimeSyntaxes {
2987    fn decorate_lint<'b>(self, diag: &'b mut Diag<'a, G>) {
2988        let counts = self.inputs.len() + self.outputs.len();
2989        let message = match counts {
2990            LifetimeSyntaxCategories { hidden: 0, elided: 0, named: 0 } => {
2991                panic!("No lifetime mismatch detected")
2992            }
2993
2994            LifetimeSyntaxCategories { hidden: _, elided: _, named: 0 } => {
2995                fluent::lint_mismatched_lifetime_syntaxes_hiding_while_elided
2996            }
2997
2998            LifetimeSyntaxCategories { hidden: _, elided: 0, named: _ } => {
2999                fluent::lint_mismatched_lifetime_syntaxes_hiding_while_named
3000            }
3001
3002            LifetimeSyntaxCategories { hidden: 0, elided: _, named: _ } => {
3003                fluent::lint_mismatched_lifetime_syntaxes_eliding_while_named
3004            }
3005
3006            LifetimeSyntaxCategories { hidden: _, elided: _, named: _ } => {
3007                fluent::lint_mismatched_lifetime_syntaxes_hiding_and_eliding_while_named
3008            }
3009        };
3010        diag.primary_message(message);
3011
3012        for s in self.inputs.hidden {
3013            diag.span_label(s, fluent::lint_mismatched_lifetime_syntaxes_input_hidden);
3014        }
3015        for s in self.inputs.elided {
3016            diag.span_label(s, fluent::lint_mismatched_lifetime_syntaxes_input_elided);
3017        }
3018        for s in self.inputs.named {
3019            diag.span_label(s, fluent::lint_mismatched_lifetime_syntaxes_input_named);
3020        }
3021
3022        for s in self.outputs.hidden {
3023            diag.span_label(s, fluent::lint_mismatched_lifetime_syntaxes_output_hidden);
3024        }
3025        for s in self.outputs.elided {
3026            diag.span_label(s, fluent::lint_mismatched_lifetime_syntaxes_output_elided);
3027        }
3028        for s in self.outputs.named {
3029            diag.span_label(s, fluent::lint_mismatched_lifetime_syntaxes_output_named);
3030        }
3031
3032        diag.help(fluent::lint_mismatched_lifetime_syntaxes_help);
3033
3034        let mut suggestions = self.suggestions.into_iter();
3035        if let Some(s) = suggestions.next() {
3036            diag.subdiagnostic(s);
3037
3038            for mut s in suggestions {
3039                s.make_optional_alternative();
3040                diag.subdiagnostic(s);
3041            }
3042        }
3043    }
3044}
3045
3046#[derive(Debug)]
3047pub(crate) enum MismatchedLifetimeSyntaxesSuggestion {
3048    Implicit {
3049        suggestions: Vec<Span>,
3050        optional_alternative: bool,
3051    },
3052
3053    Mixed {
3054        implicit_suggestions: Vec<Span>,
3055        explicit_anonymous_suggestions: Vec<(Span, String)>,
3056        optional_alternative: bool,
3057    },
3058
3059    Explicit {
3060        lifetime_name: String,
3061        suggestions: Vec<(Span, String)>,
3062        optional_alternative: bool,
3063    },
3064}
3065
3066impl MismatchedLifetimeSyntaxesSuggestion {
3067    fn make_optional_alternative(&mut self) {
3068        use MismatchedLifetimeSyntaxesSuggestion::*;
3069
3070        let optional_alternative = match self {
3071            Implicit { optional_alternative, .. }
3072            | Mixed { optional_alternative, .. }
3073            | Explicit { optional_alternative, .. } => optional_alternative,
3074        };
3075
3076        *optional_alternative = true;
3077    }
3078}
3079
3080impl Subdiagnostic for MismatchedLifetimeSyntaxesSuggestion {
3081    fn add_to_diag<G: EmissionGuarantee>(self, diag: &mut Diag<'_, G>) {
3082        use MismatchedLifetimeSyntaxesSuggestion::*;
3083
3084        let style = |optional_alternative| {
3085            if optional_alternative {
3086                SuggestionStyle::CompletelyHidden
3087            } else {
3088                SuggestionStyle::ShowAlways
3089            }
3090        };
3091
3092        let applicability = |optional_alternative| {
3093            // `cargo fix` can't handle more than one fix for the same issue,
3094            // so hide alternative suggestions from it by marking them as maybe-incorrect
3095            if optional_alternative {
3096                Applicability::MaybeIncorrect
3097            } else {
3098                Applicability::MachineApplicable
3099            }
3100        };
3101
3102        match self {
3103            Implicit { suggestions, optional_alternative } => {
3104                let suggestions = suggestions.into_iter().map(|s| (s, String::new())).collect();
3105                diag.multipart_suggestion_with_style(
3106                    fluent::lint_mismatched_lifetime_syntaxes_suggestion_implicit,
3107                    suggestions,
3108                    applicability(optional_alternative),
3109                    style(optional_alternative),
3110                );
3111            }
3112
3113            Mixed {
3114                implicit_suggestions,
3115                explicit_anonymous_suggestions,
3116                optional_alternative,
3117            } => {
3118                let message = if implicit_suggestions.is_empty() {
3119                    fluent::lint_mismatched_lifetime_syntaxes_suggestion_mixed_only_paths
3120                } else {
3121                    fluent::lint_mismatched_lifetime_syntaxes_suggestion_mixed
3122                };
3123
3124                let implicit_suggestions =
3125                    implicit_suggestions.into_iter().map(|s| (s, String::new()));
3126
3127                let suggestions =
3128                    implicit_suggestions.chain(explicit_anonymous_suggestions).collect();
3129
3130                diag.multipart_suggestion_with_style(
3131                    message,
3132                    suggestions,
3133                    applicability(optional_alternative),
3134                    style(optional_alternative),
3135                );
3136            }
3137
3138            Explicit { lifetime_name, suggestions, optional_alternative } => {
3139                diag.arg("lifetime_name", lifetime_name);
3140                let msg = diag.eagerly_translate(
3141                    fluent::lint_mismatched_lifetime_syntaxes_suggestion_explicit,
3142                );
3143                diag.remove_arg("lifetime_name");
3144                diag.multipart_suggestion_with_style(
3145                    msg,
3146                    suggestions,
3147                    applicability(optional_alternative),
3148                    style(optional_alternative),
3149                );
3150            }
3151        }
3152    }
3153}
3154
3155#[derive(LintDiagnostic)]
3156#[diag(lint_empty_attribute)]
3157#[note]
3158pub(crate) struct EmptyAttributeList {
3159    #[suggestion(code = "", applicability = "machine-applicable")]
3160    pub attr_span: Span,
3161    pub attr_path: String,
3162    pub valid_without_list: bool,
3163}
3164
3165#[derive(LintDiagnostic)]
3166#[diag(lint_invalid_target)]
3167#[warning]
3168#[help]
3169pub(crate) struct InvalidTargetLint {
3170    pub name: String,
3171    pub target: &'static str,
3172    pub applied: DiagArgValue,
3173    pub only: &'static str,
3174    #[suggestion(code = "", applicability = "machine-applicable", style = "tool-only")]
3175    pub attr_span: Span,
3176}
3177
3178#[derive(LintDiagnostic)]
3179#[diag(lint_invalid_style)]
3180pub(crate) struct InvalidAttrStyle {
3181    pub name: String,
3182    pub is_used_as_inner: bool,
3183    #[note]
3184    pub target_span: Option<Span>,
3185    pub target: &'static str,
3186}
3187
3188#[derive(LintDiagnostic)]
3189#[diag(lint_unused_duplicate)]
3190pub(crate) struct UnusedDuplicate {
3191    #[suggestion(code = "", applicability = "machine-applicable")]
3192    pub this: Span,
3193    #[note]
3194    pub other: Span,
3195    #[warning]
3196    pub warning: bool,
3197}
3198
3199#[derive(LintDiagnostic)]
3200#[diag(lint_unsafe_attr_outside_unsafe)]
3201pub(crate) struct UnsafeAttrOutsideUnsafeLint {
3202    #[label]
3203    pub span: Span,
3204    #[subdiagnostic]
3205    pub suggestion: Option<UnsafeAttrOutsideUnsafeSuggestion>,
3206}
3207
3208#[derive(Subdiagnostic)]
3209#[multipart_suggestion(
3210    lint_unsafe_attr_outside_unsafe_suggestion,
3211    applicability = "machine-applicable"
3212)]
3213pub(crate) struct UnsafeAttrOutsideUnsafeSuggestion {
3214    #[suggestion_part(code = "unsafe(")]
3215    pub left: Span,
3216    #[suggestion_part(code = ")")]
3217    pub right: Span,
3218}
3219
3220#[derive(LintDiagnostic)]
3221#[diag(lint_unused_visibilities)]
3222#[note]
3223pub(crate) struct UnusedVisibility {
3224    #[suggestion(style = "short", code = "", applicability = "machine-applicable")]
3225    pub span: Span,
3226}
3227
3228#[derive(LintDiagnostic)]
3229#[diag(lint_doc_alias_duplicated)]
3230pub(crate) struct DocAliasDuplicated {
3231    #[label]
3232    pub first_defn: Span,
3233}
3234
3235#[derive(LintDiagnostic)]
3236#[diag(lint_doc_auto_cfg_expects_hide_or_show)]
3237pub(crate) struct DocAutoCfgExpectsHideOrShow;
3238
3239#[derive(LintDiagnostic)]
3240#[diag(lint_doc_auto_cfg_hide_show_unexpected_item)]
3241pub(crate) struct DocAutoCfgHideShowUnexpectedItem {
3242    pub attr_name: Symbol,
3243}
3244
3245#[derive(LintDiagnostic)]
3246#[diag(lint_doc_auto_cfg_hide_show_expects_list)]
3247pub(crate) struct DocAutoCfgHideShowExpectsList {
3248    pub attr_name: Symbol,
3249}
3250
3251#[derive(LintDiagnostic)]
3252#[diag(lint_doc_invalid)]
3253pub(crate) struct DocInvalid;
3254
3255#[derive(LintDiagnostic)]
3256#[diag(lint_doc_unknown_include)]
3257pub(crate) struct DocUnknownInclude {
3258    pub inner: &'static str,
3259    pub value: Symbol,
3260    #[suggestion(code = "#{inner}[doc = include_str!(\"{value}\")]")]
3261    pub sugg: (Span, Applicability),
3262}
3263
3264#[derive(LintDiagnostic)]
3265#[diag(lint_doc_unknown_spotlight)]
3266#[note]
3267#[note(lint_no_op_note)]
3268pub(crate) struct DocUnknownSpotlight {
3269    #[suggestion(style = "short", applicability = "machine-applicable", code = "notable_trait")]
3270    pub sugg_span: Span,
3271}
3272
3273#[derive(LintDiagnostic)]
3274#[diag(lint_doc_unknown_passes)]
3275#[note]
3276#[note(lint_no_op_note)]
3277pub(crate) struct DocUnknownPasses {
3278    pub name: Symbol,
3279    #[label]
3280    pub note_span: Span,
3281}
3282
3283#[derive(LintDiagnostic)]
3284#[diag(lint_doc_unknown_plugins)]
3285#[note]
3286#[note(lint_no_op_note)]
3287pub(crate) struct DocUnknownPlugins {
3288    #[label]
3289    pub label_span: Span,
3290}
3291
3292#[derive(LintDiagnostic)]
3293#[diag(lint_doc_unknown_any)]
3294pub(crate) struct DocUnknownAny {
3295    pub name: Symbol,
3296}
3297
3298#[derive(LintDiagnostic)]
3299#[diag(lint_doc_auto_cfg_wrong_literal)]
3300pub(crate) struct DocAutoCfgWrongLiteral;
3301
3302#[derive(LintDiagnostic)]
3303#[diag(lint_doc_test_takes_list)]
3304pub(crate) struct DocTestTakesList;
3305
3306#[derive(LintDiagnostic)]
3307#[diag(lint_doc_test_unknown)]
3308pub(crate) struct DocTestUnknown {
3309    pub name: Symbol,
3310}
3311
3312#[derive(LintDiagnostic)]
3313#[diag(lint_doc_test_literal)]
3314pub(crate) struct DocTestLiteral;