Skip to main content

rustc_trait_selection/
errors.rs

1use rustc_data_structures::fx::{FxHashSet, FxIndexSet};
2use rustc_errors::codes::*;
3use rustc_errors::formatting::DiagMessageAddArg;
4use rustc_errors::{
5    Applicability, Diag, DiagCtxtHandle, DiagMessage, DiagStyledString, Diagnostic,
6    EmissionGuarantee, IntoDiagArg, Level, MultiSpan, Subdiagnostic, msg,
7};
8use rustc_hir::def::DefKind;
9use rustc_hir::def_id::{DefId, LocalDefId};
10use rustc_hir::intravisit::{Visitor, VisitorExt, walk_ty};
11use rustc_hir::{self as hir, AmbigArg, FnRetTy, GenericParamKind, Node};
12use rustc_macros::{Diagnostic, Subdiagnostic};
13use rustc_middle::ty::print::{PrintTraitRefExt as _, TraitRefPrintOnlyTraitPath};
14use rustc_middle::ty::{self, Binder, ClosureKind, FnSig, GenericArg, Region, Ty, TyCtxt};
15use rustc_span::{BytePos, Ident, Span, Symbol, kw, sym};
16
17use crate::error_reporting::infer::ObligationCauseAsDiagArg;
18use crate::error_reporting::infer::need_type_info::UnderspecifiedArgKind;
19use crate::error_reporting::infer::nice_region_error::placeholder_error::Highlighted;
20
21pub mod note_and_explain;
22
23#[derive(const _: () =
    {
        impl<'_sess, 'a, G> rustc_errors::Diagnostic<'_sess, G> for
            UnableToConstructConstantValue<'a> where
            G: rustc_errors::EmissionGuarantee {
            #[track_caller]
            fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
                level: rustc_errors::Level) -> rustc_errors::Diag<'_sess, G> {
                match self {
                    UnableToConstructConstantValue {
                        span: __binding_0, unevaluated: __binding_1 } => {
                        let mut diag =
                            rustc_errors::Diag::new(dcx, level,
                                rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("unable to construct a constant value for the unevaluated constant {$unevaluated}")));
                        ;
                        diag.arg("unevaluated", __binding_1);
                        diag.span(__binding_0);
                        diag
                    }
                }
            }
        }
    };Diagnostic)]
24#[diag("unable to construct a constant value for the unevaluated constant {$unevaluated}")]
25pub struct UnableToConstructConstantValue<'a> {
26    #[primary_span]
27    pub span: Span,
28    pub unevaluated: ty::UnevaluatedConst<'a>,
29}
30
31#[derive(const _: () =
    {
        impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for
            NoValueInOnUnimplemented where G: rustc_errors::EmissionGuarantee
            {
            #[track_caller]
            fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
                level: rustc_errors::Level) -> rustc_errors::Diag<'_sess, G> {
                match self {
                    NoValueInOnUnimplemented { span: __binding_0 } => {
                        let mut diag =
                            rustc_errors::Diag::new(dcx, level,
                                rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("this attribute must have a value")));
                        diag.code(E0232);
                        diag.note(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("e.g. `#[rustc_on_unimplemented(message=\"foo\")]`")));
                        ;
                        diag.span(__binding_0);
                        diag.span_label(__binding_0,
                            rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("expected value here")));
                        diag
                    }
                }
            }
        }
    };Diagnostic)]
32#[diag("this attribute must have a value", code = E0232)]
33#[note("e.g. `#[rustc_on_unimplemented(message=\"foo\")]`")]
34pub struct NoValueInOnUnimplemented {
35    #[primary_span]
36    #[label("expected value here")]
37    pub span: Span,
38}
39
40pub struct NegativePositiveConflict<'tcx> {
41    pub impl_span: Span,
42    pub trait_desc: ty::TraitRef<'tcx>,
43    pub self_ty: Option<Ty<'tcx>>,
44    pub negative_impl_span: Result<Span, Symbol>,
45    pub positive_impl_span: Result<Span, Symbol>,
46}
47
48impl<G: EmissionGuarantee> Diagnostic<'_, G> for NegativePositiveConflict<'_> {
49    #[track_caller]
50    fn into_diag(self, dcx: DiagCtxtHandle<'_>, level: Level) -> Diag<'_, G> {
51        let mut diag = Diag::new(
52            dcx,
53            level,
54            rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("found both positive and negative implementation of trait `{$trait_desc}`{$self_desc ->\n                [none] {\"\"}\n                *[default] {\" \"}for type `{$self_desc}`\n            }:"))msg!(
55            "found both positive and negative implementation of trait `{$trait_desc}`{$self_desc ->
56                [none] {\"\"}
57                *[default] {\" \"}for type `{$self_desc}`
58            }:"
59        ),
60        );
61        diag.arg("trait_desc", self.trait_desc.print_only_trait_path().to_string());
62        diag.arg("self_desc", self.self_ty.map_or_else(|| "none".to_string(), |ty| ty.to_string()));
63        diag.span(self.impl_span);
64        diag.code(E0751);
65        match self.negative_impl_span {
66            Ok(span) => {
67                diag.span_label(span, rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("negative implementation here"))msg!("negative implementation here"));
68            }
69            Err(cname) => {
70                diag.note(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("negative implementation in crate `{$negative_impl_cname}`"))msg!("negative implementation in crate `{$negative_impl_cname}`"));
71                diag.arg("negative_impl_cname", cname.to_string());
72            }
73        }
74        match self.positive_impl_span {
75            Ok(span) => {
76                diag.span_label(span, rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("positive implementation here"))msg!("positive implementation here"));
77            }
78            Err(cname) => {
79                diag.note(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("positive implementation in crate `{$positive_impl_cname}`"))msg!("positive implementation in crate `{$positive_impl_cname}`"));
80                diag.arg("positive_impl_cname", cname.to_string());
81            }
82        }
83        diag
84    }
85}
86
87#[derive(const _: () =
    {
        impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for
            InherentProjectionNormalizationOverflow where
            G: rustc_errors::EmissionGuarantee {
            #[track_caller]
            fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
                level: rustc_errors::Level) -> rustc_errors::Diag<'_sess, G> {
                match self {
                    InherentProjectionNormalizationOverflow {
                        span: __binding_0, ty: __binding_1 } => {
                        let mut diag =
                            rustc_errors::Diag::new(dcx, level,
                                rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("overflow evaluating associated type `{$ty}`")));
                        ;
                        diag.arg("ty", __binding_1);
                        diag.span(__binding_0);
                        diag
                    }
                }
            }
        }
    };Diagnostic)]
88#[diag("overflow evaluating associated type `{$ty}`")]
89pub struct InherentProjectionNormalizationOverflow {
90    #[primary_span]
91    pub span: Span,
92    pub ty: String,
93}
94
95pub enum AdjustSignatureBorrow {
96    Borrow { to_borrow: Vec<(Span, String)> },
97    RemoveBorrow { remove_borrow: Vec<(Span, String)> },
98}
99
100impl Subdiagnostic for AdjustSignatureBorrow {
101    fn add_to_diag<G: EmissionGuarantee>(self, diag: &mut Diag<'_, G>) {
102        match self {
103            AdjustSignatureBorrow::Borrow { to_borrow } => {
104                diag.arg("borrow_len", to_borrow.len());
105                diag.multipart_suggestion(
106                    rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("consider adjusting the signature so it borrows its {$borrow_len ->\n                            [one] argument\n                            *[other] arguments\n                        }"))msg!(
107                        "consider adjusting the signature so it borrows its {$borrow_len ->
108                            [one] argument
109                            *[other] arguments
110                        }"
111                    ),
112                    to_borrow,
113                    Applicability::MaybeIncorrect,
114                );
115            }
116            AdjustSignatureBorrow::RemoveBorrow { remove_borrow } => {
117                diag.arg("remove_borrow_len", remove_borrow.len());
118                diag.multipart_suggestion(
119                    rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("consider adjusting the signature so it does not borrow its {$remove_borrow_len ->\n                            [one] argument\n                            *[other] arguments\n                        }"))msg!(
120                        "consider adjusting the signature so it does not borrow its {$remove_borrow_len ->
121                            [one] argument
122                            *[other] arguments
123                        }"
124                    ),
125                    remove_borrow,
126                    Applicability::MaybeIncorrect,
127                );
128            }
129        }
130    }
131}
132
133#[derive(const _: () =
    {
        impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for
            ClosureKindMismatch where G: rustc_errors::EmissionGuarantee {
            #[track_caller]
            fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
                level: rustc_errors::Level) -> rustc_errors::Diag<'_sess, G> {
                match self {
                    ClosureKindMismatch {
                        closure_span: __binding_0,
                        expected: __binding_1,
                        found: __binding_2,
                        cause_span: __binding_3,
                        trait_prefix: __binding_4,
                        fn_once_label: __binding_5,
                        fn_mut_label: __binding_6 } => {
                        let mut diag =
                            rustc_errors::Diag::new(dcx, level,
                                rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("expected a closure that implements the `{$trait_prefix}{$expected}` trait, but this closure only implements `{$trait_prefix}{$found}`")));
                        diag.code(E0525);
                        ;
                        diag.arg("expected", __binding_1);
                        diag.arg("found", __binding_2);
                        diag.arg("trait_prefix", __binding_4);
                        diag.span(__binding_0);
                        diag.span_label(__binding_0,
                            rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("this closure implements `{$trait_prefix}{$found}`, not `{$trait_prefix}{$expected}`")));
                        diag.span_label(__binding_3,
                            rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("the requirement to implement `{$trait_prefix}{$expected}` derives from here")));
                        if let Some(__binding_5) = __binding_5 {
                            diag.subdiagnostic(__binding_5);
                        }
                        if let Some(__binding_6) = __binding_6 {
                            diag.subdiagnostic(__binding_6);
                        }
                        diag
                    }
                }
            }
        }
    };Diagnostic)]
134#[diag("expected a closure that implements the `{$trait_prefix}{$expected}` trait, but this closure only implements `{$trait_prefix}{$found}`", code = E0525)]
135pub struct ClosureKindMismatch {
136    #[primary_span]
137    #[label("this closure implements `{$trait_prefix}{$found}`, not `{$trait_prefix}{$expected}`")]
138    pub closure_span: Span,
139    pub expected: ClosureKind,
140    pub found: ClosureKind,
141    #[label("the requirement to implement `{$trait_prefix}{$expected}` derives from here")]
142    pub cause_span: Span,
143
144    pub trait_prefix: &'static str,
145
146    #[subdiagnostic]
147    pub fn_once_label: Option<ClosureFnOnceLabel>,
148
149    #[subdiagnostic]
150    pub fn_mut_label: Option<ClosureFnMutLabel>,
151}
152
153#[derive(const _: () =
    {
        impl rustc_errors::Subdiagnostic for ClosureFnOnceLabel {
            fn add_to_diag<__G>(self, diag: &mut rustc_errors::Diag<'_, __G>)
                where __G: rustc_errors::EmissionGuarantee {
                match self {
                    ClosureFnOnceLabel {
                        span: __binding_0,
                        place: __binding_1,
                        trait_prefix: __binding_2 } => {
                        let mut sub_args = rustc_errors::DiagArgMap::default();
                        sub_args.insert("place".into(),
                            rustc_errors::IntoDiagArg::into_diag_arg(__binding_1,
                                &mut diag.long_ty_path));
                        sub_args.insert("trait_prefix".into(),
                            rustc_errors::IntoDiagArg::into_diag_arg(__binding_2,
                                &mut diag.long_ty_path));
                        let __message =
                            rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("closure is `{$trait_prefix}FnOnce` because it moves the variable `{$place}` out of its environment")),
                                &sub_args);
                        diag.span_label(__binding_0, __message);
                    }
                }
            }
        }
    };Subdiagnostic)]
154#[label(
155    "closure is `{$trait_prefix}FnOnce` because it moves the variable `{$place}` out of its environment"
156)]
157pub struct ClosureFnOnceLabel {
158    #[primary_span]
159    pub span: Span,
160    pub place: String,
161    pub trait_prefix: &'static str,
162}
163
164#[derive(const _: () =
    {
        impl rustc_errors::Subdiagnostic for ClosureFnMutLabel {
            fn add_to_diag<__G>(self, diag: &mut rustc_errors::Diag<'_, __G>)
                where __G: rustc_errors::EmissionGuarantee {
                match self {
                    ClosureFnMutLabel {
                        span: __binding_0,
                        place: __binding_1,
                        trait_prefix: __binding_2 } => {
                        let mut sub_args = rustc_errors::DiagArgMap::default();
                        sub_args.insert("place".into(),
                            rustc_errors::IntoDiagArg::into_diag_arg(__binding_1,
                                &mut diag.long_ty_path));
                        sub_args.insert("trait_prefix".into(),
                            rustc_errors::IntoDiagArg::into_diag_arg(__binding_2,
                                &mut diag.long_ty_path));
                        let __message =
                            rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("closure is `{$trait_prefix}FnMut` because it mutates the variable `{$place}` here")),
                                &sub_args);
                        diag.span_label(__binding_0, __message);
                    }
                }
            }
        }
    };Subdiagnostic)]
165#[label("closure is `{$trait_prefix}FnMut` because it mutates the variable `{$place}` here")]
166pub struct ClosureFnMutLabel {
167    #[primary_span]
168    pub span: Span,
169    pub place: String,
170    pub trait_prefix: &'static str,
171}
172
173#[derive(const _: () =
    {
        impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for
            CoroClosureNotFn where G: rustc_errors::EmissionGuarantee {
            #[track_caller]
            fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
                level: rustc_errors::Level) -> rustc_errors::Diag<'_sess, G> {
                match self {
                    CoroClosureNotFn {
                        span: __binding_0, kind: __binding_1, coro_kind: __binding_2
                        } => {
                        let mut diag =
                            rustc_errors::Diag::new(dcx, level,
                                rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("{$coro_kind}closure does not implement `{$kind}` because it captures state from its environment")));
                        ;
                        diag.arg("kind", __binding_1);
                        diag.arg("coro_kind", __binding_2);
                        diag.span(__binding_0);
                        diag
                    }
                }
            }
        }
    };Diagnostic)]
174#[diag(
175    "{$coro_kind}closure does not implement `{$kind}` because it captures state from its environment"
176)]
177pub(crate) struct CoroClosureNotFn {
178    #[primary_span]
179    pub span: Span,
180    pub kind: &'static str,
181    pub coro_kind: String,
182}
183
184#[derive(const _: () =
    {
        impl<'_sess, 'a, G> rustc_errors::Diagnostic<'_sess, G> for
            AnnotationRequired<'a> where G: rustc_errors::EmissionGuarantee {
            #[track_caller]
            fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
                level: rustc_errors::Level) -> rustc_errors::Diag<'_sess, G> {
                match self {
                    AnnotationRequired {
                        span: __binding_0,
                        source_kind: __binding_1,
                        source_name: __binding_2,
                        failure_span: __binding_3,
                        bad_label: __binding_4,
                        infer_subdiags: __binding_5,
                        multi_suggestions: __binding_6 } => {
                        let mut diag =
                            rustc_errors::Diag::new(dcx, level,
                                rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("{$source_kind ->\n[closure] type annotations needed for the closure `{$source_name}`\n[normal] type annotations needed for `{$source_name}`\n*[other] type annotations needed\n}")));
                        diag.code(E0282);
                        ;
                        diag.arg("source_kind", __binding_1);
                        diag.arg("source_name", __binding_2);
                        diag.span(__binding_0);
                        if let Some(__binding_3) = __binding_3 {
                            diag.span_label(__binding_3,
                                rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("type must be known at this point")));
                        }
                        if let Some(__binding_4) = __binding_4 {
                            diag.subdiagnostic(__binding_4);
                        }
                        for __binding_5 in __binding_5 {
                            diag.subdiagnostic(__binding_5);
                        }
                        for __binding_6 in __binding_6 {
                            diag.subdiagnostic(__binding_6);
                        }
                        diag
                    }
                }
            }
        }
    };Diagnostic)]
185#[diag("{$source_kind ->
186[closure] type annotations needed for the closure `{$source_name}`
187[normal] type annotations needed for `{$source_name}`
188*[other] type annotations needed
189}", code = E0282)]
190pub struct AnnotationRequired<'a> {
191    #[primary_span]
192    pub span: Span,
193    pub source_kind: &'static str,
194    pub source_name: &'a str,
195    #[label("type must be known at this point")]
196    pub failure_span: Option<Span>,
197    #[subdiagnostic]
198    pub bad_label: Option<InferenceBadError<'a>>,
199    #[subdiagnostic]
200    pub infer_subdiags: Vec<SourceKindSubdiag<'a>>,
201    #[subdiagnostic]
202    pub multi_suggestions: Vec<SourceKindMultiSuggestion<'a>>,
203}
204
205// Copy of `AnnotationRequired` for E0283
206#[derive(const _: () =
    {
        impl<'_sess, 'a, G> rustc_errors::Diagnostic<'_sess, G> for
            AmbiguousImpl<'a> where G: rustc_errors::EmissionGuarantee {
            #[track_caller]
            fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
                level: rustc_errors::Level) -> rustc_errors::Diag<'_sess, G> {
                match self {
                    AmbiguousImpl {
                        span: __binding_0,
                        source_kind: __binding_1,
                        source_name: __binding_2,
                        failure_span: __binding_3,
                        bad_label: __binding_4,
                        infer_subdiags: __binding_5,
                        multi_suggestions: __binding_6 } => {
                        let mut diag =
                            rustc_errors::Diag::new(dcx, level,
                                rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("{$source_kind ->\n[closure] type annotations needed for the closure `{$source_name}`\n[normal] type annotations needed for `{$source_name}`\n*[other] type annotations needed\n}")));
                        diag.code(E0283);
                        ;
                        diag.arg("source_kind", __binding_1);
                        diag.arg("source_name", __binding_2);
                        diag.span(__binding_0);
                        if let Some(__binding_3) = __binding_3 {
                            diag.span_label(__binding_3,
                                rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("type must be known at this point")));
                        }
                        if let Some(__binding_4) = __binding_4 {
                            diag.subdiagnostic(__binding_4);
                        }
                        for __binding_5 in __binding_5 {
                            diag.subdiagnostic(__binding_5);
                        }
                        for __binding_6 in __binding_6 {
                            diag.subdiagnostic(__binding_6);
                        }
                        diag
                    }
                }
            }
        }
    };Diagnostic)]
207#[diag("{$source_kind ->
208[closure] type annotations needed for the closure `{$source_name}`
209[normal] type annotations needed for `{$source_name}`
210*[other] type annotations needed
211}", code = E0283)]
212pub struct AmbiguousImpl<'a> {
213    #[primary_span]
214    pub span: Span,
215    pub source_kind: &'static str,
216    pub source_name: &'a str,
217    #[label("type must be known at this point")]
218    pub failure_span: Option<Span>,
219    #[subdiagnostic]
220    pub bad_label: Option<InferenceBadError<'a>>,
221    #[subdiagnostic]
222    pub infer_subdiags: Vec<SourceKindSubdiag<'a>>,
223    #[subdiagnostic]
224    pub multi_suggestions: Vec<SourceKindMultiSuggestion<'a>>,
225}
226
227// Copy of `AnnotationRequired` for E0284
228#[derive(const _: () =
    {
        impl<'_sess, 'a, G> rustc_errors::Diagnostic<'_sess, G> for
            AmbiguousReturn<'a> where G: rustc_errors::EmissionGuarantee {
            #[track_caller]
            fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
                level: rustc_errors::Level) -> rustc_errors::Diag<'_sess, G> {
                match self {
                    AmbiguousReturn {
                        span: __binding_0,
                        source_kind: __binding_1,
                        source_name: __binding_2,
                        failure_span: __binding_3,
                        bad_label: __binding_4,
                        infer_subdiags: __binding_5,
                        multi_suggestions: __binding_6 } => {
                        let mut diag =
                            rustc_errors::Diag::new(dcx, level,
                                rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("{$source_kind ->\n[closure] type annotations needed for the closure `{$source_name}`\n[normal] type annotations needed for `{$source_name}`\n*[other] type annotations needed\n}")));
                        diag.code(E0284);
                        ;
                        diag.arg("source_kind", __binding_1);
                        diag.arg("source_name", __binding_2);
                        diag.span(__binding_0);
                        if let Some(__binding_3) = __binding_3 {
                            diag.span_label(__binding_3,
                                rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("type must be known at this point")));
                        }
                        if let Some(__binding_4) = __binding_4 {
                            diag.subdiagnostic(__binding_4);
                        }
                        for __binding_5 in __binding_5 {
                            diag.subdiagnostic(__binding_5);
                        }
                        for __binding_6 in __binding_6 {
                            diag.subdiagnostic(__binding_6);
                        }
                        diag
                    }
                }
            }
        }
    };Diagnostic)]
229#[diag("{$source_kind ->
230[closure] type annotations needed for the closure `{$source_name}`
231[normal] type annotations needed for `{$source_name}`
232*[other] type annotations needed
233}", code = E0284)]
234pub struct AmbiguousReturn<'a> {
235    #[primary_span]
236    pub span: Span,
237    pub source_kind: &'static str,
238    pub source_name: &'a str,
239    #[label("type must be known at this point")]
240    pub failure_span: Option<Span>,
241    #[subdiagnostic]
242    pub bad_label: Option<InferenceBadError<'a>>,
243    #[subdiagnostic]
244    pub infer_subdiags: Vec<SourceKindSubdiag<'a>>,
245    #[subdiagnostic]
246    pub multi_suggestions: Vec<SourceKindMultiSuggestion<'a>>,
247}
248
249// Used when a better one isn't available
250#[derive(const _: () =
    {
        impl<'a> rustc_errors::Subdiagnostic for InferenceBadError<'a> {
            fn add_to_diag<__G>(self, diag: &mut rustc_errors::Diag<'_, __G>)
                where __G: rustc_errors::EmissionGuarantee {
                match self {
                    InferenceBadError {
                        span: __binding_0,
                        bad_kind: __binding_1,
                        prefix_kind: __binding_2,
                        has_parent: __binding_3,
                        prefix: __binding_4,
                        parent_prefix: __binding_5,
                        parent_name: __binding_6,
                        name: __binding_7 } => {
                        let mut sub_args = rustc_errors::DiagArgMap::default();
                        sub_args.insert("bad_kind".into(),
                            rustc_errors::IntoDiagArg::into_diag_arg(__binding_1,
                                &mut diag.long_ty_path));
                        sub_args.insert("prefix_kind".into(),
                            rustc_errors::IntoDiagArg::into_diag_arg(__binding_2,
                                &mut diag.long_ty_path));
                        sub_args.insert("has_parent".into(),
                            rustc_errors::IntoDiagArg::into_diag_arg(__binding_3,
                                &mut diag.long_ty_path));
                        sub_args.insert("prefix".into(),
                            rustc_errors::IntoDiagArg::into_diag_arg(__binding_4,
                                &mut diag.long_ty_path));
                        sub_args.insert("parent_prefix".into(),
                            rustc_errors::IntoDiagArg::into_diag_arg(__binding_5,
                                &mut diag.long_ty_path));
                        sub_args.insert("parent_name".into(),
                            rustc_errors::IntoDiagArg::into_diag_arg(__binding_6,
                                &mut diag.long_ty_path));
                        sub_args.insert("name".into(),
                            rustc_errors::IntoDiagArg::into_diag_arg(__binding_7,
                                &mut diag.long_ty_path));
                        let __message =
                            rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("{$bad_kind ->\n*[other] cannot infer type\n[more_info] cannot infer {$prefix_kind ->\n*[type] type for {$prefix}\n[const_with_param] the value of const parameter\n[const] the value of the constant\n} `{$name}`{$has_parent ->\n[true] {\" \"}declared on the {$parent_prefix} `{$parent_name}`\n*[false] {\"\"}\n}\n}")),
                                &sub_args);
                        diag.span_label(__binding_0, __message);
                    }
                }
            }
        }
    };Subdiagnostic)]
