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