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