251#[label(
252    "{$bad_kind ->
253*[other] cannot infer type
254[more_info] cannot infer {$prefix_kind ->
255*[type] type for {$prefix}
256[const_with_param] the value of const parameter
257[const] the value of the constant
258} `{$name}`{$has_parent ->
259[true] {\" \"}declared on the {$parent_prefix} `{$parent_name}`
260*[false] {\"\"}
261}
262}"
263)]
264pub struct InferenceBadError<'a> {
265    #[primary_span]
266    pub span: Span,
267    pub bad_kind: &'static str,
268    pub prefix_kind: UnderspecifiedArgKind,
269    pub has_parent: bool,
270    pub prefix: &'a str,
271    pub parent_prefix: &'a str,
272    pub parent_name: String,
273    pub name: String,
274}
275
276#[derive(const _: () =
    {
        impl<'a> rustc_errors::Subdiagnostic for SourceKindSubdiag<'a> {
            fn add_to_diag<__G>(self, diag: &mut rustc_errors::Diag<'_, __G>)
                where __G: rustc_errors::EmissionGuarantee {
                match self {
                    SourceKindSubdiag::LetLike {
                        span: __binding_0,
                        name: __binding_1,
                        type_name: __binding_2,
                        kind: __binding_3,
                        x_kind: __binding_4,
                        prefix_kind: __binding_5,
                        prefix: __binding_6,
                        arg_name: __binding_7 } => {
                        let __code_0 =
                            [::alloc::__export::must_use({
                                                ::alloc::fmt::format(format_args!(": {0}", __binding_2))
                                            })].into_iter();
                        let mut sub_args = rustc_errors::DiagArgMap::default();
                        sub_args.insert("name".into(),
                            rustc_errors::IntoDiagArg::into_diag_arg(__binding_1,
                                &mut diag.long_ty_path));
                        sub_args.insert("type_name".into(),
                            rustc_errors::IntoDiagArg::into_diag_arg(__binding_2,
                                &mut diag.long_ty_path));
                        sub_args.insert("kind".into(),
                            rustc_errors::IntoDiagArg::into_diag_arg(__binding_3,
                                &mut diag.long_ty_path));
                        sub_args.insert("x_kind".into(),
                            rustc_errors::IntoDiagArg::into_diag_arg(__binding_4,
                                &mut diag.long_ty_path));
                        sub_args.insert("prefix_kind".into(),
                            rustc_errors::IntoDiagArg::into_diag_arg(__binding_5,
                                &mut diag.long_ty_path));
                        sub_args.insert("prefix".into(),
                            rustc_errors::IntoDiagArg::into_diag_arg(__binding_6,
                                &mut diag.long_ty_path));
                        sub_args.insert("arg_name".into(),
                            rustc_errors::IntoDiagArg::into_diag_arg(__binding_7,
                                &mut diag.long_ty_path));
                        let __message =
                            rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("{$kind ->\n            [with_pattern] consider giving `{$name}` an explicit type\n            [closure] consider giving this closure parameter an explicit type\n            *[other] consider giving this pattern a type\n        }{$x_kind ->\n            [has_name] , where the {$prefix_kind ->\n                *[type] type for {$prefix}\n                [const_with_param] value of const parameter\n                [const] value of the constant\n            } `{$arg_name}` is specified\n            [underscore] , where the placeholders `_` are specified\n            *[empty] {\"\"}\n        }")),
                                &sub_args);
                        diag.span_suggestions_with_style(__binding_0, __message,
                            __code_0, rustc_errors::Applicability::HasPlaceholders,
                            rustc_errors::SuggestionStyle::ShowAlways);
                    }
                    SourceKindSubdiag::GenericLabel {
                        span: __binding_0,
                        is_type: __binding_1,
                        param_name: __binding_2,
                        parent_exists: __binding_3,
                        parent_prefix: __binding_4,
                        parent_name: __binding_5 } => {
                        let mut sub_args = rustc_errors::DiagArgMap::default();
                        sub_args.insert("is_type".into(),
                            rustc_errors::IntoDiagArg::into_diag_arg(__binding_1,
                                &mut diag.long_ty_path));
                        sub_args.insert("param_name".into(),
                            rustc_errors::IntoDiagArg::into_diag_arg(__binding_2,
                                &mut diag.long_ty_path));
                        sub_args.insert("parent_exists".into(),
                            rustc_errors::IntoDiagArg::into_diag_arg(__binding_3,
                                &mut diag.long_ty_path));
                        sub_args.insert("parent_prefix".into(),
                            rustc_errors::IntoDiagArg::into_diag_arg(__binding_4,
                                &mut diag.long_ty_path));
                        sub_args.insert("parent_name".into(),
                            rustc_errors::IntoDiagArg::into_diag_arg(__binding_5,
                                &mut diag.long_ty_path));
                        let __message =
                            rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("cannot infer {$is_type ->\n            [true] type\n            *[false] the value\n        } of the {$is_type ->\n            [true] type\n            *[false] const\n        } {$parent_exists ->\n            [true] parameter `{$param_name}` declared on the {$parent_prefix} `{$parent_name}`\n            *[false] parameter {$param_name}\n        }")),
                                &sub_args);
                        diag.span_label(__binding_0, __message);
                    }
                    SourceKindSubdiag::GenericSuggestion {
                        span: __binding_0, arg_count: __binding_1, args: __binding_2
                        } => {
                        let __code_1 =
                            [::alloc::__export::must_use({
                                                ::alloc::fmt::format(format_args!("::<{0}>", __binding_2))
                                            })].into_iter();
                        let mut sub_args = rustc_errors::DiagArgMap::default();
                        sub_args.insert("arg_count".into(),
                            rustc_errors::IntoDiagArg::into_diag_arg(__binding_1,
                                &mut diag.long_ty_path));
                        sub_args.insert("args".into(),
                            rustc_errors::IntoDiagArg::into_diag_arg(__binding_2,
                                &mut diag.long_ty_path));
                        let __message =
                            rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("consider specifying the generic {$arg_count ->\n            [one] argument\n            *[other] arguments\n        }")),
                                &sub_args);
                        diag.span_suggestions_with_style(__binding_0, __message,
                            __code_1, rustc_errors::Applicability::HasPlaceholders,
                            rustc_errors::SuggestionStyle::ShowAlways);
                    }
                }
            }
        }
    };Subdiagnostic)]
277pub enum SourceKindSubdiag<'a> {
278    #[suggestion(
279        "{$kind ->
280            [with_pattern] consider giving `{$name}` an explicit type
281            [closure] consider giving this closure parameter an explicit type
282            *[other] consider giving this pattern a type
283        }{$x_kind ->
284            [has_name] , where the {$prefix_kind ->
285                *[type] type for {$prefix}
286                [const_with_param] value of const parameter
287                [const] value of the constant
288            } `{$arg_name}` is specified
289            [underscore] , where the placeholders `_` are specified
290            *[empty] {\"\"}
291        }",
292        style = "verbose",
293        code = ": {type_name}",
294        applicability = "has-placeholders"
295    )]
296    LetLike {
297        #[primary_span]
298        span: Span,
299        name: String,
300        type_name: String,
301        kind: &'static str,
302        x_kind: &'static str,
303        prefix_kind: UnderspecifiedArgKind,
304        prefix: &'a str,
305        arg_name: String,
306    },
307    #[label(
308        "cannot infer {$is_type ->
309            [true] type
310            *[false] the value
311        } of the {$is_type ->
312            [true] type
313            *[false] const
314        } {$parent_exists ->
315            [true] parameter `{$param_name}` declared on the {$parent_prefix} `{$parent_name}`
316            *[false] parameter {$param_name}
317        }"
318    )]
319    GenericLabel {
320        #[primary_span]
321        span: Span,
322        is_type: bool,
323        param_name: String,
324        parent_exists: bool,
325        parent_prefix: String,
326        parent_name: String,
327    },
328    #[suggestion(
329        "consider specifying the generic {$arg_count ->
330            [one] argument
331            *[other] arguments
332        }",
333        style = "verbose",
334        code = "::<{args}>",
335        applicability = "has-placeholders"
336    )]
337    GenericSuggestion {
338        #[primary_span]
339        span: Span,
340        arg_count: usize,
341        args: String,
342    },
343}
344
345#[derive(const _: () =
    {
        impl<'a> rustc_errors::Subdiagnostic for SourceKindMultiSuggestion<'a>
            {
            fn add_to_diag<__G>(self, diag: &mut rustc_errors::Diag<'_, __G>)
                where __G: rustc_errors::EmissionGuarantee {
                match self {
                    SourceKindMultiSuggestion::FullyQualified {
                        span_lo: __binding_0,
                        span_hi: __binding_1,
                        def_path: __binding_2,
                        adjustment: __binding_3,
                        successor_pos: __binding_4 } => {
                        let mut suggestions = Vec::new();
                        let __code_2 =
                            ::alloc::__export::must_use({
                                    ::alloc::fmt::format(format_args!("{1}({0}", __binding_3,
                                            __binding_2))
                                });
                        let __code_3 =
                            ::alloc::__export::must_use({
                                    ::alloc::fmt::format(format_args!("{0}", __binding_4))
                                });
                        suggestions.push((__binding_0, __code_2));
                        suggestions.push((__binding_1, __code_3));
                        let mut sub_args = rustc_errors::DiagArgMap::default();
                        sub_args.insert("def_path".into(),
                            rustc_errors::IntoDiagArg::into_diag_arg(__binding_2,
                                &mut diag.long_ty_path));
                        sub_args.insert("adjustment".into(),
                            rustc_errors::IntoDiagArg::into_diag_arg(__binding_3,
                                &mut diag.long_ty_path));
                        sub_args.insert("successor_pos".into(),
                            rustc_errors::IntoDiagArg::into_diag_arg(__binding_4,
                                &mut diag.long_ty_path));
                        let __message =
                            rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("try using a fully qualified path to specify the expected types")),
                                &sub_args);
                        diag.multipart_suggestion_with_style(__message, suggestions,
                            rustc_errors::Applicability::HasPlaceholders,
                            rustc_errors::SuggestionStyle::ShowAlways);
                    }
                    SourceKindMultiSuggestion::ClosureReturn {
                        start_span: __binding_0,
                        start_span_code: __binding_1,
                        end_span: __binding_2 } => {
                        let mut suggestions = Vec::new();
                        let __code_4 =
                            ::alloc::__export::must_use({
                                    ::alloc::fmt::format(format_args!("{0}", __binding_1))
                                });
                        let __code_5 =
                            ::alloc::__export::must_use({
                                    ::alloc::fmt::format(format_args!(" }}"))
                                });
                        suggestions.push((__binding_0, __code_4));
                        if let Some(__binding_2) = __binding_2 {
                            suggestions.push((__binding_2, __code_5));
                        }
                        let mut sub_args = rustc_errors::DiagArgMap::default();
                        sub_args.insert("start_span_code".into(),
                            rustc_errors::IntoDiagArg::into_diag_arg(__binding_1,
                                &mut diag.long_ty_path));
                        let __message =
                            rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("try giving this closure an explicit return type")),
                                &sub_args);
                        diag.multipart_suggestion_with_style(__message, suggestions,
                            rustc_errors::Applicability::HasPlaceholders,
                            rustc_errors::SuggestionStyle::ShowAlways);
                    }
                }
            }
        }
    };Subdiagnostic)]
346pub enum SourceKindMultiSuggestion<'a> {
347    #[multipart_suggestion(
348        "try using a fully qualified path to specify the expected types",
349        style = "verbose",
350        applicability = "has-placeholders"
351    )]
352    FullyQualified {
353        #[suggestion_part(code = "{def_path}({adjustment}")]
354        span_lo: Span,
355        #[suggestion_part(code = "{successor_pos}")]
356        span_hi: Span,
357        def_path: String,
358        adjustment: &'a str,
359        successor_pos: &'a str,
360    },
361    #[multipart_suggestion(
362        "try giving this closure an explicit return type",
363        style = "verbose",
364        applicability = "has-placeholders"
365    )]
366    ClosureReturn {
367        #[suggestion_part(code = "{start_span_code}")]
368        start_span: Span,
369        start_span_code: String,
370        #[suggestion_part(code = " }}")]
371        end_span: Option<Span>,
372    },
373}
374
375impl<'a> SourceKindMultiSuggestion<'a> {
376    pub fn new_fully_qualified(
377        span: Span,
378        def_path: String,
379        adjustment: &'a str,
380        successor: (&'a str, BytePos),
381    ) -> Self {
382        Self::FullyQualified {
383            span_lo: span.shrink_to_lo(),
384            span_hi: span.shrink_to_hi().with_hi(successor.1),
385            def_path,
386            adjustment,
387            successor_pos: successor.0,
388        }
389    }
390
391    pub fn new_closure_return(
392        ty_info: String,
393        data: &'a FnRetTy<'a>,
394        should_wrap_expr: Option<Span>,
395    ) -> Self {
396        let arrow = match data {
397            FnRetTy::DefaultReturn(_) => " -> ",
398            _ => "",
399        };
400        let (start_span, start_span_code, end_span) = match should_wrap_expr {
401            Some(end_span) => (data.span(), ::alloc::__export::must_use({
        ::alloc::fmt::format(format_args!("{0}{1} {{", arrow, ty_info))
    })format!("{arrow}{ty_info} {{"), Some(end_span)),
402            None => (data.span(), ::alloc::__export::must_use({
        ::alloc::fmt::format(format_args!("{0}{1}", arrow, ty_info))
    })format!("{arrow}{ty_info}"), None),
403        };
404        Self::ClosureReturn { start_span, start_span_code, end_span }
405    }
406}
407
408pub enum RegionOriginNote<'a> {
409    Plain {
410        span: Span,
411        msg: DiagMessage,
412    },
413    WithName {
414        span: Span,
415        msg: DiagMessage,
416        name: &'a str,
417        continues: bool,
418    },
419    WithRequirement {
420        span: Span,
421        requirement: ObligationCauseAsDiagArg<'a>,
422        expected_found: Option<(DiagStyledString, DiagStyledString)>,
423    },
424}
425
426impl Subdiagnostic for RegionOriginNote<'_> {
427    fn add_to_diag<G: EmissionGuarantee>(self, diag: &mut Diag<'_, G>) {
428        let label_or_note = |diag: &mut Diag<'_, G>, span, msg: DiagMessage| {
429            let sub_count = diag.children.iter().filter(|d| d.span.is_dummy()).count();
430            let expanded_sub_count = diag.children.iter().filter(|d| !d.span.is_dummy()).count();
431            let span_is_primary = diag.span.primary_spans().iter().all(|&sp| sp == span);
432            if span_is_primary && sub_count == 0 && expanded_sub_count == 0 {
433                diag.span_label(span, msg);
434            } else if span_is_primary && expanded_sub_count == 0 {
435                diag.note(msg);
436            } else {
437                diag.span_note(span, msg);
438            }
439        };
440        match self {
441            RegionOriginNote::Plain { span, msg } => {
442                label_or_note(diag, span, msg);
443            }
444            RegionOriginNote::WithName { span, msg, name, continues } => {
445                diag.arg("name", name);
446                diag.arg("continues", continues);
447                label_or_note(diag, span, msg);
448            }
449            RegionOriginNote::WithRequirement {
450                span,
451                requirement,
452                expected_found: Some((expected, found)),
453            } => {
454                let msg = rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("...so that the {$requirement ->\n                        [method_compat] method type is compatible with trait\n                        [type_compat] associated type is compatible with trait\n                        [const_compat] const is compatible with trait\n                        [expr_assignable] expression is assignable\n                        [if_else_different] `if` and `else` have incompatible types\n                        [no_else] `if` missing an `else` returns `()`\n                        [fn_main_correct_type] `main` function has the correct type\n                        [fn_lang_correct_type] lang item function has the correct type\n                        [intrinsic_correct_type] intrinsic has the correct type\n                        [method_correct_type] method receiver has the correct type\n                        *[other] types are compatible\n                    }"))msg!(
455                    "...so that the {$requirement ->
456                        [method_compat] method type is compatible with trait
457                        [type_compat] associated type is compatible with trait
458                        [const_compat] const is compatible with trait
459                        [expr_assignable] expression is assignable
460                        [if_else_different] `if` and `else` have incompatible types
461                        [no_else] `if` missing an `else` returns `()`
462                        [fn_main_correct_type] `main` function has the correct type
463                        [fn_lang_correct_type] lang item function has the correct type
464                        [intrinsic_correct_type] intrinsic has the correct type
465                        [method_correct_type] method receiver has the correct type
466                        *[other] types are compatible
467                    }"
468                )
469                .arg("requirement", requirement)
470                .format();
471                label_or_note(diag, span, msg);
472
473                diag.note_expected_found("", expected, "", found);
474            }
475            RegionOriginNote::WithRequirement { span, requirement, expected_found: None } => {
476                // FIXME: this really should be handled at some earlier stage. Our
477                // handling of region checking when type errors are present is
478                // *terrible*.
479                let msg = rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("...so that {$requirement ->\n                            [method_compat] method type is compatible with trait\n                            [type_compat] associated type is compatible with trait\n                            [const_compat] const is compatible with trait\n                            [expr_assignable] expression is assignable\n                            [if_else_different] `if` and `else` have incompatible types\n                            [no_else] `if` missing an `else` returns `()`\n                            [fn_main_correct_type] `main` function has the correct type\n                            [fn_lang_correct_type] lang item function has the correct type\n                            [intrinsic_correct_type] intrinsic has the correct type\n                            [method_correct_type] method receiver has the correct type\n                            *[other] types are compatible\n                        }"))msg!(
480                    "...so that {$requirement ->
481                            [method_compat] method type is compatible with trait
482                            [type_compat] associated type is compatible with trait
483                            [const_compat] const is compatible with trait
484                            [expr_assignable] expression is assignable
485                            [if_else_different] `if` and `else` have incompatible types
486                            [no_else] `if` missing an `else` returns `()`
487                            [fn_main_correct_type] `main` function has the correct type
488                            [fn_lang_correct_type] lang item function has the correct type
489                            [intrinsic_correct_type] intrinsic has the correct type
490                            [method_correct_type] method receiver has the correct type
491                            *[other] types are compatible
492                        }"
493                )
494                .arg("requirement", requirement)
495                .format();
496                label_or_note(diag, span, msg);
497            }
498        };
499    }
500}
501
502pub enum LifetimeMismatchLabels {
503    InRet {
504        param_span: Span,
505        ret_span: Span,
506        span: Span,
507        label_var1: Option<Ident>,
508    },
509    Normal {
510        hir_equal: bool,
511        ty_sup: Span,
512        ty_sub: Span,
513        span: Span,
514        sup: Option<Ident>,
515        sub: Option<Ident>,
516    },
517}
518
519impl Subdiagnostic for LifetimeMismatchLabels {
520    fn add_to_diag<G: EmissionGuarantee>(self, diag: &mut Diag<'_, G>) {
521        match self {
522            LifetimeMismatchLabels::InRet { param_span, ret_span, span, label_var1 } => {
523                diag.span_label(param_span, rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("this parameter and the return type are declared with different lifetimes..."))msg!("this parameter and the return type are declared with different lifetimes..."));
524                diag.span_label(ret_span, rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("{\"\"}"))msg!("{\"\"}"));
525                diag.span_label(
526                    span,
527                    rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("...but data{$label_var1_exists ->\n                            [true] {\" \"}from `{$label_var1}`\n                            *[false] {\"\"}\n                        } is returned here"))msg!(
528                        "...but data{$label_var1_exists ->
529                            [true] {\" \"}from `{$label_var1}`
530                            *[false] {\"\"}
531                        } is returned here"
532                    ),
533                );
534                diag.arg("label_var1_exists", label_var1.is_some());
535                diag.arg("label_var1", label_var1.map(|x| x.to_string()).unwrap_or_default());
536            }
537            LifetimeMismatchLabels::Normal {
538                hir_equal,
539                ty_sup,
540                ty_sub,
541                span,
542                sup: label_var1,
543                sub: label_var2,
544            } => {
545                if hir_equal {
546                    diag.span_label(
547                        ty_sup,
548                        rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("this type is declared with multiple lifetimes..."))msg!("this type is declared with multiple lifetimes..."),
549                    );
550                    diag.span_label(ty_sub, rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("{\"\"}"))msg!("{\"\"}"));
551                    diag.span_label(
552                        span,
553                        rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("...but data with one lifetime flows into the other here"))msg!("...but data with one lifetime flows into the other here"),
554                    );
555                } else {
556                    diag.span_label(
557                        ty_sup,
558                        rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("these two types are declared with different lifetimes..."))msg!("these two types are declared with different lifetimes..."),
559                    );
560                    diag.span_label(ty_sub, rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("{\"\"}"))msg!("{\"\"}"));
561                    diag.span_label(
562                        span,
563                        rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("...but data{$label_var1_exists ->\n                                [true] {\" \"}from `{$label_var1}`\n                                *[false] {\"\"}\n                            } flows{$label_var2_exists ->\n                                [true] {\" \"}into `{$label_var2}`\n                                *[false] {\"\"}\n                            } here"))msg!(
564                            "...but data{$label_var1_exists ->
565                                [true] {\" \"}from `{$label_var1}`
566                                *[false] {\"\"}
567                            } flows{$label_var2_exists ->
568                                [true] {\" \"}into `{$label_var2}`
569                                *[false] {\"\"}
570                            } here"
571                        ),
572                    );
573                    diag.arg("label_var1_exists", label_var1.is_some());
574                    diag.arg("label_var1", label_var1.map(|x| x.to_string()).unwrap_or_default());
575                    diag.arg("label_var2_exists", label_var2.is_some());
576                    diag.arg("label_var2", label_var2.map(|x| x.to_string()).unwrap_or_default());
577                }
578            }
579        }
580    }
581}
582
583pub struct AddLifetimeParamsSuggestion<'a> {
584    pub tcx: TyCtxt<'a>,
585    pub generic_param_scope: LocalDefId,
586    pub sub: Region<'a>,
587    pub ty_sup: &'a hir::Ty<'a>,
588    pub ty_sub: &'a hir::Ty<'a>,
589    pub add_note: bool,
590}
591
592impl Subdiagnostic for AddLifetimeParamsSuggestion<'_> {
593    fn add_to_diag<G: EmissionGuarantee>(self, diag: &mut Diag<'_, G>) {
594        let mut mk_suggestion = || {
595            let Some(anon_reg) = self.tcx.is_suitable_region(self.generic_param_scope, self.sub)
596            else {
597                return false;
598            };
599
600            let node = self.tcx.hir_node_by_def_id(anon_reg.scope);
601            let is_impl = #[allow(non_exhaustive_omitted_patterns)] match &node {
    hir::Node::ImplItem(_) => true,
    _ => false,
}matches!(&node, hir::Node::ImplItem(_));
602            let (generics, parent_generics) = match node {
603                hir::Node::Item(hir::Item { kind: hir::ItemKind::Fn { generics, .. }, .. })
604                | hir::Node::TraitItem(hir::TraitItem { generics, .. })
605                | hir::Node::ImplItem(hir::ImplItem { generics, .. }) => (
606                    generics,
607                    match self.tcx.parent_hir_node(self.tcx.local_def_id_to_hir_id(anon_reg.scope))
608                    {
609                        hir::Node::Item(hir::Item {
610                            kind: hir::ItemKind::Trait(_, _, _, _, generics, ..),
611                            ..
612                        })
613                        | hir::Node::Item(hir::Item {
614                            kind: hir::ItemKind::Impl(hir::Impl { generics, .. }),
615                            ..
616                        }) => Some(generics),
617                        _ => None,
618                    },
619                ),
620                _ => return false,
621            };
622
623            let suggestion_param_name = generics
624                .params
625                .iter()
626                .filter(|p| #[allow(non_exhaustive_omitted_patterns)] match p.kind {
    GenericParamKind::Lifetime { .. } => true,
    _ => false,
}matches!(p.kind, GenericParamKind::Lifetime { .. }))
627                .map(|p| p.name.ident().name)
628                .find(|i| *i != kw::UnderscoreLifetime);
629            let introduce_new = suggestion_param_name.is_none();
630
631            let mut default = "'a".to_string();
632            if let Some(parent_generics) = parent_generics {
633                let used: FxHashSet<_> = parent_generics
634                    .params
635                    .iter()
636                    .filter(|p| #[allow(non_exhaustive_omitted_patterns)] match p.kind {
    GenericParamKind::Lifetime { .. } => true,
    _ => false,
}matches!(p.kind, GenericParamKind::Lifetime { .. }))
637                    .map(|p| p.name.ident().name)
638                    .filter(|i| *i != kw::UnderscoreLifetime)
639                    .map(|l| l.to_string())
640                    .collect();
641                if let Some(lt) =
642                    ('a'..='z').map(|it| ::alloc::__export::must_use({
        ::alloc::fmt::format(format_args!("\'{0}", it))
    })format!("'{it}")).find(|it| !used.contains(it))
