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