rustc_hir_analysis/
errors.rs

1//! Errors emitted by `rustc_hir_analysis`.
2
3use rustc_abi::ExternAbi;
4use rustc_errors::codes::*;
5use rustc_errors::{
6    Applicability, Diag, DiagCtxtHandle, DiagSymbolList, Diagnostic, EmissionGuarantee, Level,
7    MultiSpan,
8};
9use rustc_hir::limit::Limit;
10use rustc_macros::{Diagnostic, LintDiagnostic, Subdiagnostic};
11use rustc_middle::ty::Ty;
12use rustc_span::{Ident, Span, Symbol};
13
14use crate::fluent_generated as fluent;
15pub(crate) mod wrong_number_of_generic_args;
16
17mod precise_captures;
18pub(crate) use precise_captures::*;
19
20#[derive(Diagnostic)]
21#[diag(hir_analysis_ambiguous_assoc_item)]
22pub(crate) struct AmbiguousAssocItem<'a> {
23    #[primary_span]
24    #[label]
25    pub span: Span,
26    pub assoc_kind: &'static str,
27    pub assoc_ident: Ident,
28    pub qself: &'a str,
29}
30
31#[derive(Diagnostic)]
32#[diag(hir_analysis_assoc_kind_mismatch)]
33pub(crate) struct AssocKindMismatch {
34    #[primary_span]
35    #[label]
36    pub span: Span,
37    pub expected: &'static str,
38    pub got: &'static str,
39    #[label(hir_analysis_expected_because_label)]
40    pub expected_because_label: Option<Span>,
41    pub assoc_kind: &'static str,
42    #[note]
43    pub def_span: Span,
44    #[label(hir_analysis_bound_on_assoc_const_label)]
45    pub bound_on_assoc_const_label: Option<Span>,
46    #[subdiagnostic]
47    pub wrap_in_braces_sugg: Option<AssocKindMismatchWrapInBracesSugg>,
48}
49
50#[derive(Subdiagnostic)]
51#[multipart_suggestion(
52    hir_analysis_assoc_kind_mismatch_wrap_in_braces_sugg,
53    applicability = "maybe-incorrect"
54)]
55pub(crate) struct AssocKindMismatchWrapInBracesSugg {
56    #[suggestion_part(code = "{{ ")]
57    pub lo: Span,
58    #[suggestion_part(code = " }}")]
59    pub hi: Span,
60}
61
62#[derive(Diagnostic)]
63#[diag(hir_analysis_assoc_item_is_private, code = E0624)]
64pub(crate) struct AssocItemIsPrivate {
65    #[primary_span]
66    #[label]
67    pub span: Span,
68    pub kind: &'static str,
69    pub name: Ident,
70    #[label(hir_analysis_defined_here_label)]
71    pub defined_here_label: Span,
72}
73
74#[derive(Diagnostic)]
75#[diag(hir_analysis_assoc_item_not_found, code = E0220)]
76pub(crate) struct AssocItemNotFound<'a> {
77    #[primary_span]
78    pub span: Span,
79    pub assoc_ident: Ident,
80    pub assoc_kind: &'static str,
81    pub qself: &'a str,
82    #[subdiagnostic]
83    pub label: Option<AssocItemNotFoundLabel<'a>>,
84    #[subdiagnostic]
85    pub sugg: Option<AssocItemNotFoundSugg<'a>>,
86    #[label(hir_analysis_within_macro)]
87    pub within_macro_span: Option<Span>,
88}
89
90#[derive(Subdiagnostic)]
91pub(crate) enum AssocItemNotFoundLabel<'a> {
92    #[label(hir_analysis_assoc_item_not_found_label)]
93    NotFound {
94        #[primary_span]
95        span: Span,
96    },
97    #[label(hir_analysis_assoc_item_not_found_found_in_other_trait_label)]
98    FoundInOtherTrait {
99        #[primary_span]
100        span: Span,
101        assoc_kind: &'static str,
102        trait_name: &'a str,
103        suggested_name: Symbol,
104        identically_named: bool,
105    },
106}
107
108#[derive(Subdiagnostic)]
109
110pub(crate) enum AssocItemNotFoundSugg<'a> {
111    #[suggestion(
112        hir_analysis_assoc_item_not_found_similar_sugg,
113        code = "{suggested_name}",
114        applicability = "maybe-incorrect"
115    )]
116    Similar {
117        #[primary_span]
118        span: Span,
119        assoc_kind: &'static str,
120        suggested_name: Symbol,
121    },
122    #[suggestion(
123        hir_analysis_assoc_item_not_found_similar_in_other_trait_sugg,
124        code = "{suggested_name}",
125        style = "verbose",
126        applicability = "maybe-incorrect"
127    )]
128    SimilarInOtherTrait {
129        #[primary_span]
130        span: Span,
131        trait_name: &'a str,
132        assoc_kind: &'static str,
133        suggested_name: Symbol,
134    },
135    #[multipart_suggestion(
136        hir_analysis_assoc_item_not_found_similar_in_other_trait_qpath_sugg,
137        style = "verbose"
138    )]
139    SimilarInOtherTraitQPath {
140        #[suggestion_part(code = "<")]
141        lo: Span,
142        #[suggestion_part(code = " as {trait_ref}>")]
143        mi: Span,
144        #[suggestion_part(code = "{suggested_name}")]
145        hi: Option<Span>,
146        trait_ref: String,
147        suggested_name: Symbol,
148        identically_named: bool,
149        #[applicability]
150        applicability: Applicability,
151    },
152    #[suggestion(
153        hir_analysis_assoc_item_not_found_other_sugg,
154        code = "{suggested_name}",
155        applicability = "maybe-incorrect"
156    )]
157    Other {
158        #[primary_span]
159        span: Span,
160        qself: &'a str,
161        assoc_kind: &'static str,
162        suggested_name: Symbol,
163    },
164}
165
166#[derive(Diagnostic)]
167#[diag(hir_analysis_wrong_number_of_generic_arguments_to_intrinsic, code = E0094)]
168pub(crate) struct WrongNumberOfGenericArgumentsToIntrinsic<'a> {
169    #[primary_span]
170    #[label]
171    pub span: Span,
172    pub found: usize,
173    pub expected: usize,
174    pub descr: &'a str,
175}
176
177#[derive(Diagnostic)]
178#[diag(hir_analysis_unrecognized_intrinsic_function, code = E0093)]
179#[help]
180pub(crate) struct UnrecognizedIntrinsicFunction {
181    #[primary_span]
182    #[label]
183    pub span: Span,
184    pub name: Symbol,
185}
186
187#[derive(Diagnostic)]
188#[diag(hir_analysis_lifetimes_or_bounds_mismatch_on_trait, code = E0195)]
189pub(crate) struct LifetimesOrBoundsMismatchOnTrait {
190    #[primary_span]
191    #[label]
192    pub span: Span,
193    #[label(hir_analysis_generics_label)]
194    pub generics_span: Span,
195    #[label(hir_analysis_where_label)]
196    pub where_span: Option<Span>,
197    #[label(hir_analysis_bounds_label)]
198    pub bounds_span: Vec<Span>,
199    pub item_kind: &'static str,
200    pub ident: Ident,
201}
202
203#[derive(Diagnostic)]
204#[diag(hir_analysis_drop_impl_on_wrong_item, code = E0120)]
205pub(crate) struct DropImplOnWrongItem {
206    #[primary_span]
207    #[label]
208    pub span: Span,
209    pub trait_: Symbol,
210}
211
212#[derive(Diagnostic)]
213pub(crate) enum FieldAlreadyDeclared {
214    #[diag(hir_analysis_field_already_declared, code = E0124)]
215    NotNested {
216        field_name: Ident,
217        #[primary_span]
218        #[label]
219        span: Span,
220        #[label(hir_analysis_previous_decl_label)]
221        prev_span: Span,
222    },
223    #[diag(hir_analysis_field_already_declared_current_nested)]
224    CurrentNested {
225        field_name: Ident,
226        #[primary_span]
227        #[label]
228        span: Span,
229        #[note(hir_analysis_nested_field_decl_note)]
230        nested_field_span: Span,
231        #[subdiagnostic]
232        help: FieldAlreadyDeclaredNestedHelp,
233        #[label(hir_analysis_previous_decl_label)]
234        prev_span: Span,
235    },
236    #[diag(hir_analysis_field_already_declared_previous_nested)]
237    PreviousNested {
238        field_name: Ident,
239        #[primary_span]
240        #[label]
241        span: Span,
242        #[label(hir_analysis_previous_decl_label)]
243        prev_span: Span,
244        #[note(hir_analysis_previous_nested_field_decl_note)]
245        prev_nested_field_span: Span,
246        #[subdiagnostic]
247        prev_help: FieldAlreadyDeclaredNestedHelp,
248    },
249    #[diag(hir_analysis_field_already_declared_both_nested)]
250    BothNested {
251        field_name: Ident,
252        #[primary_span]
253        #[label]
254        span: Span,
255        #[note(hir_analysis_nested_field_decl_note)]
256        nested_field_span: Span,
257        #[subdiagnostic]
258        help: FieldAlreadyDeclaredNestedHelp,
259        #[label(hir_analysis_previous_decl_label)]
260        prev_span: Span,
261        #[note(hir_analysis_previous_nested_field_decl_note)]
262        prev_nested_field_span: Span,
263        #[subdiagnostic]
264        prev_help: FieldAlreadyDeclaredNestedHelp,
265    },
266}
267
268#[derive(Subdiagnostic)]
269#[help(hir_analysis_field_already_declared_nested_help)]
270pub(crate) struct FieldAlreadyDeclaredNestedHelp {
271    #[primary_span]
272    pub span: Span,
273}
274
275#[derive(Diagnostic)]
276#[diag(hir_analysis_copy_impl_on_type_with_dtor, code = E0184)]
277pub(crate) struct CopyImplOnTypeWithDtor {
278    #[primary_span]
279    #[label]
280    pub span: Span,
281}
282
283#[derive(Diagnostic)]
284#[diag(hir_analysis_copy_impl_on_non_adt, code = E0206)]
285pub(crate) struct CopyImplOnNonAdt {
286    #[primary_span]
287    #[label]
288    pub span: Span,
289}
290
291#[derive(Diagnostic)]
292#[diag(hir_analysis_const_param_ty_impl_on_unsized)]
293pub(crate) struct ConstParamTyImplOnUnsized {
294    #[primary_span]
295    #[label]
296    pub span: Span,
297}
298
299#[derive(Diagnostic)]
300#[diag(hir_analysis_const_param_ty_impl_on_non_adt)]
301pub(crate) struct ConstParamTyImplOnNonAdt {
302    #[primary_span]
303    #[label]
304    pub span: Span,
305}
306
307#[derive(Diagnostic)]
308#[diag(hir_analysis_trait_object_declared_with_no_traits, code = E0224)]
309pub(crate) struct TraitObjectDeclaredWithNoTraits {
310    #[primary_span]
311    pub span: Span,
312    #[label(hir_analysis_alias_span)]
313    pub trait_alias_span: Option<Span>,
314}
315
316#[derive(Diagnostic)]
317#[diag(hir_analysis_ambiguous_lifetime_bound, code = E0227)]
318pub(crate) struct AmbiguousLifetimeBound {
319    #[primary_span]
320    pub span: Span,
321}
322
323#[derive(Diagnostic)]
324#[diag(hir_analysis_assoc_item_constraints_not_allowed_here, code = E0229)]
325pub(crate) struct AssocItemConstraintsNotAllowedHere {
326    #[primary_span]
327    #[label]
328    pub span: Span,
329
330    #[subdiagnostic]
331    pub fn_trait_expansion: Option<ParenthesizedFnTraitExpansion>,
332}
333
334#[derive(Diagnostic)]
335#[diag(hir_analysis_param_in_ty_of_assoc_const_binding)]
336pub(crate) struct ParamInTyOfAssocConstBinding<'tcx> {
337    #[primary_span]
338    #[label]
339    pub span: Span,
340    pub assoc_const: Ident,
341    pub param_name: Symbol,
342    pub param_def_kind: &'static str,
343    pub param_category: &'static str,
344    #[label(hir_analysis_param_defined_here_label)]
345    pub param_defined_here_label: Option<Span>,
346    #[subdiagnostic]
347    pub ty_note: Option<TyOfAssocConstBindingNote<'tcx>>,
348}
349
350#[derive(Subdiagnostic, Clone, Copy)]
351#[note(hir_analysis_ty_of_assoc_const_binding_note)]
352pub(crate) struct TyOfAssocConstBindingNote<'tcx> {
353    pub assoc_const: Ident,
354    pub ty: Ty<'tcx>,
355}
356
357#[derive(Diagnostic)]
358#[diag(hir_analysis_escaping_bound_var_in_ty_of_assoc_const_binding)]
359pub(crate) struct EscapingBoundVarInTyOfAssocConstBinding<'tcx> {
360    #[primary_span]
361    #[label]
362    pub span: Span,
363    pub assoc_const: Ident,
364    pub var_name: Symbol,
365    pub var_def_kind: &'static str,
366    #[label(hir_analysis_var_defined_here_label)]
367    pub var_defined_here_label: Span,
368    #[subdiagnostic]
369    pub ty_note: Option<TyOfAssocConstBindingNote<'tcx>>,
370}
371
372#[derive(Subdiagnostic)]
373#[help(hir_analysis_parenthesized_fn_trait_expansion)]
374pub(crate) struct ParenthesizedFnTraitExpansion {
375    #[primary_span]
376    pub span: Span,
377
378    pub expanded_type: String,
379}
380
381#[derive(Diagnostic)]
382#[diag(hir_analysis_value_of_associated_struct_already_specified, code = E0719)]
383pub(crate) struct ValueOfAssociatedStructAlreadySpecified {
384    #[primary_span]
385    #[label]
386    pub span: Span,
387    #[label(hir_analysis_previous_bound_label)]
388    pub prev_span: Span,
389    pub item_name: Ident,
390    pub def_path: String,
391}
392
393#[derive(Diagnostic)]
394#[diag(hir_analysis_unconstrained_opaque_type)]
395#[note]
396pub(crate) struct UnconstrainedOpaqueType {
397    #[primary_span]
398    pub span: Span,
399    pub name: Ident,
400    pub what: &'static str,
401}
402
403pub(crate) struct MissingTypeParams {
404    pub span: Span,
405    pub def_span: Span,
406    pub span_snippet: Option<String>,
407    pub missing_type_params: Vec<Symbol>,
408    pub empty_generic_args: bool,
409}
410
411// Manual implementation of `Diagnostic` to be able to call `span_to_snippet`.
412impl<'a, G: EmissionGuarantee> Diagnostic<'a, G> for MissingTypeParams {
413    #[track_caller]
414    fn into_diag(self, dcx: DiagCtxtHandle<'a>, level: Level) -> Diag<'a, G> {
415        let mut err = Diag::new(dcx, level, fluent::hir_analysis_missing_type_params);
416        err.span(self.span);
417        err.code(E0393);
418        err.arg("parameterCount", self.missing_type_params.len());
419        err.arg(
420            "parameters",
421            self.missing_type_params
422                .iter()
423                .map(|n| format!("`{n}`"))
424                .collect::<Vec<_>>()
425                .join(", "),
426        );
427
428        err.span_label(self.def_span, fluent::hir_analysis_label);
429
430        let mut suggested = false;
431        // Don't suggest setting the type params if there are some already: the order is
432        // tricky to get right and the user will already know what the syntax is.
433        if let Some(snippet) = self.span_snippet
434            && self.empty_generic_args
435        {
436            if snippet.ends_with('>') {
437                // The user wrote `Trait<'a, T>` or similar. To provide an accurate suggestion
438                // we would have to preserve the right order. For now, as clearly the user is
439                // aware of the syntax, we do nothing.
440            } else {
441                // The user wrote `Iterator`, so we don't have a type we can suggest, but at
442                // least we can clue them to the correct syntax `Iterator<Type>`.
443                err.span_suggestion_verbose(
444                    self.span.shrink_to_hi(),
445                    fluent::hir_analysis_suggestion,
446                    format!(
447                        "<{}>",
448                        self.missing_type_params
449                            .iter()
450                            .map(|n| n.to_string())
451                            .collect::<Vec<_>>()
452                            .join(", ")
453                    ),
454                    Applicability::HasPlaceholders,
455                );
456                suggested = true;
457            }
458        }
459        if !suggested {
460            err.span_label(self.span, fluent::hir_analysis_no_suggestion_label);
461        }
462
463        err.note(fluent::hir_analysis_note);
464        err
465    }
466}
467
468#[derive(Diagnostic)]
469#[diag(hir_analysis_manual_implementation, code = E0183)]
470#[help]
471pub(crate) struct ManualImplementation {
472    #[primary_span]
473    #[label]
474    pub span: Span,
475    pub trait_name: String,
476}
477
478#[derive(Diagnostic)]
479#[diag(hir_analysis_generic_args_on_overridden_impl)]
480pub(crate) struct GenericArgsOnOverriddenImpl {
481    #[primary_span]
482    pub span: Span,
483}
484
485#[derive(Diagnostic)]
486#[diag(hir_analysis_const_impl_for_non_const_trait)]
487pub(crate) struct ConstImplForNonConstTrait {
488    #[primary_span]
489    #[label]
490    pub trait_ref_span: Span,
491    pub trait_name: String,
492    #[suggestion(applicability = "machine-applicable", code = "const ", style = "verbose")]
493    pub suggestion: Option<Span>,
494    pub suggestion_pre: &'static str,
495    #[note]
496    pub marking: (),
497    #[note(hir_analysis_adding)]
498    pub adding: (),
499}
500
501#[derive(Diagnostic)]
502#[diag(hir_analysis_const_bound_for_non_const_trait)]
503pub(crate) struct ConstBoundForNonConstTrait {
504    #[primary_span]
505    #[label]
506    pub span: Span,
507    pub modifier: &'static str,
508    #[note]
509    pub def_span: Option<Span>,
510    #[suggestion(applicability = "machine-applicable", code = "const ", style = "verbose")]
511    pub suggestion: Option<Span>,
512    pub suggestion_pre: &'static str,
513    pub trait_name: String,
514}
515
516#[derive(Diagnostic)]
517#[diag(hir_analysis_self_in_impl_self)]
518pub(crate) struct SelfInImplSelf {
519    #[primary_span]
520    pub span: MultiSpan,
521    #[note]
522    pub note: (),
523}
524
525#[derive(Diagnostic)]
526#[diag(hir_analysis_linkage_type, code = E0791)]
527pub(crate) struct LinkageType {
528    #[primary_span]
529    pub span: Span,
530}
531
532#[derive(Diagnostic)]
533#[help]
534#[diag(hir_analysis_auto_deref_reached_recursion_limit, code = E0055)]
535pub(crate) struct AutoDerefReachedRecursionLimit<'a> {
536    #[primary_span]
537    #[label]
538    pub span: Span,
539    pub ty: Ty<'a>,
540    pub suggested_limit: Limit,
541    pub crate_name: Symbol,
542}
543
544#[derive(Diagnostic)]
545#[diag(hir_analysis_where_clause_on_main, code = E0646)]
546pub(crate) struct WhereClauseOnMain {
547    #[primary_span]
548    pub span: Span,
549    #[label]
550    pub generics_span: Option<Span>,
551}
552
553#[derive(Diagnostic)]
554#[diag(hir_analysis_track_caller_on_main)]
555pub(crate) struct TrackCallerOnMain {
556    #[primary_span]
557    #[suggestion(applicability = "maybe-incorrect", code = "")]
558    pub span: Span,
559    #[label(hir_analysis_track_caller_on_main)]
560    pub annotated: Span,
561}
562
563#[derive(Diagnostic)]
564#[diag(hir_analysis_target_feature_on_main)]
565pub(crate) struct TargetFeatureOnMain {
566    #[primary_span]
567    #[label(hir_analysis_target_feature_on_main)]
568    pub main: Span,
569}
570
571#[derive(Diagnostic)]
572#[diag(hir_analysis_main_function_return_type_generic, code = E0131)]
573pub(crate) struct MainFunctionReturnTypeGeneric {
574    #[primary_span]
575    pub span: Span,
576}
577
578#[derive(Diagnostic)]
579#[diag(hir_analysis_main_function_async, code = E0752)]
580pub(crate) struct MainFunctionAsync {
581    #[primary_span]
582    pub span: Span,
583    #[label]
584    pub asyncness: Option<Span>,
585}
586
587#[derive(Diagnostic)]
588#[diag(hir_analysis_main_function_generic_parameters, code = E0131)]
589pub(crate) struct MainFunctionGenericParameters {
590    #[primary_span]
591    pub span: Span,
592    #[label]
593    pub label_span: Option<Span>,
594}
595
596#[derive(Diagnostic)]
597#[diag(hir_analysis_variadic_function_compatible_convention, code = E0045)]
598pub(crate) struct VariadicFunctionCompatibleConvention<'a> {
599    #[primary_span]
600    #[label]
601    pub span: Span,
602    pub convention: &'a str,
603}
604
605#[derive(Diagnostic)]
606pub(crate) enum CannotCaptureLateBound {
607    #[diag(hir_analysis_cannot_capture_late_bound_ty)]
608    Type {
609        #[primary_span]
610        use_span: Span,
611        #[label]
612        def_span: Span,
613        what: &'static str,
614    },
615    #[diag(hir_analysis_cannot_capture_late_bound_const)]
616    Const {
617        #[primary_span]
618        use_span: Span,
619        #[label]
620        def_span: Span,
621        what: &'static str,
622    },
623    #[diag(hir_analysis_cannot_capture_late_bound_lifetime)]
624    Lifetime {
625        #[primary_span]
626        use_span: Span,
627        #[label]
628        def_span: Span,
629        what: &'static str,
630    },
631}
632
633#[derive(Diagnostic)]
634#[diag(hir_analysis_variances_of)]
635pub(crate) struct VariancesOf {
636    #[primary_span]
637    pub span: Span,
638    pub variances: String,
639}
640
641#[derive(Diagnostic)]
642#[diag(hir_analysis_type_of)]
643pub(crate) struct TypeOf<'tcx> {
644    #[primary_span]
645    pub span: Span,
646    pub ty: Ty<'tcx>,
647}
648
649#[derive(Diagnostic)]
650#[diag(hir_analysis_invalid_union_field, code = E0740)]
651pub(crate) struct InvalidUnionField {
652    #[primary_span]
653    pub field_span: Span,
654    #[subdiagnostic]
655    pub sugg: InvalidUnionFieldSuggestion,
656    #[note]
657    pub note: (),
658}
659
660#[derive(Diagnostic)]
661#[diag(hir_analysis_return_type_notation_on_non_rpitit)]
662pub(crate) struct ReturnTypeNotationOnNonRpitit<'tcx> {
663    #[primary_span]
664    pub span: Span,
665    pub ty: Ty<'tcx>,
666    #[label]
667    pub fn_span: Option<Span>,
668    #[note]
669    pub note: (),
670}
671
672#[derive(Subdiagnostic)]
673#[multipart_suggestion(hir_analysis_invalid_union_field_sugg, applicability = "machine-applicable")]
674pub(crate) struct InvalidUnionFieldSuggestion {
675    #[suggestion_part(code = "std::mem::ManuallyDrop<")]
676    pub lo: Span,
677    #[suggestion_part(code = ">")]
678    pub hi: Span,
679}
680
681#[derive(Diagnostic)]
682#[diag(hir_analysis_return_type_notation_equality_bound)]
683pub(crate) struct ReturnTypeNotationEqualityBound {
684    #[primary_span]
685    pub span: Span,
686}
687
688#[derive(Diagnostic)]
689#[diag(hir_analysis_placeholder_not_allowed_item_signatures, code = E0121)]
690pub(crate) struct PlaceholderNotAllowedItemSignatures {
691    #[primary_span]
692    #[label]
693    pub spans: Vec<Span>,
694    pub kind: String,
695}
696
697#[derive(Diagnostic)]
698#[diag(hir_analysis_associated_type_trait_uninferred_generic_params, code = E0212)]
699pub(crate) struct AssociatedItemTraitUninferredGenericParams {
700    #[primary_span]
701    pub span: Span,
702    #[suggestion(style = "verbose", applicability = "maybe-incorrect", code = "{bound}")]
703    pub inferred_sugg: Option<Span>,
704    pub bound: String,
705    #[subdiagnostic]
706    pub mpart_sugg: Option<AssociatedItemTraitUninferredGenericParamsMultipartSuggestion>,
707    pub what: &'static str,
708}
709
710#[derive(Subdiagnostic)]
711#[multipart_suggestion(
712    hir_analysis_associated_type_trait_uninferred_generic_params_multipart_suggestion,
713    applicability = "maybe-incorrect"
714)]
715pub(crate) struct AssociatedItemTraitUninferredGenericParamsMultipartSuggestion {
716    #[suggestion_part(code = "{first}")]
717    pub fspan: Span,
718    pub first: String,
719    #[suggestion_part(code = "{second}")]
720    pub sspan: Span,
721    pub second: String,
722}
723
724#[derive(Diagnostic)]
725#[diag(hir_analysis_enum_discriminant_overflowed, code = E0370)]
726#[note]
727pub(crate) struct EnumDiscriminantOverflowed {
728    #[primary_span]
729    #[label]
730    pub span: Span,
731    pub discr: String,
732    pub item_name: Ident,
733    pub wrapped_discr: String,
734}
735
736#[derive(Diagnostic)]
737#[diag(hir_analysis_paren_sugar_attribute)]
738#[help]
739pub(crate) struct ParenSugarAttribute {
740    #[primary_span]
741    pub span: Span,
742}
743
744#[derive(Diagnostic)]
745#[diag(hir_analysis_simd_ffi_highly_experimental)]
746#[help]
747pub(crate) struct SIMDFFIHighlyExperimental {
748    #[primary_span]
749    pub span: Span,
750    pub snip: String,
751}
752
753#[derive(Diagnostic)]
754pub(crate) enum ImplNotMarkedDefault {
755    #[diag(hir_analysis_impl_not_marked_default, code = E0520)]
756    #[note]
757    Ok {
758        #[primary_span]
759        #[label]
760        span: Span,
761        #[label(hir_analysis_ok_label)]
762        ok_label: Span,
763        ident: Ident,
764    },
765    #[diag(hir_analysis_impl_not_marked_default_err, code = E0520)]
766    #[note]
767    Err {
768        #[primary_span]
769        span: Span,
770        cname: Symbol,
771        ident: Ident,
772    },
773}
774
775#[derive(LintDiagnostic)]
776#[diag(hir_analysis_useless_impl_item)]
777pub(crate) struct UselessImplItem;
778
779#[derive(Diagnostic)]
780#[diag(hir_analysis_missing_trait_item, code = E0046)]
781pub(crate) struct MissingTraitItem {
782    #[primary_span]
783    #[label]
784    pub span: Span,
785    #[subdiagnostic]
786    pub missing_trait_item_label: Vec<MissingTraitItemLabel>,
787    #[subdiagnostic]
788    pub missing_trait_item: Vec<MissingTraitItemSuggestion>,
789    #[subdiagnostic]
790    pub missing_trait_item_none: Vec<MissingTraitItemSuggestionNone>,
791    pub missing_items_msg: String,
792}
793
794#[derive(Subdiagnostic)]
795#[label(hir_analysis_missing_trait_item_label)]
796pub(crate) struct MissingTraitItemLabel {
797    #[primary_span]
798    pub span: Span,
799    pub item: Symbol,
800}
801
802#[derive(Subdiagnostic)]
803#[suggestion(
804    hir_analysis_missing_trait_item_suggestion,
805    style = "tool-only",
806    applicability = "has-placeholders",
807    code = "{code}"
808)]
809pub(crate) struct MissingTraitItemSuggestion {
810    #[primary_span]
811    pub span: Span,
812    pub code: String,
813    pub snippet: String,
814}
815
816#[derive(Subdiagnostic)]
817#[suggestion(
818    hir_analysis_missing_trait_item_suggestion,
819    style = "hidden",
820    applicability = "has-placeholders",
821    code = "{code}"
822)]
823pub(crate) struct MissingTraitItemSuggestionNone {
824    #[primary_span]
825    pub span: Span,
826    pub code: String,
827    pub snippet: String,
828}
829
830#[derive(Diagnostic)]
831#[diag(hir_analysis_missing_one_of_trait_item, code = E0046)]
832pub(crate) struct MissingOneOfTraitItem {
833    #[primary_span]
834    #[label]
835    pub span: Span,
836    #[note]
837    pub note: Option<Span>,
838    pub missing_items_msg: String,
839}
840
841#[derive(Diagnostic)]
842#[diag(hir_analysis_missing_trait_item_unstable, code = E0046)]
843#[note]
844pub(crate) struct MissingTraitItemUnstable {
845    #[primary_span]
846    pub span: Span,
847    #[note(hir_analysis_some_note)]
848    pub some_note: bool,
849    #[note(hir_analysis_none_note)]
850    pub none_note: bool,
851    pub missing_item_name: Ident,
852    pub feature: Symbol,
853    pub reason: String,
854}
855
856#[derive(Diagnostic)]
857#[diag(hir_analysis_transparent_enum_variant, code = E0731)]
858pub(crate) struct TransparentEnumVariant {
859    #[primary_span]
860    #[label]
861    pub span: Span,
862    #[label(hir_analysis_multi_label)]
863    pub spans: Vec<Span>,
864    #[label(hir_analysis_many_label)]
865    pub many: Option<Span>,
866    pub number: usize,
867    pub path: String,
868}
869
870#[derive(Diagnostic)]
871#[diag(hir_analysis_transparent_non_zero_sized_enum, code = E0690)]
872pub(crate) struct TransparentNonZeroSizedEnum<'a> {
873    #[primary_span]
874    #[label]
875    pub span: Span,
876    #[label(hir_analysis_labels)]
877    pub spans: Vec<Span>,
878    pub field_count: usize,
879    pub desc: &'a str,
880}
881
882#[derive(Diagnostic)]
883#[diag(hir_analysis_transparent_non_zero_sized, code = E0690)]
884pub(crate) struct TransparentNonZeroSized<'a> {
885    #[primary_span]
886    #[label]
887    pub span: Span,
888    #[label(hir_analysis_labels)]
889    pub spans: Vec<Span>,
890    pub field_count: usize,
891    pub desc: &'a str,
892}
893
894#[derive(Diagnostic)]
895#[diag(hir_analysis_too_large_static)]
896pub(crate) struct TooLargeStatic {
897    #[primary_span]
898    pub span: Span,
899}
900
901#[derive(Diagnostic)]
902#[diag(hir_analysis_specialization_trait)]
903#[help]
904pub(crate) struct SpecializationTrait {
905    #[primary_span]
906    pub span: Span,
907}
908
909#[derive(Diagnostic)]
910#[diag(hir_analysis_closure_implicit_hrtb)]
911pub(crate) struct ClosureImplicitHrtb {
912    #[primary_span]
913    pub spans: Vec<Span>,
914    #[label]
915    pub for_sp: Span,
916}
917
918#[derive(Diagnostic)]
919#[diag(hir_analysis_empty_specialization)]
920pub(crate) struct EmptySpecialization {
921    #[primary_span]
922    pub span: Span,
923    #[note]
924    pub base_impl_span: Span,
925}
926
927#[derive(Diagnostic)]
928#[diag(hir_analysis_static_specialize)]
929pub(crate) struct StaticSpecialize {
930    #[primary_span]
931    pub span: Span,
932}
933
934#[derive(Diagnostic)]
935pub(crate) enum DropImplPolarity {
936    #[diag(hir_analysis_drop_impl_negative)]
937    Negative {
938        #[primary_span]
939        span: Span,
940    },
941    #[diag(hir_analysis_drop_impl_reservation)]
942    Reservation {
943        #[primary_span]
944        span: Span,
945    },
946}
947
948#[derive(Diagnostic)]
949pub(crate) enum ReturnTypeNotationIllegalParam {
950    #[diag(hir_analysis_return_type_notation_illegal_param_type)]
951    Type {
952        #[primary_span]
953        span: Span,
954        #[label]
955        param_span: Span,
956    },
957    #[diag(hir_analysis_return_type_notation_illegal_param_const)]
958    Const {
959        #[primary_span]
960        span: Span,
961        #[label]
962        param_span: Span,
963    },
964}
965
966#[derive(Diagnostic)]
967pub(crate) enum LateBoundInApit {
968    #[diag(hir_analysis_late_bound_type_in_apit)]
969    Type {
970        #[primary_span]
971        span: Span,
972        #[label]
973        param_span: Span,
974    },
975    #[diag(hir_analysis_late_bound_const_in_apit)]
976    Const {
977        #[primary_span]
978        span: Span,
979        #[label]
980        param_span: Span,
981    },
982    #[diag(hir_analysis_late_bound_lifetime_in_apit)]
983    Lifetime {
984        #[primary_span]
985        span: Span,
986        #[label]
987        param_span: Span,
988    },
989}
990
991#[derive(LintDiagnostic)]
992#[diag(hir_analysis_unused_associated_type_bounds)]
993#[note]
994pub(crate) struct UnusedAssociatedTypeBounds {
995    #[suggestion(code = "")]
996    pub span: Span,
997}
998
999#[derive(LintDiagnostic)]
1000#[diag(hir_analysis_rpitit_refined)]
1001#[note]
1002#[note(hir_analysis_feedback_note)]
1003pub(crate) struct ReturnPositionImplTraitInTraitRefined<'tcx> {
1004    #[suggestion(applicability = "maybe-incorrect", code = "{pre}{return_ty}{post}")]
1005    pub impl_return_span: Span,
1006    #[label]
1007    pub trait_return_span: Option<Span>,
1008    #[label(hir_analysis_unmatched_bound_label)]
1009    pub unmatched_bound: Option<Span>,
1010
1011    pub pre: &'static str,
1012    pub post: &'static str,
1013    pub return_ty: Ty<'tcx>,
1014}
1015
1016#[derive(LintDiagnostic)]
1017#[diag(hir_analysis_rpitit_refined_lifetimes)]
1018#[note]
1019#[note(hir_analysis_feedback_note)]
1020pub(crate) struct ReturnPositionImplTraitInTraitRefinedLifetimes {
1021    #[suggestion(applicability = "maybe-incorrect", code = "{suggestion}")]
1022    pub suggestion_span: Span,
1023    pub suggestion: String,
1024}
1025
1026#[derive(Diagnostic)]
1027#[diag(hir_analysis_inherent_ty_outside, code = E0390)]
1028#[help]
1029pub(crate) struct InherentTyOutside {
1030    #[primary_span]
1031    #[help(hir_analysis_span_help)]
1032    pub span: Span,
1033}
1034
1035#[derive(Diagnostic)]
1036#[diag(hir_analysis_dispatch_from_dyn_repr, code = E0378)]
1037pub(crate) struct DispatchFromDynRepr {
1038    #[primary_span]
1039    pub span: Span,
1040}
1041
1042#[derive(Diagnostic)]
1043#[diag(hir_analysis_coerce_pointee_not_struct, code = E0802)]
1044pub(crate) struct CoercePointeeNotStruct {
1045    #[primary_span]
1046    pub span: Span,
1047    pub kind: String,
1048}
1049
1050#[derive(Diagnostic)]
1051#[diag(hir_analysis_coerce_pointee_not_concrete_ty, code = E0802)]
1052pub(crate) struct CoercePointeeNotConcreteType {
1053    #[primary_span]
1054    pub span: Span,
1055}
1056
1057#[derive(Diagnostic)]
1058#[diag(hir_analysis_coerce_pointee_no_user_validity_assertion, code = E0802)]
1059pub(crate) struct CoercePointeeNoUserValidityAssertion {
1060    #[primary_span]
1061    pub span: Span,
1062}
1063
1064#[derive(Diagnostic)]
1065#[diag(hir_analysis_coerce_pointee_not_transparent, code = E0802)]
1066pub(crate) struct CoercePointeeNotTransparent {
1067    #[primary_span]
1068    pub span: Span,
1069}
1070
1071#[derive(Diagnostic)]
1072#[diag(hir_analysis_coerce_pointee_no_field, code = E0802)]
1073pub(crate) struct CoercePointeeNoField {
1074    #[primary_span]
1075    pub span: Span,
1076}
1077
1078#[derive(Diagnostic)]
1079#[diag(hir_analysis_inherent_ty_outside_relevant, code = E0390)]
1080#[help]
1081pub(crate) struct InherentTyOutsideRelevant {
1082    #[primary_span]
1083    pub span: Span,
1084    #[help(hir_analysis_span_help)]
1085    pub help_span: Span,
1086}
1087
1088#[derive(Diagnostic)]
1089#[diag(hir_analysis_inherent_ty_outside_new, code = E0116)]
1090#[note]
1091pub(crate) struct InherentTyOutsideNew {
1092    #[primary_span]
1093    #[label]
1094    pub span: Span,
1095}
1096
1097#[derive(Diagnostic)]
1098#[diag(hir_analysis_inherent_ty_outside_primitive, code = E0390)]
1099#[help]
1100pub(crate) struct InherentTyOutsidePrimitive {
1101    #[primary_span]
1102    pub span: Span,
1103    #[help(hir_analysis_span_help)]
1104    pub help_span: Span,
1105}
1106
1107#[derive(Diagnostic)]
1108#[diag(hir_analysis_inherent_primitive_ty, code = E0390)]
1109#[help]
1110pub(crate) struct InherentPrimitiveTy<'a> {
1111    #[primary_span]
1112    pub span: Span,
1113    #[subdiagnostic]
1114    pub note: Option<InherentPrimitiveTyNote<'a>>,
1115}
1116
1117#[derive(Subdiagnostic)]
1118#[note(hir_analysis_inherent_primitive_ty_note)]
1119pub(crate) struct InherentPrimitiveTyNote<'a> {
1120    pub subty: Ty<'a>,
1121}
1122
1123#[derive(Diagnostic)]
1124#[diag(hir_analysis_inherent_dyn, code = E0785)]
1125#[note]
1126pub(crate) struct InherentDyn {
1127    #[primary_span]
1128    #[label]
1129    pub span: Span,
1130}
1131
1132#[derive(Diagnostic)]
1133#[diag(hir_analysis_inherent_nominal, code = E0118)]
1134#[note]
1135pub(crate) struct InherentNominal {
1136    #[primary_span]
1137    #[label]
1138    pub span: Span,
1139}
1140
1141#[derive(Diagnostic)]
1142#[diag(hir_analysis_dispatch_from_dyn_zst, code = E0378)]
1143#[note]
1144pub(crate) struct DispatchFromDynZST<'a> {
1145    #[primary_span]
1146    pub span: Span,
1147    pub name: Ident,
1148    pub ty: Ty<'a>,
1149}
1150
1151#[derive(Diagnostic)]
1152#[diag(hir_analysis_coerce_zero, code = E0374)]
1153pub(crate) struct CoerceNoField {
1154    #[primary_span]
1155    pub span: Span,
1156    pub trait_name: &'static str,
1157    #[note(hir_analysis_coercion_between_struct_single_note)]
1158    pub note: bool,
1159}
1160
1161#[derive(Diagnostic)]
1162#[diag(hir_analysis_coerce_multi, code = E0375)]
1163pub(crate) struct CoerceMulti {
1164    pub trait_name: &'static str,
1165    #[primary_span]
1166    pub span: Span,
1167    pub number: usize,
1168    #[note]
1169    pub fields: MultiSpan,
1170}
1171
1172#[derive(Diagnostic)]
1173#[diag(hir_analysis_coerce_unsized_may, code = E0377)]
1174pub(crate) struct CoerceUnsizedNonStruct {
1175    #[primary_span]
1176    pub span: Span,
1177    pub trait_name: &'static str,
1178}
1179
1180#[derive(Diagnostic)]
1181#[diag(hir_analysis_coerce_same_pat_kind)]
1182pub(crate) struct CoerceSamePatKind {
1183    #[primary_span]
1184    pub span: Span,
1185    pub trait_name: &'static str,
1186    pub pat_a: String,
1187    pub pat_b: String,
1188}
1189
1190#[derive(Diagnostic)]
1191#[diag(hir_analysis_coerce_unsized_may, code = E0377)]
1192pub(crate) struct CoerceSameStruct {
1193    #[primary_span]
1194    pub span: Span,
1195    pub trait_name: &'static str,
1196    #[note(hir_analysis_coercion_between_struct_same_note)]
1197    pub note: bool,
1198    pub source_path: String,
1199    pub target_path: String,
1200}
1201
1202#[derive(Diagnostic)]
1203#[diag(hir_analysis_coerce_unsized_field_validity)]
1204pub(crate) struct CoerceFieldValidity<'tcx> {
1205    #[primary_span]
1206    pub span: Span,
1207    pub ty: Ty<'tcx>,
1208    pub trait_name: &'static str,
1209    #[label]
1210    pub field_span: Span,
1211    pub field_ty: Ty<'tcx>,
1212}
1213
1214#[derive(Diagnostic)]
1215#[diag(hir_analysis_trait_cannot_impl_for_ty, code = E0204)]
1216pub(crate) struct TraitCannotImplForTy {
1217    #[primary_span]
1218    pub span: Span,
1219    pub trait_name: String,
1220    #[label]
1221    pub label_spans: Vec<Span>,
1222    #[subdiagnostic]
1223    pub notes: Vec<ImplForTyRequires>,
1224}
1225
1226#[derive(Subdiagnostic)]
1227#[note(hir_analysis_requires_note)]
1228pub(crate) struct ImplForTyRequires {
1229    #[primary_span]
1230    pub span: MultiSpan,
1231    pub error_predicate: String,
1232    pub trait_name: String,
1233    pub ty: String,
1234}
1235
1236#[derive(Diagnostic)]
1237#[diag(hir_analysis_traits_with_default_impl, code = E0321)]
1238#[note]
1239pub(crate) struct TraitsWithDefaultImpl<'a> {
1240    #[primary_span]
1241    pub span: Span,
1242    pub traits: String,
1243    pub problematic_kind: &'a str,
1244    pub self_ty: Ty<'a>,
1245}
1246
1247#[derive(Diagnostic)]
1248#[diag(hir_analysis_cross_crate_traits, code = E0321)]
1249pub(crate) struct CrossCrateTraits<'a> {
1250    #[primary_span]
1251    #[label]
1252    pub span: Span,
1253    pub traits: String,
1254    pub self_ty: Ty<'a>,
1255}
1256
1257#[derive(Diagnostic)]
1258#[diag(hir_analysis_cross_crate_traits_defined, code = E0321)]
1259pub(crate) struct CrossCrateTraitsDefined {
1260    #[primary_span]
1261    #[label]
1262    pub span: Span,
1263    pub traits: String,
1264}
1265
1266#[derive(Diagnostic)]
1267#[diag(hir_analysis_no_variant_named, code = E0599)]
1268pub struct NoVariantNamed<'tcx> {
1269    #[primary_span]
1270    pub span: Span,
1271    pub ident: Ident,
1272    pub ty: Ty<'tcx>,
1273}
1274
1275// FIXME(fmease): Deduplicate:
1276
1277#[derive(Diagnostic)]
1278#[diag(hir_analysis_ty_param_first_local, code = E0210)]
1279#[note]
1280pub(crate) struct TyParamFirstLocal<'tcx> {
1281    #[primary_span]
1282    #[label]
1283    pub span: Span,
1284    #[note(hir_analysis_case_note)]
1285    pub note: (),
1286    pub param: Ident,
1287    pub local_type: Ty<'tcx>,
1288}
1289
1290#[derive(LintDiagnostic)]
1291#[diag(hir_analysis_ty_param_first_local, code = E0210)]
1292#[note]
1293pub(crate) struct TyParamFirstLocalLint<'tcx> {
1294    #[label]
1295    pub span: Span,
1296    #[note(hir_analysis_case_note)]
1297    pub note: (),
1298    pub param: Ident,
1299    pub local_type: Ty<'tcx>,
1300}
1301
1302#[derive(Diagnostic)]
1303#[diag(hir_analysis_ty_param_some, code = E0210)]
1304#[note]
1305pub(crate) struct TyParamSome {
1306    #[primary_span]
1307    #[label]
1308    pub span: Span,
1309    #[note(hir_analysis_only_note)]
1310    pub note: (),
1311    pub param: Ident,
1312}
1313
1314#[derive(LintDiagnostic)]
1315#[diag(hir_analysis_ty_param_some, code = E0210)]
1316#[note]
1317pub(crate) struct TyParamSomeLint {
1318    #[label]
1319    pub span: Span,
1320    #[note(hir_analysis_only_note)]
1321    pub note: (),
1322    pub param: Ident,
1323}
1324
1325#[derive(Diagnostic)]
1326pub(crate) enum OnlyCurrentTraits {
1327    #[diag(hir_analysis_only_current_traits_outside, code = E0117)]
1328    Outside {
1329        #[primary_span]
1330        span: Span,
1331        #[note(hir_analysis_only_current_traits_note_uncovered)]
1332        #[note(hir_analysis_only_current_traits_note_more_info)]
1333        #[note(hir_analysis_only_current_traits_note)]
1334        note: (),
1335    },
1336    #[diag(hir_analysis_only_current_traits_primitive, code = E0117)]
1337    Primitive {
1338        #[primary_span]
1339        span: Span,
1340        #[note(hir_analysis_only_current_traits_note_uncovered)]
1341        #[note(hir_analysis_only_current_traits_note_more_info)]
1342        #[note(hir_analysis_only_current_traits_note)]
1343        note: (),
1344    },
1345    #[diag(hir_analysis_only_current_traits_arbitrary, code = E0117)]
1346    Arbitrary {
1347        #[primary_span]
1348        span: Span,
1349        #[note(hir_analysis_only_current_traits_note_uncovered)]
1350        #[note(hir_analysis_only_current_traits_note_more_info)]
1351        #[note(hir_analysis_only_current_traits_note)]
1352        note: (),
1353    },
1354}
1355
1356#[derive(Subdiagnostic)]
1357#[label(hir_analysis_only_current_traits_opaque)]
1358pub(crate) struct OnlyCurrentTraitsOpaque {
1359    #[primary_span]
1360    pub span: Span,
1361}
1362#[derive(Subdiagnostic)]
1363#[label(hir_analysis_only_current_traits_foreign)]
1364pub(crate) struct OnlyCurrentTraitsForeign {
1365    #[primary_span]
1366    pub span: Span,
1367}
1368
1369#[derive(Subdiagnostic)]
1370#[label(hir_analysis_only_current_traits_name)]
1371pub(crate) struct OnlyCurrentTraitsName<'a> {
1372    #[primary_span]
1373    pub span: Span,
1374    pub name: &'a str,
1375}
1376
1377#[derive(Subdiagnostic)]
1378#[label(hir_analysis_only_current_traits_pointer)]
1379pub(crate) struct OnlyCurrentTraitsPointer<'a> {
1380    #[primary_span]
1381    pub span: Span,
1382    pub pointer: Ty<'a>,
1383}
1384
1385#[derive(Subdiagnostic)]
1386#[label(hir_analysis_only_current_traits_ty)]
1387pub(crate) struct OnlyCurrentTraitsTy<'a> {
1388    #[primary_span]
1389    pub span: Span,
1390    pub ty: Ty<'a>,
1391}
1392
1393#[derive(Subdiagnostic)]
1394#[label(hir_analysis_only_current_traits_adt)]
1395pub(crate) struct OnlyCurrentTraitsAdt {
1396    #[primary_span]
1397    pub span: Span,
1398    pub name: String,
1399}
1400
1401#[derive(Subdiagnostic)]
1402#[multipart_suggestion(
1403    hir_analysis_only_current_traits_pointer_sugg,
1404    applicability = "maybe-incorrect"
1405)]
1406pub(crate) struct OnlyCurrentTraitsPointerSugg<'a> {
1407    #[suggestion_part(code = "WrapperType")]
1408    pub wrapper_span: Span,
1409    #[suggestion_part(code = "struct WrapperType(*{mut_key}{ptr_ty});\n\n")]
1410    pub(crate) struct_span: Span,
1411    pub mut_key: &'a str,
1412    pub ptr_ty: Ty<'a>,
1413}
1414
1415#[derive(Diagnostic)]
1416#[diag(hir_analysis_not_supported_delegation)]
1417pub(crate) struct UnsupportedDelegation<'a> {
1418    #[primary_span]
1419    pub span: Span,
1420    pub descr: &'a str,
1421    #[label]
1422    pub callee_span: Span,
1423}
1424
1425#[derive(Diagnostic)]
1426#[diag(hir_analysis_method_should_return_future)]
1427pub(crate) struct MethodShouldReturnFuture {
1428    #[primary_span]
1429    pub span: Span,
1430    pub method_name: Ident,
1431    #[note]
1432    pub trait_item_span: Option<Span>,
1433}
1434
1435#[derive(Diagnostic)]
1436#[diag(hir_analysis_unused_generic_parameter)]
1437pub(crate) struct UnusedGenericParameter {
1438    #[primary_span]
1439    #[label]
1440    pub span: Span,
1441    pub param_name: Ident,
1442    pub param_def_kind: &'static str,
1443    #[label(hir_analysis_usage_spans)]
1444    pub usage_spans: Vec<Span>,
1445    #[subdiagnostic]
1446    pub help: UnusedGenericParameterHelp,
1447    #[help(hir_analysis_const_param_help)]
1448    pub const_param_help: bool,
1449}
1450
1451#[derive(Diagnostic)]
1452#[diag(hir_analysis_recursive_generic_parameter)]
1453pub(crate) struct RecursiveGenericParameter {
1454    #[primary_span]
1455    pub spans: Vec<Span>,
1456    #[label]
1457    pub param_span: Span,
1458    pub param_name: Ident,
1459    pub param_def_kind: &'static str,
1460    #[subdiagnostic]
1461    pub help: UnusedGenericParameterHelp,
1462    #[note]
1463    pub note: (),
1464}
1465
1466#[derive(Subdiagnostic)]
1467pub(crate) enum UnusedGenericParameterHelp {
1468    #[help(hir_analysis_unused_generic_parameter_adt_help)]
1469    Adt { param_name: Ident, phantom_data: String },
1470    #[help(hir_analysis_unused_generic_parameter_adt_no_phantom_data_help)]
1471    AdtNoPhantomData { param_name: Ident },
1472    #[help(hir_analysis_unused_generic_parameter_ty_alias_help)]
1473    TyAlias { param_name: Ident },
1474}
1475
1476#[derive(Diagnostic)]
1477#[diag(hir_analysis_unconstrained_generic_parameter)]
1478pub(crate) struct UnconstrainedGenericParameter {
1479    #[primary_span]
1480    #[label]
1481    pub span: Span,
1482    pub param_name: Ident,
1483    pub param_def_kind: &'static str,
1484    #[note(hir_analysis_const_param_note)]
1485    pub const_param_note: bool,
1486    #[note(hir_analysis_const_param_note2)]
1487    pub const_param_note2: bool,
1488}
1489
1490#[derive(Diagnostic)]
1491#[diag(hir_analysis_opaque_captures_higher_ranked_lifetime, code = E0657)]
1492pub(crate) struct OpaqueCapturesHigherRankedLifetime {
1493    #[primary_span]
1494    pub span: MultiSpan,
1495    #[label]
1496    pub label: Option<Span>,
1497    #[note]
1498    pub decl_span: MultiSpan,
1499    pub bad_place: &'static str,
1500}
1501
1502#[derive(Subdiagnostic)]
1503pub(crate) enum InvalidReceiverTyHint {
1504    #[note(hir_analysis_invalid_receiver_ty_help_weak_note)]
1505    Weak,
1506    #[note(hir_analysis_invalid_receiver_ty_help_nonnull_note)]
1507    NonNull,
1508}
1509
1510#[derive(Diagnostic)]
1511#[diag(hir_analysis_invalid_receiver_ty_no_arbitrary_self_types, code = E0307)]
1512#[note]
1513#[help(hir_analysis_invalid_receiver_ty_help_no_arbitrary_self_types)]
1514pub(crate) struct InvalidReceiverTyNoArbitrarySelfTypes<'tcx> {
1515    #[primary_span]
1516    pub span: Span,
1517    pub receiver_ty: Ty<'tcx>,
1518}
1519
1520#[derive(Diagnostic)]
1521#[diag(hir_analysis_invalid_receiver_ty, code = E0307)]
1522#[note]
1523#[help(hir_analysis_invalid_receiver_ty_help)]
1524pub(crate) struct InvalidReceiverTy<'tcx> {
1525    #[primary_span]
1526    pub span: Span,
1527    pub receiver_ty: Ty<'tcx>,
1528    #[subdiagnostic]
1529    pub hint: Option<InvalidReceiverTyHint>,
1530}
1531
1532#[derive(Diagnostic)]
1533#[diag(hir_analysis_invalid_generic_receiver_ty, code = E0801)]
1534#[note]
1535#[help(hir_analysis_invalid_generic_receiver_ty_help)]
1536pub(crate) struct InvalidGenericReceiverTy<'tcx> {
1537    #[primary_span]
1538    pub span: Span,
1539    pub receiver_ty: Ty<'tcx>,
1540}
1541
1542#[derive(Diagnostic)]
1543#[diag(hir_analysis_cmse_inputs_stack_spill, code = E0798)]
1544#[note]
1545pub(crate) struct CmseInputsStackSpill {
1546    #[primary_span]
1547    #[label]
1548    pub spans: Vec<Span>,
1549    pub abi: ExternAbi,
1550}
1551
1552#[derive(Diagnostic)]
1553#[diag(hir_analysis_cmse_output_stack_spill, code = E0798)]
1554#[note(hir_analysis_note1)]
1555#[note(hir_analysis_note2)]
1556pub(crate) struct CmseOutputStackSpill {
1557    #[primary_span]
1558    #[label]
1559    pub span: Span,
1560    pub abi: ExternAbi,
1561}
1562
1563#[derive(Diagnostic)]
1564#[diag(hir_analysis_cmse_generic, code = E0798)]
1565pub(crate) struct CmseGeneric {
1566    #[primary_span]
1567    pub span: Span,
1568    pub abi: ExternAbi,
1569}
1570
1571#[derive(Diagnostic)]
1572#[diag(hir_analysis_cmse_impl_trait, code = E0798)]
1573pub(crate) struct CmseImplTrait {
1574    #[primary_span]
1575    pub span: Span,
1576    pub abi: ExternAbi,
1577}
1578
1579#[derive(Diagnostic)]
1580#[diag(hir_analysis_bad_return_type_notation_position)]
1581pub(crate) struct BadReturnTypeNotation {
1582    #[primary_span]
1583    pub span: Span,
1584}
1585
1586#[derive(LintDiagnostic)]
1587#[diag(hir_analysis_supertrait_item_shadowing)]
1588pub(crate) struct SupertraitItemShadowing {
1589    pub item: Symbol,
1590    pub subtrait: Symbol,
1591    #[subdiagnostic]
1592    pub shadowee: SupertraitItemShadowee,
1593}
1594
1595#[derive(Subdiagnostic)]
1596pub(crate) enum SupertraitItemShadowee {
1597    #[note(hir_analysis_supertrait_item_shadowee)]
1598    Labeled {
1599        #[primary_span]
1600        span: Span,
1601        supertrait: Symbol,
1602    },
1603    #[note(hir_analysis_supertrait_item_multiple_shadowee)]
1604    Several {
1605        #[primary_span]
1606        spans: MultiSpan,
1607        traits: DiagSymbolList,
1608    },
1609}
1610
1611#[derive(Diagnostic)]
1612#[diag(hir_analysis_self_in_type_alias, code = E0411)]
1613pub(crate) struct SelfInTypeAlias {
1614    #[primary_span]
1615    #[label]
1616    pub span: Span,
1617}
1618
1619#[derive(Diagnostic)]
1620#[diag(hir_analysis_abi_custom_clothed_function)]
1621pub(crate) struct AbiCustomClothedFunction {
1622    #[primary_span]
1623    pub span: Span,
1624    #[suggestion(
1625        hir_analysis_suggestion,
1626        applicability = "maybe-incorrect",
1627        code = "#[unsafe(naked)]\n",
1628        style = "short"
1629    )]
1630    pub naked_span: Span,
1631}
1632
1633#[derive(Diagnostic)]
1634#[diag(hir_analysis_async_drop_without_sync_drop)]
1635#[help]
1636pub(crate) struct AsyncDropWithoutSyncDrop {
1637    #[primary_span]
1638    pub span: Span,
1639}
1640
1641#[derive(Diagnostic)]
1642#[diag(hir_analysis_lifetimes_or_bounds_mismatch_on_eii)]
1643pub(crate) struct LifetimesOrBoundsMismatchOnEii {
1644    #[primary_span]
1645    #[label]
1646    pub span: Span,
1647    #[label(hir_analysis_generics_label)]
1648    pub generics_span: Span,
1649    #[label(hir_analysis_where_label)]
1650    pub where_span: Option<Span>,
1651    #[label(hir_analysis_bounds_label)]
1652    pub bounds_span: Vec<Span>,
1653    pub ident: Symbol,
1654}
1655
1656#[derive(Diagnostic)]
1657#[diag(hir_analysis_eii_with_generics)]
1658pub(crate) struct EiiWithGenerics {
1659    #[primary_span]
1660    pub span: Span,
1661    #[label]
1662    pub attr: Span,
1663    pub eii_name: Symbol,
1664}