643                {
644                    // We want a lifetime that *isn't* present in the `trait` or `impl` that assoc
645                    // `fn` belongs to. We could suggest reusing one of their lifetimes, but it is
646                    // likely to be an over-constraining lifetime requirement, so we always add a
647                    // lifetime to the `fn`.
648                    default = lt;
649                }
650            }
651            let suggestion_param_name =
652                suggestion_param_name.map(|n| n.to_string()).unwrap_or_else(|| default);
653
654            struct ImplicitLifetimeFinder {
655                suggestions: Vec<(Span, String)>,
656                suggestion_param_name: String,
657            }
658
659            impl<'v> Visitor<'v> for ImplicitLifetimeFinder {
660                fn visit_ty(&mut self, ty: &'v hir::Ty<'v, AmbigArg>) {
661                    match ty.kind {
662                        hir::TyKind::Path(hir::QPath::Resolved(_, path)) => {
663                            for segment in path.segments {
664                                if let Some(args) = segment.args {
665                                    if args.args.iter().all(|arg| {
666                                        #[allow(non_exhaustive_omitted_patterns)] match arg {
    hir::GenericArg::Lifetime(lifetime) if lifetime.is_implicit() => true,
    _ => false,
}matches!(
667                                            arg,
668                                            hir::GenericArg::Lifetime(lifetime)
669                                                if lifetime.is_implicit()
670                                        )
671                                    }) {
672                                        self.suggestions.push((
673                                            segment.ident.span.shrink_to_hi(),
674                                            ::alloc::__export::must_use({
        ::alloc::fmt::format(format_args!("<{0}>",
                args.args.iter().map(|_|
                                self.suggestion_param_name.clone()).collect::<Vec<_>>().join(", ")))
    })format!(
675                                                "<{}>",
676                                                args.args
677                                                    .iter()
678                                                    .map(|_| self.suggestion_param_name.clone())
679                                                    .collect::<Vec<_>>()
680                                                    .join(", ")
681                                            ),
682                                        ));
683                                    } else {
684                                        for arg in args.args {
685                                            if let hir::GenericArg::Lifetime(lifetime) = arg
686                                                && lifetime.is_anonymous()
687                                            {
688                                                self.suggestions.push(
689                                                    lifetime
690                                                        .suggestion(&self.suggestion_param_name),
691                                                );
692                                            }
693                                        }
694                                    }
695                                }
696                            }
697                        }
698                        hir::TyKind::Ref(lifetime, ..) if lifetime.is_anonymous() => {
699                            self.suggestions.push(lifetime.suggestion(&self.suggestion_param_name));
700                        }
701                        _ => {}
702                    }
703                    walk_ty(self, ty);
704                }
705            }
706            let mut visitor = ImplicitLifetimeFinder {
707                suggestions: ::alloc::vec::Vec::new()vec![],
708                suggestion_param_name: suggestion_param_name.clone(),
709            };
710            if let Some(fn_decl) = node.fn_decl()
711                && let hir::FnRetTy::Return(ty) = fn_decl.output
712            {
713                visitor.visit_ty_unambig(ty);
714            }
715            if visitor.suggestions.is_empty() {
716                // Do not suggest constraining the `&self` param, but rather the return type.
717                // If that is wrong (because it is not sufficient), a follow up error will tell the
718                // user to fix it. This way we lower the chances of *over* constraining, but still
719                // get the cake of "correctly" constrained in two steps.
720                visitor.visit_ty_unambig(self.ty_sup);
721            }
722            visitor.visit_ty_unambig(self.ty_sub);
723            if visitor.suggestions.is_empty() {
724                return false;
725            }
726            if introduce_new {
727                let new_param_suggestion = if let Some(first) =
728                    generics.params.iter().find(|p| !p.name.ident().span.is_empty())
729                {
730                    (first.span.shrink_to_lo(), ::alloc::__export::must_use({
        ::alloc::fmt::format(format_args!("{0}, ", suggestion_param_name))
    })format!("{suggestion_param_name}, "))
731                } else {
732                    (generics.span, ::alloc::__export::must_use({
        ::alloc::fmt::format(format_args!("<{0}>", suggestion_param_name))
    })format!("<{suggestion_param_name}>"))
733                };
734
735                visitor.suggestions.push(new_param_suggestion);
736            }
737            diag.multipart_suggestion(
738                rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("consider {$is_reuse ->\n                        [true] reusing\n                        *[false] introducing\n                    } a named lifetime parameter{$is_impl ->\n                        [true] {\" \"}and update trait if needed\n                        *[false] {\"\"}\n                    }"))msg!(
739                    "consider {$is_reuse ->
740                        [true] reusing
741                        *[false] introducing
742                    } a named lifetime parameter{$is_impl ->
743                        [true] {\" \"}and update trait if needed
744                        *[false] {\"\"}
745                    }"
746                ),
747                visitor.suggestions,
748                Applicability::MaybeIncorrect,
749            );
750            diag.arg("is_impl", is_impl);
751            diag.arg("is_reuse", !introduce_new);
752
753            true
754        };
755        if mk_suggestion() && self.add_note {
756            diag.note(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("each elided lifetime in input position becomes a distinct lifetime"))msg!("each elided lifetime in input position becomes a distinct lifetime"));
757        }
758    }
759}
760
761#[derive(const _: () =
    {
        impl<'_sess, 'a, G> rustc_errors::Diagnostic<'_sess, G> for
            LifetimeMismatch<'a> where G: rustc_errors::EmissionGuarantee {
            #[track_caller]
            fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
                level: rustc_errors::Level) -> rustc_errors::Diag<'_sess, G> {
                match self {
                    LifetimeMismatch {
                        span: __binding_0,
                        labels: __binding_1,
                        suggestion: __binding_2 } => {
                        let mut diag =
                            rustc_errors::Diag::new(dcx, level,
                                rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("lifetime mismatch")));
                        diag.code(E0623);
                        ;
                        diag.span(__binding_0);
                        diag.subdiagnostic(__binding_1);
                        diag.subdiagnostic(__binding_2);
                        diag
                    }
                }
            }
        }
    };Diagnostic)]
762#[diag("lifetime mismatch", code = E0623)]
763pub struct LifetimeMismatch<'a> {
764    #[primary_span]
765    pub span: Span,
766    #[subdiagnostic]
767    pub labels: LifetimeMismatchLabels,
768    #[subdiagnostic]
769    pub suggestion: AddLifetimeParamsSuggestion<'a>,
770}
771
772pub struct IntroducesStaticBecauseUnmetLifetimeReq {
773    pub unmet_requirements: MultiSpan,
774    pub binding_span: Span,
775}
776
777impl Subdiagnostic for IntroducesStaticBecauseUnmetLifetimeReq {
778    fn add_to_diag<G: EmissionGuarantee>(mut self, diag: &mut Diag<'_, G>) {
779        self.unmet_requirements.push_span_label(
780            self.binding_span,
781            rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("introduces a `'static` lifetime requirement"))msg!("introduces a `'static` lifetime requirement"),
782        );
783        diag.span_note(
784            self.unmet_requirements,
785            rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("because this has an unmet lifetime requirement"))msg!("because this has an unmet lifetime requirement"),
786        );
787    }
788}
789
790// FIXME(#100717): replace with a `Option<Span>` when subdiagnostic supports that
791#[derive(const _: () =
    {
        impl rustc_errors::Subdiagnostic for DoesNotOutliveStaticFromImpl {
            fn add_to_diag<__G>(self, diag: &mut rustc_errors::Diag<'_, __G>)
                where __G: rustc_errors::EmissionGuarantee {
                match self {
                    DoesNotOutliveStaticFromImpl::Spanned { span: __binding_0 }
                        => {
                        let mut sub_args = rustc_errors::DiagArgMap::default();
                        let __message =
                            rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("...does not necessarily outlive the static lifetime introduced by the compatible `impl`")),
                                &sub_args);
                        diag.span_note(__binding_0, __message);
                    }
                    DoesNotOutliveStaticFromImpl::Unspanned => {
                        let mut sub_args = rustc_errors::DiagArgMap::default();
                        let __message =
                            rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("...does not necessarily outlive the static lifetime introduced by the compatible `impl`")),
                                &sub_args);
                        diag.note(__message);
                    }
                }
            }
        }
    };Subdiagnostic)]
792pub enum DoesNotOutliveStaticFromImpl {
793    #[note(
794        "...does not necessarily outlive the static lifetime introduced by the compatible `impl`"
795    )]
796    Spanned {
797        #[primary_span]
798        span: Span,
799    },
800    #[note(
801        "...does not necessarily outlive the static lifetime introduced by the compatible `impl`"
802    )]
803    Unspanned,
804}
805
806#[derive(const _: () =
    {
        impl rustc_errors::Subdiagnostic for ImplicitStaticLifetimeSubdiag {
            fn add_to_diag<__G>(self, diag: &mut rustc_errors::Diag<'_, __G>)
                where __G: rustc_errors::EmissionGuarantee {
                match self {
                    ImplicitStaticLifetimeSubdiag::Note { span: __binding_0 } =>
                        {
                        let mut sub_args = rustc_errors::DiagArgMap::default();
                        let __message =
                            rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("this has an implicit `'static` lifetime requirement")),
                                &sub_args);
                        diag.span_note(__binding_0, __message);
                    }
                    ImplicitStaticLifetimeSubdiag::Sugg { span: __binding_0 } =>
                        {
                        let __code_6 =
                            [::alloc::__export::must_use({
                                                ::alloc::fmt::format(format_args!(" + \'_"))
                                            })].into_iter();
                        let mut sub_args = rustc_errors::DiagArgMap::default();
                        let __message =
                            rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("consider relaxing the implicit `'static` requirement")),
                                &sub_args);
                        diag.span_suggestions_with_style(__binding_0, __message,
                            __code_6, rustc_errors::Applicability::MaybeIncorrect,
                            rustc_errors::SuggestionStyle::ShowAlways);
                    }
                }
            }
        }
    };Subdiagnostic)]
807pub enum ImplicitStaticLifetimeSubdiag {
808    #[note("this has an implicit `'static` lifetime requirement")]
809    Note {
810        #[primary_span]
811        span: Span,
812    },
813    #[suggestion(
814        "consider relaxing the implicit `'static` requirement",
815        style = "verbose",
816        code = " + '_",
817        applicability = "maybe-incorrect"
818    )]
819    Sugg {
820        #[primary_span]
821        span: Span,
822    },
823}
824
825#[derive(const _: () =
    {
        impl<'_sess, 'a, G> rustc_errors::Diagnostic<'_sess, G> for
            MismatchedStaticLifetime<'a> where
            G: rustc_errors::EmissionGuarantee {
            #[track_caller]
            fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
                level: rustc_errors::Level) -> rustc_errors::Diag<'_sess, G> {
                match self {
                    MismatchedStaticLifetime {
                        cause_span: __binding_0,
                        unmet_lifetime_reqs: __binding_1,
                        expl: __binding_2,
                        does_not_outlive_static_from_impl: __binding_3,
                        implicit_static_lifetimes: __binding_4 } => {
                        let mut diag =
                            rustc_errors::Diag::new(dcx, level,
                                rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("incompatible lifetime on type")));
                        ;
                        diag.span(__binding_0);
                        diag.subdiagnostic(__binding_1);
                        if let Some(__binding_2) = __binding_2 {
                            diag.subdiagnostic(__binding_2);
                        }
                        diag.subdiagnostic(__binding_3);
                        for __binding_4 in __binding_4 {
                            diag.subdiagnostic(__binding_4);
                        }
                        diag
                    }
                }
            }
        }
    };Diagnostic)]
826#[diag("incompatible lifetime on type")]
827pub struct MismatchedStaticLifetime<'a> {
828    #[primary_span]
829    pub cause_span: Span,
830    #[subdiagnostic]
831    pub unmet_lifetime_reqs: IntroducesStaticBecauseUnmetLifetimeReq,
832    #[subdiagnostic]
833    pub expl: Option<note_and_explain::RegionExplanation<'a>>,
834    #[subdiagnostic]
835    pub does_not_outlive_static_from_impl: DoesNotOutliveStaticFromImpl,
836    #[subdiagnostic]
837    pub implicit_static_lifetimes: Vec<ImplicitStaticLifetimeSubdiag>,
838}
839
840#[derive(const _: () =
    {
        impl<'_sess, 'a, G> rustc_errors::Diagnostic<'_sess, G> for
            ExplicitLifetimeRequired<'a> where
            G: rustc_errors::EmissionGuarantee {
            #[track_caller]
            fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
                level: rustc_errors::Level) -> rustc_errors::Diag<'_sess, G> {
                match self {
                    ExplicitLifetimeRequired::WithIdent {
                        span: __binding_0,
                        simple_ident: __binding_1,
                        named: __binding_2,
                        new_ty_span: __binding_3,
                        new_ty: __binding_4 } => {
                        let mut diag =
                            rustc_errors::Diag::new(dcx, level,
                                rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("explicit lifetime required in the type of `{$simple_ident}`")));
                        let __code_7 =
                            [::alloc::__export::must_use({
                                                ::alloc::fmt::format(format_args!("{0}", __binding_4))
                                            })].into_iter();
                        diag.code(E0621);
                        ;
                        diag.arg("simple_ident", __binding_1);
                        diag.arg("named", __binding_2);
                        diag.span(__binding_0);
                        diag.span_label(__binding_0,
                            rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("lifetime `{$named}` required")));
                        diag.span_suggestions_with_style(__binding_3,
                            rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("add explicit lifetime `{$named}` to the type of `{$simple_ident}`")),
                            __code_7, rustc_errors::Applicability::Unspecified,
                            rustc_errors::SuggestionStyle::ShowAlways);
                        diag
                    }
                    ExplicitLifetimeRequired::WithParamType {
                        span: __binding_0,
                        named: __binding_1,
                        new_ty_span: __binding_2,
                        new_ty: __binding_3 } => {
                        let mut diag =
                            rustc_errors::Diag::new(dcx, level,
                                rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("explicit lifetime required in parameter type")));
                        let __code_8 =
                            [::alloc::__export::must_use({
                                                ::alloc::fmt::format(format_args!("{0}", __binding_3))
                                            })].into_iter();
                        diag.code(E0621);
                        ;
                        diag.arg("named", __binding_1);
                        diag.span(__binding_0);
                        diag.span_label(__binding_0,
                            rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("lifetime `{$named}` required")));
                        diag.span_suggestions_with_style(__binding_2,
                            rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("add explicit lifetime `{$named}` to type")),
                            __code_8, rustc_errors::Applicability::Unspecified,
                            rustc_errors::SuggestionStyle::ShowAlways);
                        diag
                    }
                }
            }
        }
    };Diagnostic)]
841pub enum ExplicitLifetimeRequired<'a> {
842    #[diag("explicit lifetime required in the type of `{$simple_ident}`", code = E0621)]
843    WithIdent {
844        #[primary_span]
845        #[label("lifetime `{$named}` required")]
846        span: Span,
847        simple_ident: Ident,
848        named: String,
849        #[suggestion(
850            "add explicit lifetime `{$named}` to the type of `{$simple_ident}`",
851            code = "{new_ty}",
852            applicability = "unspecified",
853            style = "verbose"
854        )]
855        new_ty_span: Span,
856        #[skip_arg]
857        new_ty: Ty<'a>,
858    },
859    #[diag("explicit lifetime required in parameter type", code = E0621)]
860    WithParamType {
861        #[primary_span]
862        #[label("lifetime `{$named}` required")]
863        span: Span,
864        named: String,
865        #[suggestion(
866            "add explicit lifetime `{$named}` to type",
867            code = "{new_ty}",
868            applicability = "unspecified",
869            style = "verbose"
870        )]
871        new_ty_span: Span,
872        #[skip_arg]
873        new_ty: Ty<'a>,
874    },
875}
876
877pub enum TyOrSig<'tcx> {
878    Ty(Highlighted<'tcx, Ty<'tcx>>),
879    ClosureSig(Highlighted<'tcx, Binder<'tcx, FnSig<'tcx>>>),
880}
881
882impl IntoDiagArg for TyOrSig<'_> {
883    fn into_diag_arg(self, path: &mut Option<std::path::PathBuf>) -> rustc_errors::DiagArgValue {
884        match self {
885            TyOrSig::Ty(ty) => ty.into_diag_arg(path),
886            TyOrSig::ClosureSig(sig) => sig.into_diag_arg(path),
887        }
888    }
889}
890
891#[derive(const _: () =
    {
        impl<'tcx> rustc_errors::Subdiagnostic for ActualImplExplNotes<'tcx> {
            fn add_to_diag<__G>(self, diag: &mut rustc_errors::Diag<'_, __G>)
                where __G: rustc_errors::EmissionGuarantee {
                match self {
                    ActualImplExplNotes::ExpectedSignatureTwo {
                        leading_ellipsis: __binding_0,
                        ty_or_sig: __binding_1,
                        trait_path: __binding_2,
                        lifetime_1: __binding_3,
                        lifetime_2: __binding_4 } => {
                        let mut sub_args = rustc_errors::DiagArgMap::default();
                        sub_args.insert("leading_ellipsis".into(),
                            rustc_errors::IntoDiagArg::into_diag_arg(__binding_0,
                                &mut diag.long_ty_path));
                        sub_args.insert("ty_or_sig".into(),
                            rustc_errors::IntoDiagArg::into_diag_arg(__binding_1,
                                &mut diag.long_ty_path));
                        sub_args.insert("trait_path".into(),
                            rustc_errors::IntoDiagArg::into_diag_arg(__binding_2,
                                &mut diag.long_ty_path));
                        sub_args.insert("lifetime_1".into(),
                            rustc_errors::IntoDiagArg::into_diag_arg(__binding_3,
                                &mut diag.long_ty_path));
                        sub_args.insert("lifetime_2".into(),
                            rustc_errors::IntoDiagArg::into_diag_arg(__binding_4,
                                &mut diag.long_ty_path));
                        let __message =
                            rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("{$leading_ellipsis ->\n        [true] ...\n        *[false] {\"\"}\n    }closure with signature `{$ty_or_sig}` must implement `{$trait_path}`, for any two lifetimes `'{$lifetime_1}` and `'{$lifetime_2}`...")),
                                &sub_args);
                        diag.note(__message);
                    }
                    ActualImplExplNotes::ExpectedSignatureAny {
                        leading_ellipsis: __binding_0,
                        ty_or_sig: __binding_1,
                        trait_path: __binding_2,
                        lifetime_1: __binding_3 } => {
                        let mut sub_args = rustc_errors::DiagArgMap::default();
                        sub_args.insert("leading_ellipsis".into(),
                            rustc_errors::IntoDiagArg::into_diag_arg(__binding_0,
                                &mut diag.long_ty_path));
                        sub_args.insert("ty_or_sig".into(),
                            rustc_errors::IntoDiagArg::into_diag_arg(__binding_1,
                                &mut diag.long_ty_path));
                        sub_args.insert("trait_path".into(),
                            rustc_errors::IntoDiagArg::into_diag_arg(__binding_2,
                                &mut diag.long_ty_path));
                        sub_args.insert("lifetime_1".into(),
                            rustc_errors::IntoDiagArg::into_diag_arg(__binding_3,
                                &mut diag.long_ty_path));
                        let __message =
                            rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("{$leading_ellipsis ->\n        [true] ...\n        *[false] {\"\"}\n    }closure with signature `{$ty_or_sig}` must implement `{$trait_path}`, for any lifetime `'{$lifetime_1}`...")),
                                &sub_args);
                        diag.note(__message);
                    }
                    ActualImplExplNotes::ExpectedSignatureSome {
                        leading_ellipsis: __binding_0,
                        ty_or_sig: __binding_1,
                        trait_path: __binding_2,
                        lifetime_1: __binding_3 } => {
                        let mut sub_args = rustc_errors::DiagArgMap::default();
                        sub_args.insert("leading_ellipsis".into(),
                            rustc_errors::IntoDiagArg::into_diag_arg(__binding_0,
                                &mut diag.long_ty_path));
                        sub_args.insert("ty_or_sig".into(),
                            rustc_errors::IntoDiagArg::into_diag_arg(__binding_1,
                                &mut diag.long_ty_path));
                        sub_args.insert("trait_path".into(),
                            rustc_errors::IntoDiagArg::into_diag_arg(__binding_2,
                                &mut diag.long_ty_path));
                        sub_args.insert("lifetime_1".into(),
                            rustc_errors::IntoDiagArg::into_diag_arg(__binding_3,
                                &mut diag.long_ty_path));
                        let __message =
                            rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("{$leading_ellipsis ->\n        [true] ...\n        *[false] {\"\"}\n    }closure with signature `{$ty_or_sig}` must implement `{$trait_path}`, for some specific lifetime `'{$lifetime_1}`...")),
                                &sub_args);
                        diag.note(__message);
                    }
                    ActualImplExplNotes::ExpectedSignatureNothing {
                        leading_ellipsis: __binding_0,
                        ty_or_sig: __binding_1,
                        trait_path: __binding_2 } => {
                        let mut sub_args = rustc_errors::DiagArgMap::default();
                        sub_args.insert("leading_ellipsis".into(),
                            rustc_errors::IntoDiagArg::into_diag_arg(__binding_0,
                                &mut diag.long_ty_path));
                        sub_args.insert("ty_or_sig".into(),
                            rustc_errors::IntoDiagArg::into_diag_arg(__binding_1,
                                &mut diag.long_ty_path));
                        sub_args.insert("trait_path".into(),
                            rustc_errors::IntoDiagArg::into_diag_arg(__binding_2,
                                &mut diag.long_ty_path));
                        let __message =
                            rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("{$leading_ellipsis ->\n            [true] ...\n            *[false] {\"\"}\n        }closure with signature `{$ty_or_sig}` must implement `{$trait_path}`")),
                                &sub_args);
                        diag.note(__message);
                    }
                    ActualImplExplNotes::ExpectedPassiveTwo {
                        leading_ellipsis: __binding_0,
                        ty_or_sig: __binding_1,
                        trait_path: __binding_2,
                        lifetime_1: __binding_3,
                        lifetime_2: __binding_4 } => {
                        let mut sub_args = rustc_errors::DiagArgMap::default();
                        sub_args.insert("leading_ellipsis".into(),
                            rustc_errors::IntoDiagArg::into_diag_arg(__binding_0,
                                &mut diag.long_ty_path));
                        sub_args.insert("ty_or_sig".into(),
                            rustc_errors::IntoDiagArg::into_diag_arg(__binding_1,
                                &mut diag.long_ty_path));
                        sub_args.insert("trait_path".into(),
                            rustc_errors::IntoDiagArg::into_diag_arg(__binding_2,
                                &mut diag.long_ty_path));
                        sub_args.insert("lifetime_1".into(),
                            rustc_errors::IntoDiagArg::into_diag_arg(__binding_3,
                                &mut diag.long_ty_path));
                        sub_args.insert("lifetime_2".into(),
                            rustc_errors::IntoDiagArg::into_diag_arg(__binding_4,
                                &mut diag.long_ty_path));
                        let __message =
                            rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("{$leading_ellipsis ->\n        [true] ...\n        *[false] {\"\"}\n    }`{$trait_path}` would have to be implemented for the type `{$ty_or_sig}`, for any two lifetimes `'{$lifetime_1}` and `'{$lifetime_2}`...")),
                                &sub_args);
                        diag.note(__message);
                    }
                    ActualImplExplNotes::ExpectedPassiveAny {
                        leading_ellipsis: __binding_0,
                        ty_or_sig: __binding_1,
                        trait_path: __binding_2,
                        lifetime_1: __binding_3 } => {
                        let mut sub_args = rustc_errors::DiagArgMap::default();
                        sub_args.insert("leading_ellipsis".into(),
                            rustc_errors::IntoDiagArg::into_diag_arg(__binding_0,
                                &mut diag.long_ty_path));
                        sub_args.insert("ty_or_sig".into(),
                            rustc_errors::IntoDiagArg::into_diag_arg(__binding_1,
                                &mut diag.long_ty_path));
                        sub_args.insert("trait_path".into(),
                            rustc_errors::IntoDiagArg::into_diag_arg(__binding_2,
                                &mut diag.long_ty_path));
                        sub_args.insert("lifetime_1".into(),
                            rustc_errors::IntoDiagArg::into_diag_arg(__binding_3,
                                &mut diag.long_ty_path));
                        let __message =
                            rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("{$leading_ellipsis ->\n        [true] ...\n        *[false] {\"\"}\n    }`{$trait_path}` would have to be implemented for the type `{$ty_or_sig}`, for any lifetime `'{$lifetime_1}`...")),
                                &sub_args);
                        diag.note(__message);
                    }
                    ActualImplExplNotes::ExpectedPassiveSome {
                        leading_ellipsis: __binding_0,
                        ty_or_sig: __binding_1,
                        trait_path: __binding_2,
                        lifetime_1: __binding_3 } => {
                        let mut sub_args = rustc_errors::DiagArgMap::default();
                        sub_args.insert("leading_ellipsis".into(),
                            rustc_errors::IntoDiagArg::into_diag_arg(__binding_0,
                                &mut diag.long_ty_path));
                        sub_args.insert("ty_or_sig".into(),
                            rustc_errors::IntoDiagArg::into_diag_arg(__binding_1,
                                &mut diag.long_ty_path));
                        sub_args.insert("trait_path".into(),
                            rustc_errors::IntoDiagArg::into_diag_arg(__binding_2,
                                &mut diag.long_ty_path));
                        sub_args.insert("lifetime_1".into(),
                            rustc_errors::IntoDiagArg::into_diag_arg(__binding_3,
                                &mut diag.long_ty_path));
                        let __message =
                            rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("{$leading_ellipsis ->\n        [true] ...\n        *[false] {\"\"}\n    }`{$trait_path}` would have to be implemented for the type `{$ty_or_sig}`, for some specific lifetime `'{$lifetime_1}`...")),
                                &sub_args);
                        diag.note(__message);
                    }
                    ActualImplExplNotes::ExpectedPassiveNothing {
                        leading_ellipsis: __binding_0,
                        ty_or_sig: __binding_1,
                        trait_path: __binding_2 } => {
                        let mut sub_args = rustc_errors::DiagArgMap::default();
                        sub_args.insert("leading_ellipsis".into(),
                            rustc_errors::IntoDiagArg::into_diag_arg(__binding_0,
                                &mut diag.long_ty_path));
                        sub_args.insert("ty_or_sig".into(),
                            rustc_errors::IntoDiagArg::into_diag_arg(__binding_1,
                                &mut diag.long_ty_path));
                        sub_args.insert("trait_path".into(),
                            rustc_errors::IntoDiagArg::into_diag_arg(__binding_2,
                                &mut diag.long_ty_path));
                        let __message =
                            rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("{$leading_ellipsis ->\n            [true] ...\n            *[false] {\"\"}\n        }`{$trait_path}` would have to be implemented for the type `{$ty_or_sig}`")),
                                &sub_args);
                        diag.note(__message);
                    }
                    ActualImplExplNotes::ExpectedOtherTwo {
                        leading_ellipsis: __binding_0,
                        ty_or_sig: __binding_1,
                        trait_path: __binding_2,
                        lifetime_1: __binding_3,
                        lifetime_2: __binding_4 } => {
                        let mut sub_args = rustc_errors::DiagArgMap::default();
                        sub_args.insert("leading_ellipsis".into(),
                            rustc_errors::IntoDiagArg::into_diag_arg(__binding_0,
                                &mut diag.long_ty_path));
                        sub_args.insert("ty_or_sig".into(),
                            rustc_errors::IntoDiagArg::into_diag_arg(__binding_1,
                                &mut diag.long_ty_path));
                        sub_args.insert("trait_path".into(),
                            rustc_errors::IntoDiagArg::into_diag_arg(__binding_2,
                                &mut diag.long_ty_path));
                        sub_args.insert("lifetime_1".into(),
                            rustc_errors::IntoDiagArg::into_diag_arg(__binding_3,
                                &mut diag.long_ty_path));
                        sub_args.insert("lifetime_2".into(),
                            rustc_errors::IntoDiagArg::into_diag_arg(__binding_4,
                                &mut diag.long_ty_path));
                        let __message =
                            rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("{$leading_ellipsis ->\n        [true] ...\n        *[false] {\"\"}\n    }`{$ty_or_sig}` must implement `{$trait_path}`, for any two lifetimes `'{$lifetime_1}` and `'{$lifetime_2}`...")),
                                &sub_args);
                        diag.note(__message);
                    }
                    ActualImplExplNotes::ExpectedOtherAny {
                        leading_ellipsis: __binding_0,
                        ty_or_sig: __binding_1,
                        trait_path: __binding_2,
                        lifetime_1: __binding_3 } => {
                        let mut sub_args = rustc_errors::DiagArgMap::default();
                        sub_args.insert("leading_ellipsis".into(),
                            rustc_errors::IntoDiagArg::into_diag_arg(__binding_0,
                                &mut diag.long_ty_path));
                        sub_args.insert("ty_or_sig".into(),
                            rustc_errors::IntoDiagArg::into_diag_arg(__binding_1,
                                &mut diag.long_ty_path));
                        sub_args.insert("trait_path".into(),
                            rustc_errors::IntoDiagArg::into_diag_arg(__binding_2,
                                &mut diag.long_ty_path));
                        sub_args.insert("lifetime_1".into(),
                            rustc_errors::IntoDiagArg::into_diag_arg(__binding_3,
                                &mut diag.long_ty_path));
                        let __message =
                            rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("{$leading_ellipsis ->\n            [true] ...\n            *[false] {\"\"}\n        }`{$ty_or_sig}` must implement `{$trait_path}`, for any lifetime `'{$lifetime_1}`...")),
                                &sub_args);
                        diag.note(__message);
                    }
                    ActualImplExplNotes::ExpectedOtherSome {
                        leading_ellipsis: __binding_0,
                        ty_or_sig: __binding_1,
                        trait_path: __binding_2,
                        lifetime_1: __binding_3 } => {
                        let mut sub_args = rustc_errors::DiagArgMap::default();
                        sub_args.insert("leading_ellipsis".into(),
                            rustc_errors::IntoDiagArg::into_diag_arg(__binding_0,
                                &mut diag.long_ty_path));
                        sub_args.insert("ty_or_sig".into(),
                            rustc_errors::IntoDiagArg::into_diag_arg(__binding_1,
                                &mut diag.long_ty_path));
                        sub_args.insert("trait_path".into(),
                            rustc_errors::IntoDiagArg::into_diag_arg(__binding_2,
                                &mut diag.long_ty_path));
                        sub_args.insert("lifetime_1".into(),
                            rustc_errors::IntoDiagArg::into_diag_arg(__binding_3,
                                &mut diag.long_ty_path));
                        let __message =
                            rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("{$leading_ellipsis ->\n            [true] ...\n            *[false] {\"\"}\n        }`{$ty_or_sig}` must implement `{$trait_path}`, for some specific lifetime `'{$lifetime_1}`...")),
                                &sub_args);
                        diag.note(__message);
                    }
                    ActualImplExplNotes::ExpectedOtherNothing {
                        leading_ellipsis: __binding_0,
                        ty_or_sig: __binding_1,
                        trait_path: __binding_2 } => {
                        let mut sub_args = rustc_errors::DiagArgMap::default();
                        sub_args.insert("leading_ellipsis".into(),
                            rustc_errors::IntoDiagArg::into_diag_arg(__binding_0,
                                &mut diag.long_ty_path));
                        sub_args.insert("ty_or_sig".into(),
                            rustc_errors::IntoDiagArg::into_diag_arg(__binding_1,
                                &mut diag.long_ty_path));
                        sub_args.insert("trait_path".into(),
                            rustc_errors::IntoDiagArg::into_diag_arg(__binding_2,
                                &mut diag.long_ty_path));
                        let __message =
                            rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("{$leading_ellipsis ->\n            [true] ...\n            *[false] {\"\"}\n        }`{$ty_or_sig}` must implement `{$trait_path}`")),
                                &sub_args);
                        diag.note(__message);
                    }
                    ActualImplExplNotes::ButActuallyImplementsTrait {
                        trait_path: __binding_0,
                        has_lifetime: __binding_1,
                        lifetime: __binding_2 } => {
                        let mut sub_args = rustc_errors::DiagArgMap::default();
                        sub_args.insert("trait_path".into(),
                            rustc_errors::IntoDiagArg::into_diag_arg(__binding_0,
                                &mut diag.long_ty_path));
                        sub_args.insert("has_lifetime".into(),
                            rustc_errors::IntoDiagArg::into_diag_arg(__binding_1,
                                &mut diag.long_ty_path));
                        sub_args.insert("lifetime".into(),
                            rustc_errors::IntoDiagArg::into_diag_arg(__binding_2,
                                &mut diag.long_ty_path));
                        let __message =
                            rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("...but it actually implements `{$trait_path}`{$has_lifetime ->\n            [true] , for some specific lifetime `'{$lifetime}`\n            *[false] {\"\"}\n        }")),
                                &sub_args);
                        diag.note(__message);
                    }
                    ActualImplExplNotes::ButActuallyImplementedForTy {
                        trait_path: __binding_0,
                        has_lifetime: __binding_1,
                        lifetime: __binding_2,
                        ty: __binding_3 } => {
                        let mut sub_args = rustc_errors::DiagArgMap::default();
                        sub_args.insert("trait_path".into(),
                            rustc_errors::IntoDiagArg::into_diag_arg(__binding_0,
                                &mut diag.long_ty_path));
                        sub_args.insert("has_lifetime".into(),
                            rustc_errors::IntoDiagArg::into_diag_arg(__binding_1,
                                &mut diag.long_ty_path));
                        sub_args.insert("lifetime".into(),
                            rustc_errors::IntoDiagArg::into_diag_arg(__binding_2,
                                &mut diag.long_ty_path));
                        sub_args.insert("ty".into(),
                            rustc_errors::IntoDiagArg::into_diag_arg(__binding_3,
                                &mut diag.long_ty_path));
                        let __message =
                            rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("...but `{$trait_path}` is actually implemented for the type `{$ty}`{$has_lifetime ->\n            [true] , for some specific lifetime `'{$lifetime}`\n            *[false] {\"\"}\n        }")),
                                &sub_args);
                        diag.note(__message);
                    }
                    ActualImplExplNotes::ButActuallyTyImplements {
                        trait_path: __binding_0,
                        has_lifetime: __binding_1,
                        lifetime: __binding_2,
                        ty: __binding_3 } => {
                        let mut sub_args = rustc_errors::DiagArgMap::default();
                        sub_args.insert("trait_path".into(),
                            rustc_errors::IntoDiagArg::into_diag_arg(__binding_0,
                                &mut diag.long_ty_path));
                        sub_args.insert("has_lifetime".into(),
                            rustc_errors::IntoDiagArg::into_diag_arg(__binding_1,
                                &mut diag.long_ty_path));
                        sub_args.insert("lifetime".into(),
                            rustc_errors::IntoDiagArg::into_diag_arg(__binding_2,
                                &mut diag.long_ty_path));
                        sub_args.insert("ty".into(),
                            rustc_errors::IntoDiagArg::into_diag_arg(__binding_3,
                                &mut diag.long_ty_path));
                        let __message =
                            rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("...but `{$ty}` actually implements `{$trait_path}`{$has_lifetime ->\n            [true] , for some specific lifetime `'{$lifetime}`\n            *[false] {\"\"}\n        }")),
                                &sub_args);
                        diag.note(__message);
                    }
                }
            }
        }
    };Subdiagnostic)]
892pub enum ActualImplExplNotes<'tcx> {
893    #[note("{$leading_ellipsis ->
894        [true] ...
895        *[false] {\"\"}
896    }closure with signature `{$ty_or_sig}` must implement `{$trait_path}`, for any two lifetimes `'{$lifetime_1}` and `'{$lifetime_2}`...")]
897    ExpectedSignatureTwo {
898        leading_ellipsis: bool,
899        ty_or_sig: TyOrSig<'tcx>,
900        trait_path: Highlighted<'tcx, TraitRefPrintOnlyTraitPath<'tcx>>,
901        lifetime_1: usize,
902        lifetime_2: usize,
903    },
904    #[note("{$leading_ellipsis ->
905        [true] ...
906        *[false] {\"\"}
907    }closure with signature `{$ty_or_sig}` must implement `{$trait_path}`, for any lifetime `'{$lifetime_1}`...")]
908    ExpectedSignatureAny {
909        leading_ellipsis: bool,
910        ty_or_sig: TyOrSig<'tcx>,
911        trait_path: Highlighted<'tcx, TraitRefPrintOnlyTraitPath<'tcx>>,
912        lifetime_1: usize,
913    },
914    #[note("{$leading_ellipsis ->
915        [true] ...
916        *[false] {\"\"}
917    }closure with signature `{$ty_or_sig}` must implement `{$trait_path}`, for some specific lifetime `'{$lifetime_1}`...")]
918    ExpectedSignatureSome {
919        leading_ellipsis: bool,
920        ty_or_sig: TyOrSig<'tcx>,
921        trait_path: Highlighted<'tcx, TraitRefPrintOnlyTraitPath<'tcx>>,
922        lifetime_1: usize,
923    },
924    #[note(
925        "{$leading_ellipsis ->
926            [true] ...
927            *[false] {\"\"}
928        }closure with signature `{$ty_or_sig}` must implement `{$trait_path}`"
929    )]
930    ExpectedSignatureNothing {
931        leading_ellipsis: bool,
932        ty_or_sig: TyOrSig<'tcx>,
933        trait_path: Highlighted<'tcx, TraitRefPrintOnlyTraitPath<'tcx>>,
934    },
935    #[note("{$leading_ellipsis ->
936        [true] ...
937        *[false] {\"\"}
938    }`{$trait_path}` would have to be implemented for the type `{$ty_or_sig}`, for any two lifetimes `'{$lifetime_1}` and `'{$lifetime_2}`...")]
939    ExpectedPassiveTwo {
940        leading_ellipsis: bool,
941        ty_or_sig: TyOrSig<'tcx>,
942        trait_path: Highlighted<'tcx, TraitRefPrintOnlyTraitPath<'tcx>>,
943        lifetime_1: usize,
944        lifetime_2: usize,
945    },
946    #[note("{$leading_ellipsis ->
947        [true] ...
948        *[false] {\"\"}
949    }`{$trait_path}` would have to be implemented for the type `{$ty_or_sig}`, for any lifetime `'{$lifetime_1}`...")]
950    ExpectedPassiveAny {
951        leading_ellipsis: bool,
952        ty_or_sig: TyOrSig<'tcx>,
953        trait_path: Highlighted<'tcx, TraitRefPrintOnlyTraitPath<'tcx>>,
954        lifetime_1: usize,
955    },
956    #[note("{$leading_ellipsis ->
957        [true] ...
958        *[false] {\"\"}
959    }`{$trait_path}` would have to be implemented for the type `{$ty_or_sig}`, for some specific lifetime `'{$lifetime_1}`...")]
960    ExpectedPassiveSome {
961        leading_ellipsis: bool,
962        ty_or_sig: TyOrSig<'tcx>,
963        trait_path: Highlighted<'tcx, TraitRefPrintOnlyTraitPath<'tcx>>,
964        lifetime_1: usize,
965    },
966    #[note(
967        "{$leading_ellipsis ->
968            [true] ...
969            *[false] {\"\"}
970        }`{$trait_path}` would have to be implemented for the type `{$ty_or_sig}`"
971    )]
972    ExpectedPassiveNothing {
973        leading_ellipsis: bool,
974        ty_or_sig: TyOrSig<'tcx>,
975        trait_path: Highlighted<'tcx, TraitRefPrintOnlyTraitPath<'tcx>>,
976    },
977    #[note("{$leading_ellipsis ->
978        [true] ...
979        *[false] {\"\"}
980    }`{$ty_or_sig}` must implement `{$trait_path}`, for any two lifetimes `'{$lifetime_1}` and `'{$lifetime_2}`...")]
981    ExpectedOtherTwo {
982        leading_ellipsis: bool,
983        ty_or_sig: TyOrSig<'tcx>,
984        trait_path: Highlighted<'tcx, TraitRefPrintOnlyTraitPath<'tcx>>,
985        lifetime_1: usize,
986        lifetime_2: usize,
987    },
988    #[note(
989        "{$leading_ellipsis ->
990            [true] ...
991            *[false] {\"\"}
992        }`{$ty_or_sig}` must implement `{$trait_path}`, for any lifetime `'{$lifetime_1}`..."
993    )]
994    ExpectedOtherAny {
995        leading_ellipsis: bool,
996        ty_or_sig: TyOrSig<'tcx>,
997        trait_path: Highlighted<'tcx, TraitRefPrintOnlyTraitPath<'tcx>>,
998        lifetime_1: usize,
999    },
1000    #[note(
1001        "{$leading_ellipsis ->
1002            [true] ...
1003            *[false] {\"\"}
1004        }`{$ty_or_sig}` must implement `{$trait_path}`, for some specific lifetime `'{$lifetime_1}`..."
1005    )]
1006    ExpectedOtherSome {
1007        leading_ellipsis: bool,
1008        ty_or_sig: TyOrSig<'tcx>,
1009        trait_path: Highlighted<'tcx, TraitRefPrintOnlyTraitPath<'tcx>>,
1010        lifetime_1: usize,
1011    },
1012    #[note(
1013        "{$leading_ellipsis ->
1014            [true] ...
1015            *[false] {\"\"}
1016        }`{$ty_or_sig}` must implement `{$trait_path}`"
1017    )]
1018    ExpectedOtherNothing {
1019        leading_ellipsis: bool,
1020        ty_or_sig: TyOrSig<'tcx>,
1021        trait_path: Highlighted<'tcx, TraitRefPrintOnlyTraitPath<'tcx>>,
1022    },
1023    #[note(
1024        "...but it actually implements `{$trait_path}`{$has_lifetime ->
1025            [true] , for some specific lifetime `'{$lifetime}`
1026            *[false] {\"\"}
1027        }"
1028    )]
1029    ButActuallyImplementsTrait {
1030        trait_path: Highlighted<'tcx, TraitRefPrintOnlyTraitPath<'tcx>>,
1031        has_lifetime: bool,
1032        lifetime: usize,
1033    },
1034    #[note(
1035        "...but `{$trait_path}` is actually implemented for the type `{$ty}`{$has_lifetime ->
1036            [true] , for some specific lifetime `'{$lifetime}`
1037            *[false] {\"\"}
1038        }"
1039    )]
1040    ButActuallyImplementedForTy {
1041        trait_path: Highlighted<'tcx, TraitRefPrintOnlyTraitPath<'tcx>>,
1042        has_lifetime: bool,
1043        lifetime: usize,
1044        ty: String,
1045    },
1046    #[note(
1047        "...but `{$ty}` actually implements `{$trait_path}`{$has_lifetime ->
1048            [true] , for some specific lifetime `'{$lifetime}`
1049            *[false] {\"\"}
1050        }"
1051    )]
1052    ButActuallyTyImplements {
1053        trait_path: Highlighted<'tcx, TraitRefPrintOnlyTraitPath<'tcx>>,
1054        has_lifetime: bool,
1055        lifetime: usize,
1056        ty: String,
1057    },
1058}
1059
1060pub enum ActualImplExpectedKind {
1061    Signature,
1062    Passive,
1063    Other,
1064}
1065
1066pub enum ActualImplExpectedLifetimeKind {
1067    Two,
1068    Any,
1069    Some,
1070    Nothing,
1071}
1072
1073impl<'tcx> ActualImplExplNotes<'tcx> {
1074    pub fn new_expected(
1075        kind: ActualImplExpectedKind,
1076        lt_kind: ActualImplExpectedLifetimeKind,
1077        leading_ellipsis: bool,
1078        ty_or_sig: TyOrSig<'tcx>,
1079        trait_path: Highlighted<'tcx, TraitRefPrintOnlyTraitPath<'tcx>>,
1080        lifetime_1: usize,
1081        lifetime_2: usize,
1082    ) -> Self {
1083        match (kind, lt_kind) {
1084            (ActualImplExpectedKind::Signature, ActualImplExpectedLifetimeKind::Two) => {
1085                Self::ExpectedSignatureTwo {
1086                    leading_ellipsis,
1087                    ty_or_sig,
1088                    trait_path,
1089                    lifetime_1,
1090                    lifetime_2,
1091                }
1092            }
1093            (ActualImplExpectedKind::Signature, ActualImplExpectedLifetimeKind::Any) => {
1094                Self::ExpectedSignatureAny { leading_ellipsis, ty_or_sig, trait_path, lifetime_1 }
1095            }
1096            (ActualImplExpectedKind::Signature, ActualImplExpectedLifetimeKind::Some) => {
1097                Self::ExpectedSignatureSome { leading_ellipsis, ty_or_sig, trait_path, lifetime_1 }
1098            }
1099            (ActualImplExpectedKind::Signature, ActualImplExpectedLifetimeKind::Nothing) => {
1100                Self::ExpectedSignatureNothing { leading_ellipsis, ty_or_sig, trait_path }
1101            }
1102            (ActualImplExpectedKind::Passive, ActualImplExpectedLifetimeKind::Two) => {
1103                Self::ExpectedPassiveTwo {
1104                    leading_ellipsis,
1105                    ty_or_sig,
1106                    trait_path,
1107                    lifetime_1,
1108                    lifetime_2,
1109                }
1110            }
1111            (ActualImplExpectedKind::Passive, ActualImplExpectedLifetimeKind::Any) => {
1112                Self::ExpectedPassiveAny { leading_ellipsis, ty_or_sig, trait_path, lifetime_1 }
1113            }
1114            (ActualImplExpectedKind::Passive, ActualImplExpectedLifetimeKind::Some) => {
1115                Self::ExpectedPassiveSome { leading_ellipsis, ty_or_sig, trait_path, lifetime_1 }
1116            }
1117            (ActualImplExpectedKind::Passive, ActualImplExpectedLifetimeKind::Nothing) => {
1118                Self::ExpectedPassiveNothing { leading_ellipsis, ty_or_sig, trait_path }
1119            }
1120            (ActualImplExpectedKind::Other, ActualImplExpectedLifetimeKind::Two) => {
1121                Self::ExpectedOtherTwo {
1122                    leading_ellipsis,
1123                    ty_or_sig,
1124                    trait_path,
1125                    lifetime_1,
1126                    lifetime_2,
1127                }
1128            }
1129            (ActualImplExpectedKind::Other, ActualImplExpectedLifetimeKind::Any) => {
1130                Self::ExpectedOtherAny { leading_ellipsis, ty_or_sig, trait_path, lifetime_1 }
1131            }
1132            (ActualImplExpectedKind::Other, ActualImplExpectedLifetimeKind::Some) => {
1133                Self::ExpectedOtherSome { leading_ellipsis, ty_or_sig, trait_path, lifetime_1 }
1134            }
1135            (ActualImplExpectedKind::Other, ActualImplExpectedLifetimeKind::Nothing) => {
1136                Self::ExpectedOtherNothing { leading_ellipsis, ty_or_sig, trait_path }
1137            }
1138        }
1139    }
1140}
1141
1142#[derive(const _: () =
    {
        impl<'_sess, 'tcx, G> rustc_errors::Diagnostic<'_sess, G> for
            TraitPlaceholderMismatch<'tcx> where
            G: rustc_errors::EmissionGuarantee {
            #[track_caller]
            fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
                level: rustc_errors::Level) -> rustc_errors::Diag<'_sess, G> {
                match self {
                    TraitPlaceholderMismatch {
                        span: __binding_0,
                        satisfy_span: __binding_1,
                        where_span: __binding_2,
                        dup_span: __binding_3,
                        def_id: __binding_4,
                        trait_def_id: __binding_5,
                        actual_impl_expl_notes: __binding_6 } => {
                        let mut diag =
                            rustc_errors::Diag::new(dcx, level,
                                rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("implementation of `{$trait_def_id}` is not general enough")));
                        ;
                        diag.arg("def_id", __binding_4);
                        diag.arg("trait_def_id", __binding_5);
                        diag.span(__binding_0);
                        if let Some(__binding_1) = __binding_1 {
                            diag.span_label(__binding_1,
                                rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("doesn't satisfy where-clause")));
                        }
                        if let Some(__binding_2) = __binding_2 {
                            diag.span_label(__binding_2,
                                rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("due to a where-clause on `{$def_id}`...")));
                        }
                        if let Some(__binding_3) = __binding_3 {
                            diag.span_label(__binding_3,
                                rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("implementation of `{$trait_def_id}` is not general enough")));
                        }
                        for __binding_6 in __binding_6 {
                            diag.subdiagnostic(__binding_6);
                        }
                        diag
                    }
                }
            }
        }
    };Diagnostic)]
1143#[diag("implementation of `{$trait_def_id}` is not general enough")]
1144pub struct TraitPlaceholderMismatch<'tcx> {
1145    #[primary_span]
1146    pub span: Span,
1147    #[label("doesn't satisfy where-clause")]
1148    pub satisfy_span: Option<Span>,
1149    #[label("due to a where-clause on `{$def_id}`...")]
1150    pub where_span: Option<Span>,
1151    #[label("implementation of `{$trait_def_id}` is not general enough")]
1152    pub dup_span: Option<Span>,
1153    pub def_id: String,
1154    pub trait_def_id: String,
1155
1156    #[subdiagnostic]
1157    pub actual_impl_expl_notes: Vec<ActualImplExplNotes<'tcx>>,
1158}
1159
1160pub struct ConsiderBorrowingParamHelp {
1161    pub spans: Vec<Span>,
1162}
1163
1164impl Subdiagnostic for ConsiderBorrowingParamHelp {
1165    fn add_to_diag<G: EmissionGuarantee>(self, diag: &mut Diag<'_, G>) {
1166        let mut type_param_span: MultiSpan = self.spans.clone().into();
1167        for &span in &self.spans {
1168            // Seems like we can't call f() here as Into<DiagMessage> is required
1169            type_param_span
1170                .push_span_label(span, rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("consider borrowing this type parameter in the trait"))msg!("consider borrowing this type parameter in the trait"));
1171        }
1172        let msg = rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("the lifetime requirements from the `impl` do not correspond to the requirements in the `trait`"))msg!(
1173            "the lifetime requirements from the `impl` do not correspond to the requirements in the `trait`"
1174        );
1175        diag.span_help(type_param_span, msg);
1176    }
1177}
1178
1179#[derive(const _: () =
    {
        impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for TraitImplDiff
            where G: rustc_errors::EmissionGuarantee {
            #[track_caller]
            fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
                level: rustc_errors::Level) -> rustc_errors::Diag<'_sess, G> {
                match self {
                    TraitImplDiff {
                        sp: __binding_0,
                        trait_sp: __binding_1,
                        note: __binding_2,
                        param_help: __binding_3,
                        rel_help: __binding_4,
                        expected: __binding_5,
                        found: __binding_6 } => {
                        let mut diag =
                            rustc_errors::Diag::new(dcx, level,
                                rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("`impl` item signature doesn't match `trait` item signature")));
                        ;
                        diag.arg("expected", __binding_5);
                        diag.arg("found", __binding_6);
                        diag.span(__binding_0);
                        diag.span_label(__binding_0,
                            rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("found `{$found}`")));
                        diag.span_label(__binding_1,
                            rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("expected `{$expected}`")));
                        diag.note(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("expected signature `{$expected}`\n        {\"   \"}found signature `{$found}`")));
                        diag.subdiagnostic(__binding_3);
                        if __binding_4 {
                            diag.help(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("verify the lifetime relationships in the `trait` and `impl` between the `self` argument, the other inputs and its output")));
                        }
                        diag
                    }
                }
            }
        }
    };Diagnostic)]
1180#[diag("`impl` item signature doesn't match `trait` item signature")]
1181pub struct TraitImplDiff {
1182    #[primary_span]
1183    #[label("found `{$found}`")]
1184    pub sp: Span,
1185    #[label("expected `{$expected}`")]
1186    pub trait_sp: Span,
1187    #[note(
1188        "expected signature `{$expected}`
1189        {\"   \"}found signature `{$found}`"
1190    )]
1191    pub note: (),
1192    #[subdiagnostic]
1193    pub param_help: ConsiderBorrowingParamHelp,
1194    #[help(
1195        "verify the lifetime relationships in the `trait` and `impl` between the `self` argument, the other inputs and its output"
1196    )]
1197    pub rel_help: bool,
1198    pub expected: String,
1199    pub found: String,
1200}
1201
1202pub struct DynTraitConstraintSuggestion {
1203    pub span: Span,
1204    pub ident: Ident,
1205}
1206
1207impl Subdiagnostic for DynTraitConstraintSuggestion {
1208    fn add_to_diag<G: EmissionGuarantee>(self, diag: &mut Diag<'_, G>) {
1209        let mut multi_span: MultiSpan = ::alloc::boxed::box_assume_init_into_vec_unsafe(::alloc::intrinsics::write_box_via_move(::alloc::boxed::Box::new_uninit(),
        [self.span]))vec![self.span].into();
1210        multi_span.push_span_label(
1211            self.span,
1212            rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("this has an implicit `'static` lifetime requirement"))msg!("this has an implicit `'static` lifetime requirement"),
1213        );
1214        multi_span.push_span_label(
1215            self.ident.span,
1216            rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("calling this method introduces the `impl`'s `'static` requirement"))msg!("calling this method introduces the `impl`'s `'static` requirement"),
1217        );
1218        let msg = rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("the used `impl` has a `'static` requirement"))msg!("the used `impl` has a `'static` requirement");
1219        diag.span_note(multi_span, msg);
1220        let msg = rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("consider relaxing the implicit `'static` requirement"))msg!("consider relaxing the implicit `'static` requirement");
1221        diag.span_suggestion_verbose(
1222            self.span.shrink_to_hi(),
1223            msg,
1224            " + '_",
1225            Applicability::MaybeIncorrect,
1226        );
1227    }
1228}
1229
1230pub struct ReqIntroducedLocations {
1231    pub span: MultiSpan,
1232    pub spans: Vec<Span>,
1233    pub fn_decl_span: Span,
1234    pub cause_span: Span,
1235    pub add_label: bool,
1236}
1237
1238impl Subdiagnostic for ReqIntroducedLocations {
1239    fn add_to_diag<G: EmissionGuarantee>(mut self, diag: &mut Diag<'_, G>) {
1240        for sp in self.spans {
1241            self.span.push_span_label(sp, rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("`'static` requirement introduced here"))msg!("`'static` requirement introduced here"));
1242        }
1243
1244        if self.add_label {
1245            self.span.push_span_label(
1246                self.fn_decl_span,
1247                rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("requirement introduced by this return type"))msg!("requirement introduced by this return type"),
1248            );
1249        }
1250        self.span.push_span_label(self.cause_span, rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("because of this returned expression"))msg!("because of this returned expression"));
1251        let msg = rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("\"`'static` lifetime requirement introduced by the return type"))msg!("\"`'static` lifetime requirement introduced by the return type");
1252        diag.span_note(self.span, msg);
1253    }
1254}
1255
1256#[derive(const _: () =
    {
        impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for
            ButNeedsToSatisfy where G: rustc_errors::EmissionGuarantee {
            #[track_caller]
            fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
                level: rustc_errors::Level) -> rustc_errors::Diag<'_sess, G> {
                match self {
                    ButNeedsToSatisfy {
                        sp: __binding_0,
                        influencer_point: __binding_1,
                        spans: __binding_2,
                        require_span_as_label: __binding_3,
                        require_span_as_note: __binding_4,
                        bound: __binding_5,
                        has_param_name: __binding_6,
                        param_name: __binding_7,
                        spans_empty: __binding_8,
                        has_lifetime: __binding_9,
                        lifetime: __binding_10 } => {
                        let mut diag =
                            rustc_errors::Diag::new(dcx, level,
                                rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("{$has_param_name ->\n    [true] `{$param_name}`\n    *[false] `fn` parameter\n} has {$has_lifetime ->\n    [true] lifetime `{$lifetime}`\n    *[false] an anonymous lifetime `'_`\n} but it needs to satisfy a `'static` lifetime requirement")));
                        diag.code(E0759);
                        ;
                        diag.arg("has_param_name", __binding_6);
                        diag.arg("param_name", __binding_7);
                        diag.arg("spans_empty", __binding_8);
                        diag.arg("has_lifetime", __binding_9);
                        diag.arg("lifetime", __binding_10);
                        diag.span(__binding_0);
                        diag.span_label(__binding_1,
                            rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("this data with {$has_lifetime ->\n        [true] lifetime `{$lifetime}`\n        *[false] an anonymous lifetime `'_`\n    }...")));
                        for __binding_2 in __binding_2 {
                            diag.span_label(__binding_2,
                                rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("...is used here...")));
                        }
                        if let Some(__binding_3) = __binding_3 {
                            diag.span_label(__binding_3,
                                rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("{$spans_empty ->\n        *[true] ...is used and required to live as long as `'static` here\n        [false] ...and is required to live as long as `'static` here\n    }")));
                        }
                        if let Some(__binding_4) = __binding_4 {
                            diag.span_note(__binding_4,
                                rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("{$spans_empty ->\n        *[true] ...is used and required to live as long as `'static` here\n        [false] ...and is required to live as long as `'static` here\n    }")));
                        }
                        if let Some(__binding_5) = __binding_5 {
                            diag.span_note(__binding_5,
                                rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("`'static` lifetime requirement introduced by this bound")));
                        }
                        diag
                    }
                }
            }
        }
    };Diagnostic)]
1257#[diag("{$has_param_name ->
1258    [true] `{$param_name}`
1259    *[false] `fn` parameter
1260} has {$has_lifetime ->
1261    [true] lifetime `{$lifetime}`
1262    *[false] an anonymous lifetime `'_`
1263} but it needs to satisfy a `'static` lifetime requirement", code = E0759)]
1264pub struct ButNeedsToSatisfy {
1265    #[primary_span]
1266    pub sp: Span,
1267    #[label(
1268        "this data with {$has_lifetime ->
1269        [true] lifetime `{$lifetime}`
1270        *[false] an anonymous lifetime `'_`
1271    }..."
1272    )]
1273    pub influencer_point: Span,
1274    #[label("...is used here...")]
1275    pub spans: Vec<Span>,
1276    #[label(
1277        "{$spans_empty ->
1278        *[true] ...is used and required to live as long as `'static` here
1279        [false] ...and is required to live as long as `'static` here
1280    }"
1281    )]
1282    pub require_span_as_label: Option<Span>,
1283    #[note(
1284        "{$spans_empty ->
1285        *[true] ...is used and required to live as long as `'static` here
1286        [false] ...and is required to live as long as `'static` here
1287    }"
1288    )]
1289    pub require_span_as_note: Option<Span>,
1290    #[note("`'static` lifetime requirement introduced by this bound")]
1291    pub bound: Option<Span>,
1292
1293    pub has_param_name: bool,
1294    pub param_name: String,
1295    pub spans_empty: bool,
1296    pub has_lifetime: bool,
1297    pub lifetime: String,
1298}
1299
1300#[derive(const _: () =
    {
        impl<'_sess, 'a, G> rustc_errors::Diagnostic<'_sess, G> for
            OutlivesContent<'a> where G: rustc_errors::EmissionGuarantee {
            #[track_caller]
            fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
                level: rustc_errors::Level) -> rustc_errors::Diag<'_sess, G> {
                match self {
                    OutlivesContent { span: __binding_0, notes: __binding_1 } =>
                        {
                        let mut diag =
                            rustc_errors::Diag::new(dcx, level,
                                rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("lifetime of reference outlives lifetime of borrowed content...")));
                        diag.code(E0312);
                        ;
                        diag.span(__binding_0);
                        for __binding_1 in __binding_1 {
                            diag.subdiagnostic(__binding_1);
                        }
                        diag
                    }
                }
            }
        }
    };Diagnostic)]
1301#[diag("lifetime of reference outlives lifetime of borrowed content...", code = E0312)]
1302pub struct OutlivesContent<'a> {
1303    #[primary_span]
1304    pub span: Span,
1305    #[subdiagnostic]
1306    pub notes: Vec<note_and_explain::RegionExplanation<'a>>,
1307}
1308
1309#[derive(const _: () =
    {
        impl<'_sess, 'a, G> rustc_errors::Diagnostic<'_sess, G> for
            OutlivesBound<'a> where G: rustc_errors::EmissionGuarantee {
            #[track_caller]
            fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
                level: rustc_errors::Level) -> rustc_errors::Diag<'_sess, G> {
                match self {
                    OutlivesBound { span: __binding_0, notes: __binding_1 } => {
                        let mut diag =
                            rustc_errors::Diag::new(dcx, level,
                                rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("lifetime of the source pointer does not outlive lifetime bound of the object type")));
                        diag.code(E0476);
                        ;
                        diag.span(__binding_0);
                        for __binding_1 in __binding_1 {
                            diag.subdiagnostic(__binding_1);
                        }
                        diag
                    }
                }
            }
        }
    };Diagnostic)]
1310#[diag("lifetime of the source pointer does not outlive lifetime bound of the object type", code = E0476)]
1311pub struct OutlivesBound<'a> {
1312    #[primary_span]
1313    pub span: Span,
1314    #[subdiagnostic]
1315    pub notes: Vec<note_and_explain::RegionExplanation<'a>>,
1316}
1317
1318#[derive(const _: () =
    {
        impl<'_sess, 'a, G> rustc_errors::Diagnostic<'_sess, G> for
            FulfillReqLifetime<'a> where G: rustc_errors::EmissionGuarantee {
            #[track_caller]
            fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
                level: rustc_errors::Level) -> rustc_errors::Diag<'_sess, G> {
                match self {
                    FulfillReqLifetime {
                        span: __binding_0, ty: __binding_1, note: __binding_2 } => {
                        let mut diag =
                            rustc_errors::Diag::new(dcx, level,
                                rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("the type `{$ty}` does not fulfill the required lifetime")));
                        diag.code(E0477);
                        ;
                        diag.arg("ty", __binding_1);
                        diag.span(__binding_0);
                        if let Some(__binding_2) = __binding_2 {
                            diag.subdiagnostic(__binding_2);
                        }
                        diag
                    }
                }
            }
        }
    };Diagnostic)]
1319#[diag("the type `{$ty}` does not fulfill the required lifetime", code = E0477)]
1320pub struct FulfillReqLifetime<'a> {
1321    #[primary_span]
1322    pub span: Span,
1323    pub ty: Ty<'a>,
1324    #[subdiagnostic]
1325    pub note: Option<note_and_explain::RegionExplanation<'a>>,
1326}
1327
1328#[derive(const _: () =
    {
        impl<'_sess, 'a, G> rustc_errors::Diagnostic<'_sess, G> for
            LfBoundNotSatisfied<'a> where G: rustc_errors::EmissionGuarantee {
            #[track_caller]
            fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
                level: rustc_errors::Level) -> rustc_errors::Diag<'_sess, G> {
                match self {
                    LfBoundNotSatisfied { span: __binding_0, notes: __binding_1
                        } => {
                        let mut diag =
                            rustc_errors::Diag::new(dcx, level,
                                rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("lifetime bound not satisfied")));
                        diag.code(E0478);
                        ;
                        diag.span(__binding_0);
                        for __binding_1 in __binding_1 {
                            diag.subdiagnostic(__binding_1);
                        }
                        diag
                    }
                }
            }
        }
    };Diagnostic)]
1329#[diag("lifetime bound not satisfied", code = E0478)]
1330pub struct LfBoundNotSatisfied<'a> {
1331    #[primary_span]
1332    pub span: Span,
1333    #[subdiagnostic]
1334    pub notes: Vec<note_and_explain::RegionExplanation<'a>>,
1335}
1336
1337#[derive(const _: () =
    {
        impl<'_sess, 'a, G> rustc_errors::Diagnostic<'_sess, G> for
            RefLongerThanData<'a> where G: rustc_errors::EmissionGuarantee {
            #[track_caller]
            fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
                level: rustc_errors::Level) -> rustc_errors::Diag<'_sess, G> {
                match self {
                    RefLongerThanData {
                        span: __binding_0, ty: __binding_1, notes: __binding_2 } =>
                        {
                        let mut diag =
                            rustc_errors::Diag::new(dcx, level,
                                rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("in type `{$ty}`, reference has a longer lifetime than the data it references")));
                        diag.code(E0491);
                        ;
                        diag.arg("ty", __binding_1);
                        diag.span(__binding_0);
                        for __binding_2 in __binding_2 {
                            diag.subdiagnostic(__binding_2);
                        }
                        diag
                    }
                }
            }
        }
    };Diagnostic)]
1338#[diag("in type `{$ty}`, reference has a longer lifetime than the data it references", code = E0491)]
1339pub struct RefLongerThanData<'a> {
1340    #[primary_span]
1341    pub span: Span,
1342    pub ty: Ty<'a>,
1343    #[subdiagnostic]
1344    pub notes: Vec<note_and_explain::RegionExplanation<'a>>,
1345}
1346
1347#[derive(const _: () =
    {
        impl rustc_errors::Subdiagnostic for WhereClauseSuggestions {
            fn add_to_diag<__G>(self, diag: &mut rustc_errors::Diag<'_, __G>)
                where __G: rustc_errors::EmissionGuarantee {
                match self {
                    WhereClauseSuggestions::Remove { span: __binding_0 } => {
                        let __code_9 =
                            [::alloc::__export::must_use({
                                                ::alloc::fmt::format(format_args!(""))
                                            })].into_iter();
                        let mut sub_args = rustc_errors::DiagArgMap::default();
                        let __message =
                            rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("remove the `where` clause")),
                                &sub_args);
                        diag.span_suggestions_with_style(__binding_0, __message,
                            __code_9, rustc_errors::Applicability::MachineApplicable,
                            rustc_errors::SuggestionStyle::ShowAlways);
                    }
                    WhereClauseSuggestions::CopyPredicates {
                        span: __binding_0,
                        space: __binding_1,
                        trait_predicates: __binding_2 } => {
                        let __code_10 =
                            [::alloc::__export::must_use({
                                                ::alloc::fmt::format(format_args!("{0}where {1}",
                                                        __binding_1, __binding_2))
                                            })].into_iter();
                        let mut sub_args = rustc_errors::DiagArgMap::default();
                        sub_args.insert("space".into(),
                            rustc_errors::IntoDiagArg::into_diag_arg(__binding_1,
                                &mut diag.long_ty_path));
                        sub_args.insert("trait_predicates".into(),
                            rustc_errors::IntoDiagArg::into_diag_arg(__binding_2,
                                &mut diag.long_ty_path));
                        let __message =
                            rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("copy the `where` clause predicates from the trait")),
                                &sub_args);
                        diag.span_suggestions_with_style(__binding_0, __message,
                            __code_10, rustc_errors::Applicability::MachineApplicable,
                            rustc_errors::SuggestionStyle::ShowAlways);
                    }
                }
            }
        }
    };Subdiagnostic)]
1348pub enum WhereClauseSuggestions {
1349    #[suggestion(
1350        "remove the `where` clause",
1351        code = "",
1352        applicability = "machine-applicable",
1353        style = "verbose"
1354    )]
1355    Remove {
1356        #[primary_span]
1357        span: Span,
1358    },
1359    #[suggestion(
1360        "copy the `where` clause predicates from the trait",
1361        code = "{space}where {trait_predicates}",
1362        applicability = "machine-applicable",
1363        style = "verbose"
1364    )]
1365    CopyPredicates {
1366        #[primary_span]
1367        span: Span,
1368        space: &'static str,
1369        trait_predicates: String,
1370    },
1371}
1372
1373#[derive(const _: () =
    {
        impl rustc_errors::Subdiagnostic for SuggestRemoveSemiOrReturnBinding
            {
            fn add_to_diag<__G>(self, diag: &mut rustc_errors::Diag<'_, __G>)
                where __G: rustc_errors::EmissionGuarantee {
                match self {
                    SuggestRemoveSemiOrReturnBinding::RemoveAndBox {
                        first_lo: __binding_0,
                        first_hi: __binding_1,
                        second_lo: __binding_2,
                        second_hi: __binding_3,
                        sp: __binding_4 } => {
                        let mut suggestions = Vec::new();
                        let __code_11 =
                            ::alloc::__export::must_use({
                                    ::alloc::fmt::format(format_args!("Box::new("))
                                });
                        let __code_12 =
                            ::alloc::__export::must_use({
                                    ::alloc::fmt::format(format_args!(")"))
                                });
                        let __code_13 =
                            ::alloc::__export::must_use({
                                    ::alloc::fmt::format(format_args!("Box::new("))
                                });
                        let __code_14 =
                            ::alloc::__export::must_use({
                                    ::alloc::fmt::format(format_args!(")"))
                                });
                        let __code_15 =
                            ::alloc::__export::must_use({
                                    ::alloc::fmt::format(format_args!(""))
                                });
                        suggestions.push((__binding_0, __code_11));
                        suggestions.push((__binding_1, __code_12));
                        suggestions.push((__binding_2, __code_13));
                        suggestions.push((__binding_3, __code_14));
                        suggestions.push((__binding_4, __code_15));
                        let mut sub_args = rustc_errors::DiagArgMap::default();
                        let __message =
                            rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("consider removing this semicolon and boxing the expressions")),
                                &sub_args);
                        diag.multipart_suggestion_with_style(__message, suggestions,
                            rustc_errors::Applicability::MachineApplicable,
                            rustc_errors::SuggestionStyle::ShowCode);
                    }
                    SuggestRemoveSemiOrReturnBinding::Remove { sp: __binding_0 }
                        => {
                        let __code_16 =
                            [::alloc::__export::must_use({
                                                ::alloc::fmt::format(format_args!(""))
                                            })].into_iter();
                        let mut sub_args = rustc_errors::DiagArgMap::default();
                        let __message =
                            rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("consider removing this semicolon")),
                                &sub_args);
                        diag.span_suggestions_with_style(__binding_0, __message,
                            __code_16, rustc_errors::Applicability::MachineApplicable,
                            rustc_errors::SuggestionStyle::HideCodeInline);
                    }
                    SuggestRemoveSemiOrReturnBinding::Add {
                        sp: __binding_0, code: __binding_1, ident: __binding_2 } =>
                        {
                        let __code_17 =
                            [::alloc::__export::must_use({
                                                ::alloc::fmt::format(format_args!("{0}", __binding_1))
                                            })].into_iter();
                        let mut sub_args = rustc_errors::DiagArgMap::default();
                        sub_args.insert("code".into(),
                            rustc_errors::IntoDiagArg::into_diag_arg(__binding_1,
                                &mut diag.long_ty_path));
                        sub_args.insert("ident".into(),
                            rustc_errors::IntoDiagArg::into_diag_arg(__binding_2,
                                &mut diag.long_ty_path));
                        let __message =
                            rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("consider returning the local binding `{$ident}`")),
                                &sub_args);
                        diag.span_suggestions_with_style(__binding_0, __message,
                            __code_17, rustc_errors::Applicability::MaybeIncorrect,
                            rustc_errors::SuggestionStyle::ShowAlways);
                    }
                    SuggestRemoveSemiOrReturnBinding::AddOne {
                        spans: __binding_0 } => {
                        let mut sub_args = rustc_errors::DiagArgMap::default();
                        let __message =
                            rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("consider returning one of these bindings")),
                                &sub_args);
                        diag.span_note(__binding_0, __message);
                    }
                }
            }
        }
    };Subdiagnostic)]
1374pub enum SuggestRemoveSemiOrReturnBinding {
1375    #[multipart_suggestion(
1376        "consider removing this semicolon and boxing the expressions",
1377        applicability = "machine-applicable"
1378    )]
1379    RemoveAndBox {
1380        #[suggestion_part(code = "Box::new(")]
1381        first_lo: Span,
1382        #[suggestion_part(code = ")")]
1383        first_hi: Span,
1384        #[suggestion_part(code = "Box::new(")]
1385        second_lo: Span,
1386        #[suggestion_part(code = ")")]
1387        second_hi: Span,
1388        #[suggestion_part(code = "")]
1389        sp: Span,
1390    },
1391    #[suggestion(
1392        "consider removing this semicolon",
1393        style = "short",
1394        code = "",
1395        applicability = "machine-applicable"
1396    )]
1397    Remove {
1398        #[primary_span]
1399        sp: Span,
1400    },
1401    #[suggestion(
1402        "consider returning the local binding `{$ident}`",
1403        style = "verbose",
1404        code = "{code}",
1405        applicability = "maybe-incorrect"
1406    )]
1407    Add {
1408        #[primary_span]
1409        sp: Span,
1410        code: String,
1411        ident: Ident,
1412    },
1413    #[note("consider returning one of these bindings")]
1414    AddOne {
1415        #[primary_span]
1416        spans: MultiSpan,
1417    },
1418}
1419
1420#[derive(const _: () =
    {
        impl rustc_errors::Subdiagnostic for ConsiderAddingAwait {
            fn add_to_diag<__G>(self, diag: &mut rustc_errors::Diag<'_, __G>)
                where __G: rustc_errors::EmissionGuarantee {
                match self {
                    ConsiderAddingAwait::BothFuturesHelp => {
                        let mut sub_args = rustc_errors::DiagArgMap::default();
                        let __message =
                            rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("consider `await`ing on both `Future`s")),
                                &sub_args);
                        diag.help(__message);
                    }
                    ConsiderAddingAwait::BothFuturesSugg {
                        first: __binding_0, second: __binding_1 } => {
                        let mut suggestions = Vec::new();
                        let __code_18 =
                            ::alloc::__export::must_use({
                                    ::alloc::fmt::format(format_args!(".await"))
                                });
                        let __code_19 =
                            ::alloc::__export::must_use({
                                    ::alloc::fmt::format(format_args!(".await"))
                                });
                        suggestions.push((__binding_0, __code_18));
                        suggestions.push((__binding_1, __code_19));
                        let mut sub_args = rustc_errors::DiagArgMap::default();
                        let __message =
                            rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("consider `await`ing on both `Future`s")),
                                &sub_args);
                        diag.multipart_suggestion_with_style(__message, suggestions,
                            rustc_errors::Applicability::MaybeIncorrect,
                            rustc_errors::SuggestionStyle::ShowCode);
                    }
                    ConsiderAddingAwait::FutureSugg { span: __binding_0 } => {
                        let __code_20 =
                            [::alloc::__export::must_use({
                                                ::alloc::fmt::format(format_args!(".await"))
                                            })].into_iter();
                        let mut sub_args = rustc_errors::DiagArgMap::default();
                        let __message =
                            rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("consider `await`ing on the `Future`")),
                                &sub_args);
                        diag.span_suggestions_with_style(__binding_0, __message,
                            __code_20, rustc_errors::Applicability::MaybeIncorrect,
                            rustc_errors::SuggestionStyle::ShowAlways);
                    }
                    ConsiderAddingAwait::FutureSuggNote { span: __binding_0 } =>
                        {
                        let mut sub_args = rustc_errors::DiagArgMap::default();
                        let __message =
                            rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("calling an async function returns a future")),
                                &sub_args);
                        diag.span_note(__binding_0, __message);
                    }
                    ConsiderAddingAwait::FutureSuggMultiple { spans: __binding_0
                        } => {
                        let mut suggestions = Vec::new();
                        let __code_21 =
                            ::alloc::__export::must_use({
                                    ::alloc::fmt::format(format_args!(".await"))
                                });
                        for __binding_0 in __binding_0 {
                            suggestions.push((__binding_0, __code_21.clone()));
                        }
                        let mut sub_args = rustc_errors::DiagArgMap::default();
                        let __message =
                            rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("consider `await`ing on the `Future`")),
                                &sub_args);
                        diag.multipart_suggestion_with_style(__message, suggestions,
                            rustc_errors::Applicability::MaybeIncorrect,
                            rustc_errors::SuggestionStyle::ShowAlways);
                    }
                }
            }
        }
    };Subdiagnostic)]
1421pub enum ConsiderAddingAwait {
1422    #[help("consider `await`ing on both `Future`s")]
1423    BothFuturesHelp,
1424    #[multipart_suggestion(
1425        "consider `await`ing on both `Future`s",
1426        applicability = "maybe-incorrect"
1427    )]
1428    BothFuturesSugg {
1429        #[suggestion_part(code = ".await")]
1430        first: Span,
1431        #[suggestion_part(code = ".await")]
1432        second: Span,
1433    },
1434    #[suggestion(
1435        "consider `await`ing on the `Future`",
1436        code = ".await",
1437        style = "verbose",
1438        applicability = "maybe-incorrect"
1439    )]
1440    FutureSugg {
1441        #[primary_span]
1442        span: Span,
1443    },
1444    #[note("calling an async function returns a future")]
1445    FutureSuggNote {
1446        #[primary_span]
1447        span: Span,
1448    },
1449    #[multipart_suggestion(
1450        "consider `await`ing on the `Future`",
1451        style = "verbose",
1452        applicability = "maybe-incorrect"
1453    )]
1454    FutureSuggMultiple {
1455        #[suggestion_part(code = ".await")]
1456        spans: Vec<Span>,
1457    },
1458}
1459
1460#[derive(const _: () =
    {
        impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for
            PlaceholderRelationLfNotSatisfied where
            G: rustc_errors::EmissionGuarantee {
            #[track_caller]
            fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
                level: rustc_errors::Level) -> rustc_errors::Diag<'_sess, G> {
                match self {
                    PlaceholderRelationLfNotSatisfied::HasBoth {
                        span: __binding_0,
                        sub_span: __binding_1,
                        sup_span: __binding_2,
                        sub_symbol: __binding_3,
                        sup_symbol: __binding_4,
                        note: __binding_5 } => {
                        let mut diag =
                            rustc_errors::Diag::new(dcx, level,
                                rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("lifetime bound not satisfied")));
                        ;
                        diag.arg("sub_symbol", __binding_3);
                        diag.arg("sup_symbol", __binding_4);
                        diag.span(__binding_0);
                        diag.span_note(__binding_1,
                            rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("the lifetime `{$sub_symbol}` defined here...")));
                        diag.span_note(__binding_2,
                            rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("...must outlive the lifetime `{$sup_symbol}` defined here")));
                        diag.note(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("this is a known limitation that will be removed in the future (see issue #100013 <https://github.com/rust-lang/rust/issues/100013> for more information)")));
                        diag
                    }
                    PlaceholderRelationLfNotSatisfied::HasSub {
                        span: __binding_0,
                        sub_span: __binding_1,
                        sup_span: __binding_2,
                        sub_symbol: __binding_3,
                        note: __binding_4 } => {
                        let mut diag =
                            rustc_errors::Diag::new(dcx, level,
                                rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("lifetime bound not satisfied")));
                        ;
                        diag.arg("sub_symbol", __binding_3);
                        diag.span(__binding_0);
                        diag.span_note(__binding_1,
                            rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("the lifetime `{$sub_symbol}` defined here...")));
                        diag.span_note(__binding_2,
                            rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("...must outlive the lifetime defined here")));
                        diag.note(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("this is a known limitation that will be removed in the future (see issue #100013 <https://github.com/rust-lang/rust/issues/100013> for more information)")));
                        diag
                    }
                    PlaceholderRelationLfNotSatisfied::HasSup {
                        span: __binding_0,
                        sub_span: __binding_1,
                        sup_span: __binding_2,
                        sup_symbol: __binding_3,
                        note: __binding_4 } => {
                        let mut diag =
                            rustc_errors::Diag::new(dcx, level,
                                rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("lifetime bound not satisfied")));
                        ;
                        diag.arg("sup_symbol", __binding_3);
                        diag.span(__binding_0);
                        diag.span_note(__binding_1,
                            rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("the lifetime defined here...")));
                        diag.span_note(__binding_2,
                            rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("...must outlive the lifetime `{$sup_symbol}` defined here")));
                        diag.note(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("this is a known limitation that will be removed in the future (see issue #100013 <https://github.com/rust-lang/rust/issues/100013> for more information)")));
                        diag
                    }
                    PlaceholderRelationLfNotSatisfied::HasNone {
                        span: __binding_0,
                        sub_span: __binding_1,
                        sup_span: __binding_2,
                        note: __binding_3 } => {
                        let mut diag =
                            rustc_errors::Diag::new(dcx, level,
                                rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("lifetime bound not satisfied")));
                        ;
                        diag.span(__binding_0);
                        diag.span_note(__binding_1,
                            rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("the lifetime defined here...")));
                        diag.span_note(__binding_2,
                            rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("...must outlive the lifetime defined here")));
                        diag.note(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("this is a known limitation that will be removed in the future (see issue #100013 <https://github.com/rust-lang/rust/issues/100013> for more information)")));
                        diag
                    }
                    PlaceholderRelationLfNotSatisfied::OnlyPrimarySpan {
                        span: __binding_0, note: __binding_1 } => {
                        let mut diag =
                            rustc_errors::Diag::new(dcx, level,
                                rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("lifetime bound not satisfied")));
                        ;
                        diag.span(__binding_0);
                        diag.note(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("this is a known limitation that will be removed in the future (see issue #100013 <https://github.com/rust-lang/rust/issues/100013> for more information)")));
                        diag
                    }
                }
            }
        }
    };Diagnostic)]
1461pub enum PlaceholderRelationLfNotSatisfied {
1462    #[diag("lifetime bound not satisfied")]
1463    HasBoth {
1464        #[primary_span]
1465        span: Span,
1466        #[note("the lifetime `{$sub_symbol}` defined here...")]
1467        sub_span: Span,
1468        #[note("...must outlive the lifetime `{$sup_symbol}` defined here")]
1469        sup_span: Span,
1470        sub_symbol: Symbol,
1471        sup_symbol: Symbol,
1472        #[note(
1473            "this is a known limitation that will be removed in the future (see issue #100013 <https://github.com/rust-lang/rust/issues/100013> for more information)"
1474        )]
1475        note: (),
1476    },
1477    #[diag("lifetime bound not satisfied")]
1478    HasSub {
1479        #[primary_span]
1480        span: Span,
1481        #[note("the lifetime `{$sub_symbol}` defined here...")]
1482        sub_span: Span,
1483        #[note("...must outlive the lifetime defined here")]
1484        sup_span: Span,
1485        sub_symbol: Symbol,
1486        #[note(
1487            "this is a known limitation that will be removed in the future (see issue #100013 <https://github.com/rust-lang/rust/issues/100013> for more information)"
1488        )]
1489        note: (),
1490    },
1491    #[diag("lifetime bound not satisfied")]
1492    HasSup {
1493        #[primary_span]
1494        span: Span,
1495        #[note("the lifetime defined here...")]
1496        sub_span: Span,
1497        #[note("...must outlive the lifetime `{$sup_symbol}` defined here")]
1498        sup_span: Span,
1499        sup_symbol: Symbol,
1500        #[note(
1501            "this is a known limitation that will be removed in the future (see issue #100013 <https://github.com/rust-lang/rust/issues/100013> for more information)"
1502        )]
1503        note: (),
1504    },
1505    #[diag("lifetime bound not satisfied")]
1506    HasNone {
1507        #[primary_span]
1508        span: Span,
1509        #[note("the lifetime defined here...")]
1510        sub_span: Span,
1511        #[note("...must outlive the lifetime defined here")]
1512        sup_span: Span,
1513        #[note(
1514            "this is a known limitation that will be removed in the future (see issue #100013 <https://github.com/rust-lang/rust/issues/100013> for more information)"
1515        )]
1516        note: (),
1517    },
1518    #[diag("lifetime bound not satisfied")]
1519    OnlyPrimarySpan {
1520        #[primary_span]
1521        span: Span,
1522        #[note(
1523            "this is a known limitation that will be removed in the future (see issue #100013 <https://github.com/rust-lang/rust/issues/100013> for more information)"
1524        )]
1525        note: (),
1526    },
1527}
1528
1529#[derive(const _: () =
    {
        impl<'_sess, 'tcx, G> rustc_errors::Diagnostic<'_sess, G> for
            OpaqueCapturesLifetime<'tcx> where
            G: rustc_errors::EmissionGuarantee {
            #[track_caller]
            fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
                level: rustc_errors::Level) -> rustc_errors::Diag<'_sess, G> {
                match self {
                    OpaqueCapturesLifetime {
                        span: __binding_0,
                        opaque_ty_span: __binding_1,
                        opaque_ty: __binding_2 } => {
                        let mut diag =
                            rustc_errors::Diag::new(dcx, level,
                                rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("hidden type for `{$opaque_ty}` captures lifetime that does not appear in bounds")));
                        diag.code(E0700);
                        ;
                        diag.arg("opaque_ty", __binding_2);
                        diag.span(__binding_0);
                        diag.span_label(__binding_1,
                            rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("opaque type defined here")));
                        diag
                    }
                }
            }
        }
    };Diagnostic)]
1530#[diag("hidden type for `{$opaque_ty}` captures lifetime that does not appear in bounds", code = E0700)]
1531pub struct OpaqueCapturesLifetime<'tcx> {
1532    #[primary_span]
1533    pub span: Span,
1534    #[label("opaque type defined here")]
1535    pub opaque_ty_span: Span,
1536    pub opaque_ty: Ty<'tcx>,
1537}
1538
1539#[derive(const _: () =
    {
        impl<'a> rustc_errors::Subdiagnostic for FunctionPointerSuggestion<'a>
            {
            fn add_to_diag<__G>(self, diag: &mut rustc_errors::Diag<'_, __G>)
                where __G: rustc_errors::EmissionGuarantee {
                match self {
                    FunctionPointerSuggestion::UseRef { span: __binding_0 } => {
                        let __code_22 =
                            [::alloc::__export::must_use({
                                                ::alloc::fmt::format(format_args!("&"))
                                            })].into_iter();
                        let mut sub_args = rustc_errors::DiagArgMap::default();
                        let __message =
                            rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("consider using a reference")),
                                &sub_args);
                        diag.span_suggestions_with_style(__binding_0, __message,
                            __code_22, rustc_errors::Applicability::MaybeIncorrect,
                            rustc_errors::SuggestionStyle::ShowAlways);
                    }
                    FunctionPointerSuggestion::RemoveRef {
                        span: __binding_0, fn_name: __binding_1 } => {
                        let __code_23 =
                            [::alloc::__export::must_use({
                                                ::alloc::fmt::format(format_args!("{0}", __binding_1))
                                            })].into_iter();
                        let mut sub_args = rustc_errors::DiagArgMap::default();
                        let __message =
                            rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("consider removing the reference")),
                                &sub_args);
                        diag.span_suggestions_with_style(__binding_0, __message,
                            __code_23, rustc_errors::Applicability::MaybeIncorrect,
                            rustc_errors::SuggestionStyle::ShowAlways);
                    }
                    FunctionPointerSuggestion::CastRef {
                        span: __binding_0, fn_name: __binding_1, sig: __binding_2 }
                        => {
                        let __code_24 =
                            [::alloc::__export::must_use({
                                                ::alloc::fmt::format(format_args!("&({0} as {1})",
                                                        __binding_1, __binding_2))
                                            })].into_iter();
                        let mut sub_args = rustc_errors::DiagArgMap::default();
                        let __message =
                            rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("consider casting to a fn pointer")),
                                &sub_args);
                        diag.span_suggestions_with_style(__binding_0, __message,
                            __code_24, rustc_errors::Applicability::MaybeIncorrect,
                            rustc_errors::SuggestionStyle::ShowAlways);
                    }
                    FunctionPointerSuggestion::Cast {
                        span: __binding_0, sig: __binding_1 } => {
                        let __code_25 =
                            [::alloc::__export::must_use({
                                                ::alloc::fmt::format(format_args!(" as {0}", __binding_1))
                                            })].into_iter();
                        let mut sub_args = rustc_errors::DiagArgMap::default();
                        let __message =
                            rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("consider casting to a fn pointer")),
                                &sub_args);
                        diag.span_suggestions_with_style(__binding_0, __message,
                            __code_25, rustc_errors::Applicability::MaybeIncorrect,
                            rustc_errors::SuggestionStyle::ShowAlways);
                    }
                    FunctionPointerSuggestion::CastBoth {
                        span: __binding_0,
                        found_sig: __binding_1,
                        expected_sig: __binding_2 } => {
                        let __code_26 =
                            [::alloc::__export::must_use({
                                                ::alloc::fmt::format(format_args!(" as {0}", __binding_1))
                                            })].into_iter();
                        let mut sub_args = rustc_errors::DiagArgMap::default();
                        sub_args.insert("expected_sig".into(),
                            rustc_errors::IntoDiagArg::into_diag_arg(__binding_2,
                                &mut diag.long_ty_path));
                        let __message =
                            rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("consider casting both fn items to fn pointers using `as {$expected_sig}`")),
                                &sub_args);
                        diag.span_suggestions_with_style(__binding_0, __message,
                            __code_26, rustc_errors::Applicability::MaybeIncorrect,
                            rustc_errors::SuggestionStyle::HideCodeAlways);
                    }
                    FunctionPointerSuggestion::CastBothRef {
                        span: __binding_0,
                        fn_name: __binding_1,
                        found_sig: __binding_2,
                        expected_sig: __binding_3 } => {
                        let __code_27 =
                            [::alloc::__export::must_use({
                                                ::alloc::fmt::format(format_args!("&({0} as {1})",
                                                        __binding_1, __binding_2))
                                            })].into_iter();
                        let mut sub_args = rustc_errors::DiagArgMap::default();
                        sub_args.insert("expected_sig".into(),
                            rustc_errors::IntoDiagArg::into_diag_arg(__binding_3,
                                &mut diag.long_ty_path));
                        let __message =
                            rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("consider casting both fn items to fn pointers using `as {$expected_sig}`")),
                                &sub_args);
                        diag.span_suggestions_with_style(__binding_0, __message,
                            __code_27, rustc_errors::Applicability::MaybeIncorrect,
                            rustc_errors::SuggestionStyle::HideCodeAlways);
                    }
                }
            }
        }
    };Subdiagnostic)]
1540pub enum FunctionPointerSuggestion<'a> {
1541    #[suggestion(
1542        "consider using a reference",
1543        code = "&",
1544        style = "verbose",
1545        applicability = "maybe-incorrect"
1546    )]
1547    UseRef {
1548        #[primary_span]
1549        span: Span,
1550    },
1551    #[suggestion(
1552        "consider removing the reference",
1553        code = "{fn_name}",
1554        style = "verbose",
1555        applicability = "maybe-incorrect"
1556    )]
1557    RemoveRef {
1558        #[primary_span]
1559        span: Span,
1560        #[skip_arg]
1561        fn_name: String,
1562    },
1563    #[suggestion(
1564        "consider casting to a fn pointer",
1565        code = "&({fn_name} as {sig})",
1566        style = "verbose",
1567        applicability = "maybe-incorrect"
1568    )]
1569    CastRef {
1570        #[primary_span]
1571        span: Span,
1572        #[skip_arg]
1573        fn_name: String,
1574        #[skip_arg]
1575        sig: Binder<'a, FnSig<'a>>,
1576    },
1577    #[suggestion(
1578        "consider casting to a fn pointer",
1579        code = " as {sig}",
1580        style = "verbose",
1581        applicability = "maybe-incorrect"
1582    )]
1583    Cast {
1584        #[primary_span]
1585        span: Span,
1586        #[skip_arg]
1587        sig: Binder<'a, FnSig<'a>>,
1588    },
1589    #[suggestion(
1590        "consider casting both fn items to fn pointers using `as {$expected_sig}`",
1591        code = " as {found_sig}",
1592        style = "hidden",
1593        applicability = "maybe-incorrect"
1594    )]
1595    CastBoth {
1596        #[primary_span]
1597        span: Span,
1598        #[skip_arg]
1599        found_sig: Binder<'a, FnSig<'a>>,
1600        expected_sig: Binder<'a, FnSig<'a>>,
1601    },
1602    #[suggestion(
1603        "consider casting both fn items to fn pointers using `as {$expected_sig}`",
1604        code = "&({fn_name} as {found_sig})",
1605        style = "hidden",
1606        applicability = "maybe-incorrect"
1607    )]
1608    CastBothRef {
1609        #[primary_span]
1610        span: Span,
1611        #[skip_arg]
1612        fn_name: String,
1613        #[skip_arg]
1614        found_sig: Binder<'a, FnSig<'a>>,
1615        expected_sig: Binder<'a, FnSig<'a>>,
1616    },
1617}
1618
1619#[derive(const _: () =
    {
        impl rustc_errors::Subdiagnostic for FnItemsAreDistinct {
            fn add_to_diag<__G>(self, diag: &mut rustc_errors::Diag<'_, __G>)
                where __G: rustc_errors::EmissionGuarantee {
                match self {
                    FnItemsAreDistinct => {
                        let mut sub_args = rustc_errors::DiagArgMap::default();
                        let __message =
                            rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("fn items are distinct from fn pointers")),
                                &sub_args);
                        diag.note(__message);
                    }
                }
            }
        }
    };Subdiagnostic)]
1620#[note("fn items are distinct from fn pointers")]
1621pub struct FnItemsAreDistinct;
1622
1623#[derive(const _: () =
    {
        impl rustc_errors::Subdiagnostic for FnUniqTypes {
            fn add_to_diag<__G>(self, diag: &mut rustc_errors::Diag<'_, __G>)
                where __G: rustc_errors::EmissionGuarantee {
                match self {
                    FnUniqTypes => {
                        let mut sub_args = rustc_errors::DiagArgMap::default();
                        let __message =
                            rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("different fn items have unique types, even if their signatures are the same")),
                                &sub_args);
                        diag.note(__message);
                    }
                }
            }
        }
    };Subdiagnostic)]
1624#[note("different fn items have unique types, even if their signatures are the same")]
1625pub struct FnUniqTypes;
1626
1627#[derive(const _: () =
    {
        impl rustc_errors::Subdiagnostic for FnConsiderCasting {
            fn add_to_diag<__G>(self, diag: &mut rustc_errors::Diag<'_, __G>)
                where __G: rustc_errors::EmissionGuarantee {
                match self {
                    FnConsiderCasting { casting: __binding_0 } => {
                        let mut sub_args = rustc_errors::DiagArgMap::default();
                        sub_args.insert("casting".into(),
                            rustc_errors::IntoDiagArg::into_diag_arg(__binding_0,
                                &mut diag.long_ty_path));
                        let __message =
                            rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("consider casting the fn item to a fn pointer: `{$casting}`")),
                                &sub_args);
                        diag.help(__message);
                    }
                }
            }
        }
    };Subdiagnostic)]
1628#[help("consider casting the fn item to a fn pointer: `{$casting}`")]
1629pub struct FnConsiderCasting {
1630    pub casting: String,
1631}
1632
1633#[derive(const _: () =
    {
        impl<'a> rustc_errors::Subdiagnostic for FnConsiderCastingBoth<'a> {
            fn add_to_diag<__G>(self, diag: &mut rustc_errors::Diag<'_, __G>)
                where __G: rustc_errors::EmissionGuarantee {
                match self {
                    FnConsiderCastingBoth { sig: __binding_0 } => {
                        let mut sub_args = rustc_errors::DiagArgMap::default();
                        sub_args.insert("sig".into(),
                            rustc_errors::IntoDiagArg::into_diag_arg(__binding_0,
                                &mut diag.long_ty_path));
                        let __message =
                            rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("consider casting both fn items to fn pointers using `as {$sig}`")),
                                &sub_args);
                        diag.help(__message);
                    }
                }
            }
        }
    };Subdiagnostic)]
1634#[help("consider casting both fn items to fn pointers using `as {$sig}`")]
1635pub struct FnConsiderCastingBoth<'a> {
1636    pub sig: Binder<'a, FnSig<'a>>,
1637}
1638
1639#[derive(const _: () =
    {
        impl<'a> rustc_errors::Subdiagnostic for SuggestAccessingField<'a> {
            fn add_to_diag<__G>(self, diag: &mut rustc_errors::Diag<'_, __G>)
                where __G: rustc_errors::EmissionGuarantee {
                match self {
                    SuggestAccessingField::Safe {
                        span: __binding_0,
                        snippet: __binding_1,
                        name: __binding_2,
                        ty: __binding_3 } => {
                        let __code_28 =
                            [::alloc::__export::must_use({
                                                ::alloc::fmt::format(format_args!("{1}.{0}", __binding_2,
                                                        __binding_1))
                                            })].into_iter();
                        let mut sub_args = rustc_errors::DiagArgMap::default();
                        sub_args.insert("snippet".into(),
                            rustc_errors::IntoDiagArg::into_diag_arg(__binding_1,
                                &mut diag.long_ty_path));
                        sub_args.insert("name".into(),
                            rustc_errors::IntoDiagArg::into_diag_arg(__binding_2,
                                &mut diag.long_ty_path));
                        sub_args.insert("ty".into(),
                            rustc_errors::IntoDiagArg::into_diag_arg(__binding_3,
                                &mut diag.long_ty_path));
                        let __message =
                            rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("you might have meant to use field `{$name}` whose type is `{$ty}`")),
                                &sub_args);
                        diag.span_suggestions_with_style(__binding_0, __message,
                            __code_28, rustc_errors::Applicability::MaybeIncorrect,
                            rustc_errors::SuggestionStyle::ShowAlways);
                    }
                    SuggestAccessingField::Unsafe {
                        span: __binding_0,
                        snippet: __binding_1,
                        name: __binding_2,
                        ty: __binding_3 } => {
                        let __code_29 =
                            [::alloc::__export::must_use({
                                                ::alloc::fmt::format(format_args!("unsafe {{ {1}.{0} }}",
                                                        __binding_2, __binding_1))
                                            })].into_iter();
                        let mut sub_args = rustc_errors::DiagArgMap::default();
                        sub_args.insert("snippet".into(),
                            rustc_errors::IntoDiagArg::into_diag_arg(__binding_1,
                                &mut diag.long_ty_path));
                        sub_args.insert("name".into(),
                            rustc_errors::IntoDiagArg::into_diag_arg(__binding_2,
                                &mut diag.long_ty_path));
                        sub_args.insert("ty".into(),
                            rustc_errors::IntoDiagArg::into_diag_arg(__binding_3,
                                &mut diag.long_ty_path));
                        let __message =
                            rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("you might have meant to use field `{$name}` whose type is `{$ty}`")),
                                &sub_args);
                        diag.span_suggestions_with_style(__binding_0, __message,
                            __code_29, rustc_errors::Applicability::MaybeIncorrect,
                            rustc_errors::SuggestionStyle::ShowAlways);
                    }
                }
            }
        }
    };Subdiagnostic)]
1640pub enum SuggestAccessingField<'a> {
1641    #[suggestion(
1642        "you might have meant to use field `{$name}` whose type is `{$ty}`",
1643        code = "{snippet}.{name}",
1644        applicability = "maybe-incorrect",
1645        style = "verbose"
1646    )]
1647    Safe {
1648        #[primary_span]
1649        span: Span,
1650        snippet: String,
1651        name: Symbol,
1652        ty: Ty<'a>,
1653    },
1654    #[suggestion(
1655        "you might have meant to use field `{$name}` whose type is `{$ty}`",
1656        code = "unsafe {{ {snippet}.{name} }}",
1657        applicability = "maybe-incorrect",
1658        style = "verbose"
1659    )]
1660    Unsafe {
1661        #[primary_span]
1662        span: Span,
1663        snippet: String,
1664        name: Symbol,
1665        ty: Ty<'a>,
1666    },
1667}
1668
1669#[derive(const _: () =
    {
        impl rustc_errors::Subdiagnostic for SuggestTuplePatternOne {
            fn add_to_diag<__G>(self, diag: &mut rustc_errors::Diag<'_, __G>)
                where __G: rustc_errors::EmissionGuarantee {
                match self {
                    SuggestTuplePatternOne {
                        variant: __binding_0,
                        span_low: __binding_1,
                        span_high: __binding_2 } => {
                        let mut suggestions = Vec::new();
                        let __code_30 =
                            ::alloc::__export::must_use({
                                    ::alloc::fmt::format(format_args!("{0}(", __binding_0))
                                });
                        let __code_31 =
                            ::alloc::__export::must_use({
                                    ::alloc::fmt::format(format_args!(")"))
                                });
                        suggestions.push((__binding_1, __code_30));
                        suggestions.push((__binding_2, __code_31));
                        let mut sub_args = rustc_errors::DiagArgMap::default();
                        sub_args.insert("variant".into(),
                            rustc_errors::IntoDiagArg::into_diag_arg(__binding_0,
                                &mut diag.long_ty_path));
                        let __message =
                            rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("try wrapping the pattern in `{$variant}`")),
                                &sub_args);
                        diag.multipart_suggestion_with_style(__message, suggestions,
                            rustc_errors::Applicability::MaybeIncorrect,
                            rustc_errors::SuggestionStyle::ShowCode);
                    }
                }
            }
        }
    };Subdiagnostic)]
1670#[multipart_suggestion(
1671    "try wrapping the pattern in `{$variant}`",
1672    applicability = "maybe-incorrect"
1673)]
1674pub struct SuggestTuplePatternOne {
1675    pub variant: String,
1676    #[suggestion_part(code = "{variant}(")]
1677    pub span_low: Span,
1678    #[suggestion_part(code = ")")]
1679    pub span_high: Span,
1680}
1681
1682pub struct SuggestTuplePatternMany {
1683    pub path: String,
1684    pub cause_span: Span,
1685    pub compatible_variants: Vec<String>,
1686}
1687
1688impl Subdiagnostic for SuggestTuplePatternMany {
1689    fn add_to_diag<G: EmissionGuarantee>(self, diag: &mut Diag<'_, G>) {
1690        diag.arg("path", self.path);
1691        let message = rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("try wrapping the pattern in a variant of `{$path}`"))msg!("try wrapping the pattern in a variant of `{$path}`");
1692        diag.multipart_suggestions(
1693            message,
1694            self.compatible_variants.into_iter().map(|variant| {
1695                ::alloc::boxed::box_assume_init_into_vec_unsafe(::alloc::intrinsics::write_box_via_move(::alloc::boxed::Box::new_uninit(),
        [(self.cause_span.shrink_to_lo(),
                    ::alloc::__export::must_use({
                            ::alloc::fmt::format(format_args!("{0}(", variant))
                        })), (self.cause_span.shrink_to_hi(), ")".to_string())]))vec![
1696                    (self.cause_span.shrink_to_lo(), format!("{variant}(")),
1697                    (self.cause_span.shrink_to_hi(), ")".to_string()),
1698                ]
1699            }),
1700            rustc_errors::Applicability::MaybeIncorrect,
1701        );
1702    }
1703}
1704
1705#[derive(const _: () =
    {
        impl rustc_errors::Subdiagnostic for TypeErrorAdditionalDiags {
            fn add_to_diag<__G>(self, diag: &mut rustc_errors::Diag<'_, __G>)
                where __G: rustc_errors::EmissionGuarantee {
                match self {
                    TypeErrorAdditionalDiags::MeantByteLiteral {
                        span: __binding_0, code: __binding_1 } => {
                        let __code_32 =
                            [::alloc::__export::must_use({
                                                ::alloc::fmt::format(format_args!("b\'{0}\'", __binding_1))
                                            })].into_iter();
                        let mut sub_args = rustc_errors::DiagArgMap::default();
                        sub_args.insert("code".into(),
                            rustc_errors::IntoDiagArg::into_diag_arg(__binding_1,
                                &mut diag.long_ty_path));
                        let __message =
                            rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("if you meant to write a byte literal, prefix with `b`")),
                                &sub_args);
                        diag.span_suggestions_with_style(__binding_0, __message,
                            __code_32, rustc_errors::Applicability::MachineApplicable,
                            rustc_errors::SuggestionStyle::ShowAlways);
                    }
                    TypeErrorAdditionalDiags::MeantCharLiteral {
                        span: __binding_0, code: __binding_1 } => {
                        let __code_33 =
                            [::alloc::__export::must_use({
                                                ::alloc::fmt::format(format_args!("\'{0}\'", __binding_1))
                                            })].into_iter();
                        let mut sub_args = rustc_errors::DiagArgMap::default();
                        sub_args.insert("code".into(),
                            rustc_errors::IntoDiagArg::into_diag_arg(__binding_1,
                                &mut diag.long_ty_path));
                        let __message =
                            rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("if you meant to write a `char` literal, use single quotes")),
                                &sub_args);
                        diag.span_suggestions_with_style(__binding_0, __message,
                            __code_33, rustc_errors::Applicability::MachineApplicable,
                            rustc_errors::SuggestionStyle::ShowAlways);
                    }
                    TypeErrorAdditionalDiags::MeantStrLiteral {
                        start: __binding_0, end: __binding_1 } => {
                        let mut suggestions = Vec::new();
                        let __code_34 =
                            ::alloc::__export::must_use({
                                    ::alloc::fmt::format(format_args!("\""))
                                });
                        let __code_35 =
                            ::alloc::__export::must_use({
                                    ::alloc::fmt::format(format_args!("\""))
                                });
                        suggestions.push((__binding_0, __code_34));
                        suggestions.push((__binding_1, __code_35));
                        let mut sub_args = rustc_errors::DiagArgMap::default();
                        let __message =
                            rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("if you meant to write a string literal, use double quotes")),
                                &sub_args);
                        diag.multipart_suggestion_with_style(__message, suggestions,
                            rustc_errors::Applicability::MachineApplicable,
                            rustc_errors::SuggestionStyle::ShowCode);
                    }
                    TypeErrorAdditionalDiags::ConsiderSpecifyingLength {
                        span: __binding_0, length: __binding_1 } => {
                        let __code_36 =
                            [::alloc::__export::must_use({
                                                ::alloc::fmt::format(format_args!("{0}", __binding_1))
                                            })].into_iter();
                        let mut sub_args = rustc_errors::DiagArgMap::default();
                        sub_args.insert("length".into(),
                            rustc_errors::IntoDiagArg::into_diag_arg(__binding_1,
                                &mut diag.long_ty_path));
                        let __message =
                            rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("consider specifying the actual array length")),
                                &sub_args);
                        diag.span_suggestions_with_style(__binding_0, __message,
                            __code_36, rustc_errors::Applicability::MaybeIncorrect,
                            rustc_errors::SuggestionStyle::ShowAlways);
                    }
                    TypeErrorAdditionalDiags::TryCannotConvert {
                        found: __binding_0, expected: __binding_1 } => {
                        let mut sub_args = rustc_errors::DiagArgMap::default();
                        sub_args.insert("found".into(),
                            rustc_errors::IntoDiagArg::into_diag_arg(__binding_0,
                                &mut diag.long_ty_path));
                        sub_args.insert("expected".into(),
                            rustc_errors::IntoDiagArg::into_diag_arg(__binding_1,
                                &mut diag.long_ty_path));
                        let __message =
                            rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("`?` operator cannot convert from `{$found}` to `{$expected}`")),
                                &sub_args);
                        diag.note(__message);
                    }
                    TypeErrorAdditionalDiags::TupleOnlyComma { span: __binding_0
                        } => {
                        let __code_37 =
                            [::alloc::__export::must_use({
                                                ::alloc::fmt::format(format_args!(","))
                                            })].into_iter();
                        let mut sub_args = rustc_errors::DiagArgMap::default();
                        let __message =
                            rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("use a trailing comma to create a tuple with one element")),
                                &sub_args);
                        diag.span_suggestions_with_style(__binding_0, __message,
                            __code_37, rustc_errors::Applicability::MachineApplicable,
                            rustc_errors::SuggestionStyle::ShowCode);
                    }
                    TypeErrorAdditionalDiags::TupleAlsoParentheses {
                        span_low: __binding_0, span_high: __binding_1 } => {
                        let mut suggestions = Vec::new();
                        let __code_38 =
                            ::alloc::__export::must_use({
                                    ::alloc::fmt::format(format_args!("("))
                                });
                        let __code_39 =
                            ::alloc::__export::must_use({
                                    ::alloc::fmt::format(format_args!(",)"))
                                });
                        suggestions.push((__binding_0, __code_38));
                        suggestions.push((__binding_1, __code_39));
                        let mut sub_args = rustc_errors::DiagArgMap::default();
                        let __message =
                            rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("use a trailing comma to create a tuple with one element")),
                                &sub_args);
                        diag.multipart_suggestion_with_style(__message, suggestions,
                            rustc_errors::Applicability::MachineApplicable,
                            rustc_errors::SuggestionStyle::ShowCode);
                    }
                    TypeErrorAdditionalDiags::AddLetForLetChains {
                        span: __binding_0 } => {
                        let __code_40 =
                            [::alloc::__export::must_use({
                                                ::alloc::fmt::format(format_args!("let "))
                                            })].into_iter();
                        let mut sub_args = rustc_errors::DiagArgMap::default();
                        let __message =
                            rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("consider adding `let`")),
                                &sub_args);
                        diag.span_suggestions_with_style(__binding_0, __message,
                            __code_40, rustc_errors::Applicability::MachineApplicable,
                            rustc_errors::SuggestionStyle::ShowAlways);
                    }
                }
            }
        }
    };Subdiagnostic)]
1706pub enum TypeErrorAdditionalDiags {
1707    #[suggestion(
1708        "if you meant to write a byte literal, prefix with `b`",
1709        code = "b'{code}'",
1710        applicability = "machine-applicable",
1711        style = "verbose"
1712    )]
1713    MeantByteLiteral {
1714        #[primary_span]
1715        span: Span,
1716        code: String,
1717    },
1718    #[suggestion(
1719        "if you meant to write a `char` literal, use single quotes",
1720        code = "'{code}'",
1721        applicability = "machine-applicable",
1722        style = "verbose"
1723    )]
1724    MeantCharLiteral {
1725        #[primary_span]
1726        span: Span,
1727        code: String,
1728    },
1729    #[multipart_suggestion(
1730        "if you meant to write a string literal, use double quotes",
1731        applicability = "machine-applicable"
1732    )]
1733    MeantStrLiteral {
1734        #[suggestion_part(code = "\"")]
1735        start: Span,
1736        #[suggestion_part(code = "\"")]
1737        end: Span,
1738    },
1739    #[suggestion(
1740        "consider specifying the actual array length",
1741        code = "{length}",
1742        applicability = "maybe-incorrect",
1743        style = "verbose"
1744    )]
1745    ConsiderSpecifyingLength {
1746        #[primary_span]
1747        span: Span,
1748        length: u64,
1749    },
1750    #[note("`?` operator cannot convert from `{$found}` to `{$expected}`")]
1751    TryCannotConvert { found: String, expected: String },
1752    #[suggestion(
1753        "use a trailing comma to create a tuple with one element",
1754        code = ",",
1755        applicability = "machine-applicable"
1756    )]
1757    TupleOnlyComma {
1758        #[primary_span]
1759        span: Span,
1760    },
1761    #[multipart_suggestion(
1762        "use a trailing comma to create a tuple with one element",
1763        applicability = "machine-applicable"
1764    )]
1765    TupleAlsoParentheses {
1766        #[suggestion_part(code = "(")]
1767        span_low: Span,
1768        #[suggestion_part(code = ",)")]
1769        span_high: Span,
1770    },
1771    #[suggestion(
1772        "consider adding `let`",
1773        style = "verbose",
1774        applicability = "machine-applicable",
1775        code = "let "
1776    )]
1777    AddLetForLetChains {
1778        #[primary_span]
1779        span: Span,
1780    },
1781}
1782
1783#[derive(const _: () =
    {
        impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for
            ObligationCauseFailureCode where
            G: rustc_errors::EmissionGuarantee {
            #[track_caller]
            fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
                level: rustc_errors::Level) -> rustc_errors::Diag<'_sess, G> {
                match self {
                    ObligationCauseFailureCode::MethodCompat {
                        span: __binding_0, subdiags: __binding_1 } => {
                        let mut diag =
                            rustc_errors::Diag::new(dcx, level,
                                rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("method not compatible with trait")));
                        diag.code(E0308);
                        ;
                        diag.span(__binding_0);
                        for __binding_1 in __binding_1 {
                            diag.subdiagnostic(__binding_1);
                        }
                        diag
                    }
                    ObligationCauseFailureCode::TypeCompat {
                        span: __binding_0, subdiags: __binding_1 } => {
                        let mut diag =
                            rustc_errors::Diag::new(dcx, level,
                                rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("type not compatible with trait")));
                        diag.code(E0308);
                        ;
                        diag.span(__binding_0);
                        for __binding_1 in __binding_1 {
                            diag.subdiagnostic(__binding_1);
                        }
                        diag
                    }
                    ObligationCauseFailureCode::ConstCompat {
                        span: __binding_0, subdiags: __binding_1 } => {
                        let mut diag =
                            rustc_errors::Diag::new(dcx, level,
                                rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("const not compatible with trait")));
                        diag.code(E0308);
                        ;
                        diag.span(__binding_0);
                        for __binding_1 in __binding_1 {
                            diag.subdiagnostic(__binding_1);
                        }
                        diag
                    }
                    ObligationCauseFailureCode::TryCompat {
                        span: __binding_0, subdiags: __binding_1 } => {
                        let mut diag =
                            rustc_errors::Diag::new(dcx, level,
                                rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("`?` operator has incompatible types")));
                        diag.code(E0308);
                        ;
                        diag.span(__binding_0);
                        for __binding_1 in __binding_1 {
                            diag.subdiagnostic(__binding_1);
                        }
                        diag
                    }
                    ObligationCauseFailureCode::MatchCompat {
                        span: __binding_0, subdiags: __binding_1 } => {
                        let mut diag =
                            rustc_errors::Diag::new(dcx, level,
                                rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("`match` arms have incompatible types")));
                        diag.code(E0308);
                        ;
                        diag.span(__binding_0);
                        for __binding_1 in __binding_1 {
                            diag.subdiagnostic(__binding_1);
                        }
                        diag
                    }
                    ObligationCauseFailureCode::IfElseDifferent {
                        span: __binding_0, subdiags: __binding_1 } => {
                        let mut diag =
                            rustc_errors::Diag::new(dcx, level,
                                rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("`if` and `else` have incompatible types")));
                        diag.code(E0308);
                        ;
                        diag.span(__binding_0);
                        for __binding_1 in __binding_1 {
                            diag.subdiagnostic(__binding_1);
                        }
                        diag
                    }
                    ObligationCauseFailureCode::NoElse { span: __binding_0 } =>
                        {
                        let mut diag =
                            rustc_errors::Diag::new(dcx, level,
                                rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("`if` may be missing an `else` clause")));
                        diag.code(E0317);
                        ;
                        diag.span(__binding_0);
                        diag
                    }
                    ObligationCauseFailureCode::NoDiverge {
                        span: __binding_0, subdiags: __binding_1 } => {
                        let mut diag =
                            rustc_errors::Diag::new(dcx, level,
                                rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("`else` clause of `let...else` does not diverge")));
                        diag.code(E0308);
                        ;
                        diag.span(__binding_0);
                        for __binding_1 in __binding_1 {
                            diag.subdiagnostic(__binding_1);
                        }
                        diag
                    }
                    ObligationCauseFailureCode::FnMainCorrectType {
                        span: __binding_0 } => {
                        let mut diag =
                            rustc_errors::Diag::new(dcx, level,
                                rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("`main` function has wrong type")));
                        diag.code(E0580);
                        ;
                        diag.span(__binding_0);
                        diag
                    }
                    ObligationCauseFailureCode::FnLangCorrectType {
                        span: __binding_0,
                        subdiags: __binding_1,
                        lang_item_name: __binding_2 } => {
                        let mut diag =
                            rustc_errors::Diag::new(dcx, level,
                                rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("{$lang_item_name ->\n            [panic_impl] `#[panic_handler]`\n            *[lang_item_name] lang item `{$lang_item_name}`\n        } function has wrong type")));
                        diag.code(E0308);
                        ;
                        diag.arg("lang_item_name", __binding_2);
                        diag.span(__binding_0);
                        for __binding_1 in __binding_1 {
                            diag.subdiagnostic(__binding_1);
                        }
                        diag
                    }
                    ObligationCauseFailureCode::IntrinsicCorrectType {
                        span: __binding_0, subdiags: __binding_1 } => {
                        let mut diag =
                            rustc_errors::Diag::new(dcx, level,
                                rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("intrinsic has wrong type")));
                        diag.code(E0308);
                        ;
                        diag.span(__binding_0);
                        for __binding_1 in __binding_1 {
                            diag.subdiagnostic(__binding_1);
                        }
                        diag
                    }
                    ObligationCauseFailureCode::MethodCorrectType {
                        span: __binding_0, subdiags: __binding_1 } => {
                        let mut diag =
                            rustc_errors::Diag::new(dcx, level,
                                rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("mismatched `self` parameter type")));
                        diag.code(E0308);
                        ;
                        diag.span(__binding_0);
                        for __binding_1 in __binding_1 {
                            diag.subdiagnostic(__binding_1);
                        }
                        diag
                    }
                    ObligationCauseFailureCode::ClosureSelfref {
                        span: __binding_0 } => {
                        let mut diag =
                            rustc_errors::Diag::new(dcx, level,
                                rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("closure/coroutine type that references itself")));
                        diag.code(E0644);
                        ;
                        diag.span(__binding_0);
                        diag
                    }
                    ObligationCauseFailureCode::CantCoerceForceInline {
                        span: __binding_0, subdiags: __binding_1 } => {
                        let mut diag =
                            rustc_errors::Diag::new(dcx, level,
                                rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("cannot coerce functions which must be inlined to function pointers")));
                        diag.code(E0308);
                        ;
                        diag.span(__binding_0);
                        for __binding_1 in __binding_1 {
                            diag.subdiagnostic(__binding_1);
                        }
                        diag
                    }
                    ObligationCauseFailureCode::CantCoerceIntrinsic {
                        span: __binding_0, subdiags: __binding_1 } => {
                        let mut diag =
                            rustc_errors::Diag::new(dcx, level,
                                rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("cannot coerce intrinsics to function pointers")));
                        diag.code(E0308);
                        ;
                        diag.span(__binding_0);
                        for __binding_1 in __binding_1 {
                            diag.subdiagnostic(__binding_1);
                        }
                        diag
                    }
                    ObligationCauseFailureCode::Generic {
                        span: __binding_0, subdiags: __binding_1 } => {
                        let mut diag =
                            rustc_errors::Diag::new(dcx, level,
                                rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("mismatched types")));
                        diag.code(E0308);
                        ;
                        diag.span(__binding_0);
                        for __binding_1 in __binding_1 {
                            diag.subdiagnostic(__binding_1);
                        }
                        diag
                    }
                }
            }
        }
    };Diagnostic)]
1784pub enum ObligationCauseFailureCode {
1785    #[diag("method not compatible with trait", code = E0308)]
1786    MethodCompat {
1787        #[primary_span]
1788        span: Span,
1789        #[subdiagnostic]
1790        subdiags: Vec<TypeErrorAdditionalDiags>,
1791    },
1792    #[diag("type not compatible with trait", code = E0308)]
1793    TypeCompat {
1794        #[primary_span]
1795        span: Span,
1796        #[subdiagnostic]
1797        subdiags: Vec<TypeErrorAdditionalDiags>,
1798    },
1799    #[diag("const not compatible with trait", code = E0308)]
1800    ConstCompat {
1801        #[primary_span]
1802        span: Span,
1803        #[subdiagnostic]
1804        subdiags: Vec<TypeErrorAdditionalDiags>,
1805    },
1806    #[diag("`?` operator has incompatible types", code = E0308)]
1807    TryCompat {
1808        #[primary_span]
1809        span: Span,
1810        #[subdiagnostic]
1811        subdiags: Vec<TypeErrorAdditionalDiags>,
1812    },
1813    #[diag("`match` arms have incompatible types", code = E0308)]
1814    MatchCompat {
1815        #[primary_span]
1816        span: Span,
1817        #[subdiagnostic]
1818        subdiags: Vec<TypeErrorAdditionalDiags>,
1819    },
1820    #[diag("`if` and `else` have incompatible types", code = E0308)]
1821    IfElseDifferent {
1822        #[primary_span]
1823        span: Span,
1824        #[subdiagnostic]
1825        subdiags: Vec<TypeErrorAdditionalDiags>,
1826    },
1827    #[diag("`if` may be missing an `else` clause", code = E0317)]
1828    NoElse {
1829        #[primary_span]
1830        span: Span,
1831    },
1832    #[diag("`else` clause of `let...else` does not diverge", code = E0308)]
1833    NoDiverge {
1834        #[primary_span]
1835        span: Span,
1836        #[subdiagnostic]
1837        subdiags: Vec<TypeErrorAdditionalDiags>,
1838    },
1839    #[diag("`main` function has wrong type", code = E0580)]
1840    FnMainCorrectType {
1841        #[primary_span]
1842        span: Span,
1843    },
1844    #[diag(
1845        "{$lang_item_name ->
1846            [panic_impl] `#[panic_handler]`
1847            *[lang_item_name] lang item `{$lang_item_name}`
1848        } function has wrong type"
1849    , code = E0308)]
1850    FnLangCorrectType {
1851        #[primary_span]
1852        span: Span,
1853        #[subdiagnostic]
1854        subdiags: Vec<TypeErrorAdditionalDiags>,
1855        lang_item_name: Symbol,
1856    },
1857    #[diag("intrinsic has wrong type", code = E0308)]
1858    IntrinsicCorrectType {
1859        #[primary_span]
1860        span: Span,
1861        #[subdiagnostic]
1862        subdiags: Vec<TypeErrorAdditionalDiags>,
1863    },
1864    #[diag("mismatched `self` parameter type", code = E0308)]
1865    MethodCorrectType {
1866        #[primary_span]
1867        span: Span,
1868        #[subdiagnostic]
1869        subdiags: Vec<TypeErrorAdditionalDiags>,
1870    },
1871    #[diag("closure/coroutine type that references itself", code = E0644)]
1872    ClosureSelfref {
1873        #[primary_span]
1874        span: Span,
1875    },
1876    #[diag("cannot coerce functions which must be inlined to function pointers", code = E0308)]
1877    CantCoerceForceInline {
1878        #[primary_span]
1879        span: Span,
1880        #[subdiagnostic]
1881        subdiags: Vec<TypeErrorAdditionalDiags>,
1882    },
1883    #[diag("cannot coerce intrinsics to function pointers", code = E0308)]
1884    CantCoerceIntrinsic {
1885        #[primary_span]
1886        span: Span,
1887        #[subdiagnostic]
1888        subdiags: Vec<TypeErrorAdditionalDiags>,
1889    },
1890    #[diag("mismatched types", code = E0308)]
1891    Generic {
1892        #[primary_span]
1893        span: Span,
1894        #[subdiagnostic]
1895        subdiags: Vec<TypeErrorAdditionalDiags>,
1896    },
1897}
1898
1899#[derive(const _: () =
    {
        impl rustc_errors::Subdiagnostic for AddPreciseCapturing {
            fn add_to_diag<__G>(self, diag: &mut rustc_errors::Diag<'_, __G>)
                where __G: rustc_errors::EmissionGuarantee {
                match self {
                    AddPreciseCapturing::New {
                        span: __binding_0,
                        new_lifetime: __binding_1,
                        concatenated_bounds: __binding_2 } => {
                        let __code_41 =
                            [::alloc::__export::must_use({
                                                ::alloc::fmt::format(format_args!(" + use<{0}>",
                                                        __binding_2))
                                            })].into_iter();
                        let mut sub_args = rustc_errors::DiagArgMap::default();
                        sub_args.insert("new_lifetime".into(),
                            rustc_errors::IntoDiagArg::into_diag_arg(__binding_1,
                                &mut diag.long_ty_path));
                        sub_args.insert("concatenated_bounds".into(),
                            rustc_errors::IntoDiagArg::into_diag_arg(__binding_2,
                                &mut diag.long_ty_path));
                        let __message =
                            rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("add a `use<...>` bound to explicitly capture `{$new_lifetime}`")),
                                &sub_args);
                        diag.span_suggestions_with_style(__binding_0, __message,
                            __code_41, rustc_errors::Applicability::MachineApplicable,
                            rustc_errors::SuggestionStyle::ShowAlways);
                    }
                    AddPreciseCapturing::Existing {
                        span: __binding_0,
                        new_lifetime: __binding_1,
                        pre: __binding_2,
                        post: __binding_3 } => {
                        let __code_42 =
                            [::alloc::__export::must_use({
                                                ::alloc::fmt::format(format_args!("{2}{0}{1}", __binding_1,
                                                        __binding_3, __binding_2))
                                            })].into_iter();
                        let mut sub_args = rustc_errors::DiagArgMap::default();
                        sub_args.insert("new_lifetime".into(),
                            rustc_errors::IntoDiagArg::into_diag_arg(__binding_1,
                                &mut diag.long_ty_path));
                        sub_args.insert("pre".into(),
                            rustc_errors::IntoDiagArg::into_diag_arg(__binding_2,
                                &mut diag.long_ty_path));
                        sub_args.insert("post".into(),
                            rustc_errors::IntoDiagArg::into_diag_arg(__binding_3,
                                &mut diag.long_ty_path));
                        let __message =
                            rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("add `{$new_lifetime}` to the `use<...>` bound to explicitly capture it")),
                                &sub_args);
                        diag.span_suggestions_with_style(__binding_0, __message,
                            __code_42, rustc_errors::Applicability::MachineApplicable,
                            rustc_errors::SuggestionStyle::ShowAlways);
                    }
                }
            }
        }
    };Subdiagnostic)]
1900pub enum AddPreciseCapturing {
1901    #[suggestion(
1902        "add a `use<...>` bound to explicitly capture `{$new_lifetime}`",
1903        style = "verbose",
1904        code = " + use<{concatenated_bounds}>",
1905        applicability = "machine-applicable"
1906    )]
1907    New {
1908        #[primary_span]
1909        span: Span,
1910        new_lifetime: Symbol,
1911        concatenated_bounds: String,
1912    },
1913    #[suggestion(
1914        "add `{$new_lifetime}` to the `use<...>` bound to explicitly capture it",
1915        style = "verbose",
1916        code = "{pre}{new_lifetime}{post}",
1917        applicability = "machine-applicable"
1918    )]
1919    Existing {
1920        #[primary_span]
1921        span: Span,
1922        new_lifetime: Symbol,
1923        pre: &'static str,
1924        post: &'static str,
1925    },
1926}
1927
1928pub struct AddPreciseCapturingAndParams {
1929    pub suggs: Vec<(Span, String)>,
1930    pub new_lifetime: Symbol,
1931    pub apit_spans: Vec<Span>,
1932}
1933
1934impl Subdiagnostic for AddPreciseCapturingAndParams {
1935    fn add_to_diag<G: EmissionGuarantee>(self, diag: &mut Diag<'_, G>) {
1936        diag.arg("new_lifetime", self.new_lifetime);
1937        diag.multipart_suggestion(
1938            rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("add a `use<...>` bound to explicitly capture `{$new_lifetime}` after turning all argument-position `impl Trait` into type parameters, noting that this possibly affects the API of this crate"))msg!("add a `use<...>` bound to explicitly capture `{$new_lifetime}` after turning all argument-position `impl Trait` into type parameters, noting that this possibly affects the API of this crate"),
1939            self.suggs,
1940            Applicability::MaybeIncorrect,
1941        );
1942        diag.span_note(
1943            self.apit_spans,
1944            rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("you could use a `use<...>` bound to explicitly capture `{$new_lifetime}`, but argument-position `impl Trait`s are not nameable"))msg!("you could use a `use<...>` bound to explicitly capture `{$new_lifetime}`, but argument-position `impl Trait`s are not nameable"),
1945        );
1946    }
1947}
1948
1949/// Given a set of captured `DefId` for an RPIT (opaque_def_id) and a given
1950/// function (fn_def_id), try to suggest adding `+ use<...>` to capture just
1951/// the specified parameters. If one of those parameters is an APIT, then try
1952/// to suggest turning it into a regular type parameter.
1953pub fn impl_trait_overcapture_suggestion<'tcx>(
1954    tcx: TyCtxt<'tcx>,
1955    opaque_def_id: LocalDefId,
1956    fn_def_id: LocalDefId,
1957    captured_args: FxIndexSet<DefId>,
1958) -> Option<AddPreciseCapturingForOvercapture> {
1959    let generics = tcx.generics_of(fn_def_id);
1960
1961    let mut captured_lifetimes = FxIndexSet::default();
1962    let mut captured_non_lifetimes = FxIndexSet::default();
1963    let mut synthetics = ::alloc::vec::Vec::new()vec![];
1964
1965    for arg in captured_args {
1966        if tcx.def_kind(arg) == DefKind::LifetimeParam {
1967            captured_lifetimes.insert(tcx.item_name(arg));
1968        } else {
1969            let idx = generics.param_def_id_to_index(tcx, arg).expect("expected arg in scope");
1970            let param = generics.param_at(idx as usize, tcx);
1971            if param.kind.is_synthetic() {
1972                synthetics.push((tcx.def_span(arg), param.name));
1973            } else {
1974                captured_non_lifetimes.insert(tcx.item_name(arg));
1975            }
1976        }
1977    }
1978
1979    let mut next_fresh_param = || {
1980        ['T', 'U', 'V', 'W', 'X', 'Y', 'A', 'B', 'C']
1981            .into_iter()
1982            .map(sym::character)
1983            .chain((0..).map(|i| Symbol::intern(&::alloc::__export::must_use({ ::alloc::fmt::format(format_args!("T{0}", i)) })format!("T{i}"))))
1984            .find(|s| captured_non_lifetimes.insert(*s))
1985            .unwrap()
1986    };
1987
1988    let mut suggs = ::alloc::vec::Vec::new()vec![];
1989    let mut apit_spans = ::alloc::vec::Vec::new()vec![];
1990
1991    if !synthetics.is_empty() {
1992        let mut new_params = String::new();
1993        for (i, (span, name)) in synthetics.into_iter().enumerate() {
1994            apit_spans.push(span);
1995
1996            let fresh_param = next_fresh_param();
1997
1998            // Suggest renaming.
1999            suggs.push((span, fresh_param.to_string()));
2000
2001            // Super jank. Turn `impl Trait` into `T: Trait`.
2002            //
2003            // This currently involves stripping the `impl` from the name of
2004            // the parameter, since APITs are always named after how they are
2005            // rendered in the AST. This sucks! But to recreate the bound list
2006            // from the APIT itself would be miserable, so we're stuck with
2007            // this for now!
2008            if i > 0 {
2009                new_params += ", ";
2010            }
2011            let name_as_bounds = name.as_str().trim_start_matches("impl").trim_start();
2012            new_params += fresh_param.as_str();
2013            new_params += ": ";
2014            new_params += name_as_bounds;
2015        }
2016
2017        let Some(generics) = tcx.hir_get_generics(fn_def_id) else {
2018            // This shouldn't happen, but don't ICE.
2019            return None;
2020        };
2021
2022        // Add generics or concatenate to the end of the list.
2023        suggs.push(if let Some(params_span) = generics.span_for_param_suggestion() {
2024            (params_span, ::alloc::__export::must_use({
        ::alloc::fmt::format(format_args!(", {0}", new_params))
    })format!(", {new_params}"))
2025        } else {
2026            (generics.span, ::alloc::__export::must_use({
        ::alloc::fmt::format(format_args!("<{0}>", new_params))
    })format!("<{new_params}>"))
2027        });
2028    }
2029
2030    let concatenated_bounds = captured_lifetimes
2031        .into_iter()
2032        .chain(captured_non_lifetimes)
2033        .map(|sym| sym.to_string())
2034        .collect::<Vec<_>>()
2035        .join(", ");
2036
2037    let opaque_hir_id = tcx.local_def_id_to_hir_id(opaque_def_id);
2038    // FIXME: This is a bit too conservative, since it ignores parens already written in AST.
2039    let (lparen, rparen) = match tcx
2040        .hir_parent_iter(opaque_hir_id)
2041        .nth(1)
2042        .expect("expected ty to have a parent always")
2043        .1
2044    {
2045        Node::PathSegment(segment)
2046            if segment.args().paren_sugar_output().is_some_and(|ty| ty.hir_id == opaque_hir_id) =>
2047        {
2048            ("(", ")")
2049        }
2050        Node::Ty(ty) => match ty.kind {
2051            rustc_hir::TyKind::Ptr(_) | rustc_hir::TyKind::Ref(..) => ("(", ")"),
2052            // FIXME: RPITs are not allowed to be nested in `impl Fn() -> ...`,
2053            // but we eventually could support that, and that would necessitate
2054            // making this more sophisticated.
2055            _ => ("", ""),
2056        },
2057        _ => ("", ""),
2058    };
2059
2060    let rpit_span = tcx.def_span(opaque_def_id);
2061    if !lparen.is_empty() {
2062        suggs.push((rpit_span.shrink_to_lo(), lparen.to_string()));
2063    }
2064    suggs.push((rpit_span.shrink_to_hi(), ::alloc::__export::must_use({
        ::alloc::fmt::format(format_args!(" + use<{0}>{1}",
                concatenated_bounds, rparen))
    })format!(" + use<{concatenated_bounds}>{rparen}")));
2065
2066    Some(AddPreciseCapturingForOvercapture { suggs, apit_spans })
2067}
2068
2069pub struct AddPreciseCapturingForOvercapture {
2070    pub suggs: Vec<(Span, String)>,
2071    pub apit_spans: Vec<Span>,
2072}
2073
2074impl Subdiagnostic for AddPreciseCapturingForOvercapture {
2075    fn add_to_diag<G: EmissionGuarantee>(self, diag: &mut Diag<'_, G>) {
2076        let applicability = if self.apit_spans.is_empty() {
2077            Applicability::MachineApplicable
2078        } else {
2079            // If there are APIT that are converted to regular parameters,
2080            // then this may make the API turbofishable in ways that were
2081            // not intended.
2082            Applicability::MaybeIncorrect
2083        };
2084        diag.multipart_suggestion(
2085            rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("use the precise capturing `use<...>` syntax to make the captures explicit"))msg!("use the precise capturing `use<...>` syntax to make the captures explicit"),
2086            self.suggs,
2087            applicability,
2088        );
2089        if !self.apit_spans.is_empty() {
2090            diag.span_note(
2091                self.apit_spans,
2092                rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("you could use a `use<...>` bound to explicitly specify captures, but argument-position `impl Trait`s are not nameable"))msg!("you could use a `use<...>` bound to explicitly specify captures, but argument-position `impl Trait`s are not nameable"),
2093            );
2094        }
2095    }
2096}
2097
2098#[derive(const _: () =
    {
        impl<'_sess, 'a, 'tcx, G> rustc_errors::Diagnostic<'_sess, G> for
            NonGenericOpaqueTypeParam<'a, 'tcx> where
            G: rustc_errors::EmissionGuarantee {
            #[track_caller]
            fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
                level: rustc_errors::Level) -> rustc_errors::Diag<'_sess, G> {
                match self {
                    NonGenericOpaqueTypeParam {
                        arg: __binding_0,
                        kind: __binding_1,
                        span: __binding_2,
                        param_span: __binding_3 } => {
                        let mut diag =
                            rustc_errors::Diag::new(dcx, level,
                                rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("expected generic {$kind} parameter, found `{$arg}`")));
                        diag.code(E0792);
                        ;
                        diag.arg("arg", __binding_0);
                        diag.arg("kind", __binding_1);
                        diag.span(__binding_2);
                        diag.span_label(__binding_3,
                            rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("{STREQ($arg, \"'static\") ->\n        [true] cannot use static lifetime; use a bound lifetime instead or remove the lifetime parameter from the opaque type\n        *[other] this generic parameter must be used with a generic {$kind} parameter\n    }")));
                        diag
                    }
                }
            }
        }
    };Diagnostic)]
2099#[diag("expected generic {$kind} parameter, found `{$arg}`", code = E0792)]
2100pub(crate) struct NonGenericOpaqueTypeParam<'a, 'tcx> {
2101    pub arg: GenericArg<'tcx>,
2102    pub kind: &'a str,
2103    #[primary_span]
2104    pub span: Span,
2105    #[label("{STREQ($arg, \"'static\") ->
2106        [true] cannot use static lifetime; use a bound lifetime instead or remove the lifetime parameter from the opaque type
2107        *[other] this generic parameter must be used with a generic {$kind} parameter
2108    }")]
2109    pub param_span: Span,
2110}