Skip to main content

rustc_mir_transform/
errors.rs

1use rustc_errors::codes::*;
2use rustc_errors::{
3    Applicability, Diag, DiagCtxtHandle, DiagSymbolList, Diagnostic, EmissionGuarantee, Level,
4    Subdiagnostic, msg,
5};
6use rustc_macros::{Diagnostic, Subdiagnostic};
7use rustc_middle::mir::AssertKind;
8use rustc_middle::ty::TyCtxt;
9use rustc_session::lint::{self, Lint};
10use rustc_span::def_id::DefId;
11use rustc_span::{Ident, Span, Symbol};
12
13#[derive(const _: () =
    {
        impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for
            UnconditionalRecursion 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 {
                    UnconditionalRecursion {
                        span: __binding_0, call_sites: __binding_1 } => {
                        let mut diag =
                            rustc_errors::Diag::new(dcx, level,
                                rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("function cannot return without recursing")));
                        diag.help(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("a `loop` may express intention better if this is on purpose")));
                        ;
                        diag.span_label(__binding_0,
                            rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("cannot return without recursing")));
                        for __binding_1 in __binding_1 {
                            diag.span_label(__binding_1,
                                rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("recursive call site")));
                        }
                        diag
                    }
                }
            }
        }
    };Diagnostic)]
14#[diag("function cannot return without recursing")]
15#[help("a `loop` may express intention better if this is on purpose")]
16pub(crate) struct UnconditionalRecursion {
17    #[label("cannot return without recursing")]
18    pub(crate) span: Span,
19    #[label("recursive call site")]
20    pub(crate) call_sites: Vec<Span>,
21}
22
23#[derive(const _: () =
    {
        impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for
            InvalidForceInline 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 {
                    InvalidForceInline {
                        attr_span: __binding_0,
                        callee_span: __binding_1,
                        callee: __binding_2,
                        reason: __binding_3 } => {
                        let mut diag =
                            rustc_errors::Diag::new(dcx, level,
                                rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("`{$callee}` is incompatible with `#[rustc_force_inline]`")));
                        diag.note(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("incompatible due to: {$reason}")));
                        ;
                        diag.arg("callee", __binding_2);
                        diag.arg("reason", __binding_3);
                        diag.span(__binding_0);
                        diag.span_label(__binding_1,
                            rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("`{$callee}` defined here")));
                        diag
                    }
                }
            }
        }
    };Diagnostic)]
24#[diag("`{$callee}` is incompatible with `#[rustc_force_inline]`")]
25#[note("incompatible due to: {$reason}")]
26pub(crate) struct InvalidForceInline {
27    #[primary_span]
28    pub attr_span: Span,
29    #[label("`{$callee}` defined here")]
30    pub callee_span: Span,
31    pub callee: String,
32    pub reason: &'static str,
33}
34
35#[derive(const _: () =
    {
        impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for ConstMutate
            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 {
                    ConstMutate::Modify { konst: __binding_0 } => {
                        let mut diag =
                            rustc_errors::Diag::new(dcx, level,
                                rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("attempting to modify a `const` item")));
                        diag.note(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("each usage of a `const` item creates a new temporary; the original `const` item will not be modified")));
                        ;
                        diag.span_note(__binding_0,
                            rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("`const` item defined here")));
                        diag
                    }
                    ConstMutate::MutBorrow {
                        method_call: __binding_0, konst: __binding_1 } => {
                        let mut diag =
                            rustc_errors::Diag::new(dcx, level,
                                rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("taking a mutable reference to a `const` item")));
                        diag.note(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("each usage of a `const` item creates a new temporary")));
                        diag.note(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("the mutable reference will refer to this temporary, not the original `const` item")));
                        ;
                        if let Some(__binding_0) = __binding_0 {
                            diag.span_note(__binding_0,
                                rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("mutable reference created due to call to this method")));
                        }
                        diag.span_note(__binding_1,
                            rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("`const` item defined here")));
                        diag
                    }
                }
            }
        }
    };Diagnostic)]
36pub(crate) enum ConstMutate {
37    #[diag("attempting to modify a `const` item")]
38    #[note(
39        "each usage of a `const` item creates a new temporary; the original `const` item will not be modified"
40    )]
41    Modify {
42        #[note("`const` item defined here")]
43        konst: Span,
44    },
45    #[diag("taking a mutable reference to a `const` item")]
46    #[note("each usage of a `const` item creates a new temporary")]
47    #[note("the mutable reference will refer to this temporary, not the original `const` item")]
48    MutBorrow {
49        #[note("mutable reference created due to call to this method")]
50        method_call: Option<Span>,
51        #[note("`const` item defined here")]
52        konst: Span,
53    },
54}
55
56#[derive(const _: () =
    {
        impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for
            UnalignedPackedRef 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 {
                    UnalignedPackedRef {
                        span: __binding_0, ty_descr: __binding_1, align: __binding_2
                        } => {
                        let mut diag =
                            rustc_errors::Diag::new(dcx, level,
                                rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("reference to field of packed {$ty_descr} is unaligned")));
                        diag.code(E0793);
                        diag.note(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("this {$ty_descr} is {$align ->\n        [one] {\"\"}\n        *[other] {\"at most \"}\n    }{$align}-byte aligned, but the type of this field may require higher alignment")));
                        diag.note(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("creating a misaligned reference is undefined behavior (even if that reference is never dereferenced)")));
                        diag.help(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("copy the field contents to a local variable, or replace the reference with a raw pointer and use `read_unaligned`/`write_unaligned` (loads and stores via `*p` must be properly aligned even when using raw pointers)")));
                        ;
                        diag.arg("ty_descr", __binding_1);
                        diag.arg("align", __binding_2);
                        diag.span(__binding_0);
                        diag
                    }
                }
            }
        }
    };Diagnostic)]
57#[diag("reference to field of packed {$ty_descr} is unaligned", code = E0793)]
58#[note(
59    "this {$ty_descr} is {$align ->
60        [one] {\"\"}
61        *[other] {\"at most \"}
62    }{$align}-byte aligned, but the type of this field may require higher alignment"
63)]
64#[note(
65    "creating a misaligned reference is undefined behavior (even if that reference is never dereferenced)"
66)]
67#[help(
68    "copy the field contents to a local variable, or replace the reference with a raw pointer and use `read_unaligned`/`write_unaligned` (loads and stores via `*p` must be properly aligned even when using raw pointers)"
69)]
70pub(crate) struct UnalignedPackedRef {
71    #[primary_span]
72    pub span: Span,
73    pub ty_descr: &'static str,
74    pub align: u64,
75}
76
77#[derive(const _: () =
    {
        impl<'_sess, 'a, G> rustc_errors::Diagnostic<'_sess, G> for
            UnknownPassName<'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 {
                    UnknownPassName { name: __binding_0 } => {
                        let mut diag =
                            rustc_errors::Diag::new(dcx, level,
                                rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("MIR pass `{$name}` is unknown and will be ignored")));
                        ;
                        diag.arg("name", __binding_0);
                        diag
                    }
                }
            }
        }
    };Diagnostic)]
78#[diag("MIR pass `{$name}` is unknown and will be ignored")]
79pub(crate) struct UnknownPassName<'a> {
80    pub(crate) name: &'a str,
81}
82
83#[derive(const _: () =
    {
        impl<'_sess, 'a, G> rustc_errors::Diagnostic<'_sess, G> for
            ValidPassNames<'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 {
                    ValidPassNames { valid_passes: __binding_0 } => {
                        let mut diag =
                            rustc_errors::Diag::new(dcx, level,
                                rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("valid MIR pass names are: {$valid_passes}")));
                        ;
                        diag.arg("valid_passes", __binding_0);
                        diag
                    }
                }
            }
        }
    };Diagnostic)]
84#[diag("valid MIR pass names are: {$valid_passes}")]
85pub(crate) struct ValidPassNames<'a> {
86    pub(crate) valid_passes: DiagSymbolList<&'a str>,
87}
88
89pub(crate) struct AssertLint<P> {
90    pub span: Span,
91    pub assert_kind: AssertKind<P>,
92    pub lint_kind: AssertLintKind,
93}
94
95pub(crate) enum AssertLintKind {
96    ArithmeticOverflow,
97    UnconditionalPanic,
98}
99
100impl<'a, P: std::fmt::Debug> Diagnostic<'a, ()> for AssertLint<P> {
101    fn into_diag(self, dcx: DiagCtxtHandle<'a>, level: Level) -> Diag<'a, ()> {
102        let mut diag = Diag::new(
103            dcx,
104            level,
105            match self.lint_kind {
106                AssertLintKind::ArithmeticOverflow => {
107                    rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("this arithmetic operation will overflow"))msg!("this arithmetic operation will overflow")
108                }
109                AssertLintKind::UnconditionalPanic => {
110                    rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("this operation will panic at runtime"))msg!("this operation will panic at runtime")
111                }
112            },
113        );
114        diag.span_label(self.span, self.assert_kind.to_string());
115        diag
116    }
117}
118
119impl AssertLintKind {
120    pub(crate) fn lint(&self) -> &'static Lint {
121        match self {
122            AssertLintKind::ArithmeticOverflow => lint::builtin::ARITHMETIC_OVERFLOW,
123            AssertLintKind::UnconditionalPanic => lint::builtin::UNCONDITIONAL_PANIC,
124        }
125    }
126}
127
128#[derive(const _: () =
    {
        impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for AsmUnwindCall
            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 {
                    AsmUnwindCall { span: __binding_0 } => {
                        let mut diag =
                            rustc_errors::Diag::new(dcx, level,
                                rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("call to inline assembly that may unwind")));
                        ;
                        diag.span_label(__binding_0,
                            rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("call to inline assembly that may unwind")));
                        diag
                    }
                }
            }
        }
    };Diagnostic)]
129#[diag("call to inline assembly that may unwind")]
130pub(crate) struct AsmUnwindCall {
131    #[label("call to inline assembly that may unwind")]
132    pub span: Span,
133}
134
135#[derive(const _: () =
    {
        impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for FfiUnwindCall
            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 {
                    FfiUnwindCall { span: __binding_0, foreign: __binding_1 } =>
                        {
                        let mut diag =
                            rustc_errors::Diag::new(dcx, level,
                                rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("call to {$foreign ->\n        [true] foreign function\n        *[false] function pointer\n    } with FFI-unwind ABI")));
                        ;
                        diag.arg("foreign", __binding_1);
                        diag.span_label(__binding_0,
                            rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("call to {$foreign ->\n            [true] foreign function\n            *[false] function pointer\n        } with FFI-unwind ABI")));
                        diag
                    }
                }
            }
        }
    };Diagnostic)]
136#[diag(
137    "call to {$foreign ->
138        [true] foreign function
139        *[false] function pointer
140    } with FFI-unwind ABI"
141)]
142pub(crate) struct FfiUnwindCall {
143    #[label(
144        "call to {$foreign ->
145            [true] foreign function
146            *[false] function pointer
147        } with FFI-unwind ABI"
148    )]
149    pub span: Span,
150    pub foreign: bool,
151}
152
153#[derive(const _: () =
    {
        impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for FnItemRef
            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 {
                    FnItemRef {
                        span: __binding_0, sugg: __binding_1, ident: __binding_2 }
                        => {
                        let mut diag =
                            rustc_errors::Diag::new(dcx, level,
                                rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("taking a reference to a function item does not give a function pointer")));
                        let __code_0 =
                            [::alloc::__export::must_use({
                                                ::alloc::fmt::format(format_args!("{0}", __binding_1))
                                            })].into_iter();
                        ;
                        diag.arg("sugg", __binding_1);
                        diag.arg("ident", __binding_2);
                        diag.span_suggestions_with_style(__binding_0,
                            rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("cast `{$ident}` to obtain a function pointer")),
                            __code_0, rustc_errors::Applicability::Unspecified,
                            rustc_errors::SuggestionStyle::ShowCode);
                        diag
                    }
                }
            }
        }
    };Diagnostic)]
154#[diag("taking a reference to a function item does not give a function pointer")]
155pub(crate) struct FnItemRef {
156    #[suggestion(
157        "cast `{$ident}` to obtain a function pointer",
158        code = "{sugg}",
159        applicability = "unspecified"
160    )]
161    pub span: Span,
162    pub sugg: String,
163    pub ident: Ident,
164}
165
166#[derive(const _: () =
    {
        impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for
            UnusedCaptureMaybeCaptureRef 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 {
                    UnusedCaptureMaybeCaptureRef { name: __binding_0 } => {
                        let mut diag =
                            rustc_errors::Diag::new(dcx, level,
                                rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("value captured by `{$name}` is never read")));
                        diag.help(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("did you mean to capture by reference instead?")));
                        ;
                        diag.arg("name", __binding_0);
                        diag
                    }
                }
            }
        }
    };Diagnostic)]
167#[diag("value captured by `{$name}` is never read")]
168#[help("did you mean to capture by reference instead?")]
169pub(crate) struct UnusedCaptureMaybeCaptureRef {
170    pub name: Symbol,
171}
172
173#[derive(const _: () =
    {
        impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for
            UnusedVarAssignedOnly 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 {
                    UnusedVarAssignedOnly { name: __binding_0, typo: __binding_1
                        } => {
                        let mut diag =
                            rustc_errors::Diag::new(dcx, level,
                                rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("variable `{$name}` is assigned to, but never used")));
                        diag.note(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("consider using `_{$name}` instead")));
                        ;
                        diag.arg("name", __binding_0);
                        if let Some(__binding_1) = __binding_1 {
                            diag.subdiagnostic(__binding_1);
                        }
                        diag
                    }
                }
            }
        }
    };Diagnostic)]
174#[diag("variable `{$name}` is assigned to, but never used")]
175#[note("consider using `_{$name}` instead")]
176pub(crate) struct UnusedVarAssignedOnly {
177    pub name: Symbol,
178    #[subdiagnostic]
179    pub typo: Option<PatternTypo>,
180}
181
182#[derive(const _: () =
    {
        impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for UnusedAssign
            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 {
                    UnusedAssign {
                        name: __binding_0,
                        overwrite: __binding_1,
                        suggestion: __binding_2,
                        help: __binding_3 } => {
                        let mut diag =
                            rustc_errors::Diag::new(dcx, level,
                                rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("value assigned to `{$name}` is never read")));
                        ;
                        diag.arg("name", __binding_0);
                        if let Some(__binding_1) = __binding_1 {
                            diag.subdiagnostic(__binding_1);
                        }
                        if let Some(__binding_2) = __binding_2 {
                            diag.subdiagnostic(__binding_2);
                        }
                        if __binding_3 {
                            diag.help(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("maybe it is overwritten before being read?")));
                        }
                        diag
                    }
                }
            }
        }
    };Diagnostic)]
183#[diag("value assigned to `{$name}` is never read")]
184pub(crate) struct UnusedAssign {
185    pub name: Symbol,
186    #[subdiagnostic]
187    pub overwrite: Option<UnusedAssignOverwrite>,
188    #[subdiagnostic]
189    pub suggestion: Option<UnusedAssignSuggestion>,
190    #[help("maybe it is overwritten before being read?")]
191    pub help: bool,
192}
193
194pub(crate) struct UnusedAssignOverwrite {
195    pub assigned_span: Span,
196    pub overwrite_span: Span,
197    pub name: Symbol,
198}
199
200impl Subdiagnostic for UnusedAssignOverwrite {
201    fn add_to_diag<G: EmissionGuarantee>(self, diag: &mut Diag<'_, G>) {
202        diag.span_label(self.assigned_span, "this value is reassigned later and never used");
203        diag.span_label(
204            self.overwrite_span,
205            ::alloc::__export::must_use({
        ::alloc::fmt::format(format_args!("`{0}` is overwritten here before the previous value is read",
                self.name))
    })format!("`{}` is overwritten here before the previous value is read", self.name),
206        );
207    }
208}
209
210#[derive(const _: () =
    {
        impl rustc_errors::Subdiagnostic for UnusedAssignSuggestion {
            fn add_to_diag<__G>(self, diag: &mut rustc_errors::Diag<'_, __G>)
                where __G: rustc_errors::EmissionGuarantee {
                match self {
                    UnusedAssignSuggestion {
                        pre: __binding_0,
                        ty_span: __binding_1,
                        ty_ref_span: __binding_2,
                        pre_lhs_span: __binding_3,
                        rhs_borrow_span: __binding_4 } => {
                        let mut suggestions = Vec::new();
                        let __code_1 =
                            ::alloc::__export::must_use({
                                    ::alloc::fmt::format(format_args!("{0}mut ", __binding_0))
                                });
                        let __code_2 =
                            ::alloc::__export::must_use({
                                    ::alloc::fmt::format(format_args!(""))
                                });
                        let __code_3 =
                            ::alloc::__export::must_use({
                                    ::alloc::fmt::format(format_args!("*"))
                                });
                        let __code_4 =
                            ::alloc::__export::must_use({
                                    ::alloc::fmt::format(format_args!(""))
                                });
                        if let Some(__binding_1) = __binding_1 {
                            suggestions.push((__binding_1, __code_1));
                        }
                        suggestions.push((__binding_2, __code_2));
                        suggestions.push((__binding_3, __code_3));
                        suggestions.push((__binding_4, __code_4));
                        let mut sub_args = rustc_errors::DiagArgMap::default();
                        sub_args.insert("pre".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("you might have meant to mutate the pointed at value being passed in, instead of changing the reference in the local binding")),
                                &sub_args);
                        diag.multipart_suggestion_with_style(__message, suggestions,
                            rustc_errors::Applicability::MaybeIncorrect,
                            rustc_errors::SuggestionStyle::ShowCode);
                    }
                }
            }
        }
    };Subdiagnostic)]
211#[multipart_suggestion(
212    "you might have meant to mutate the pointed at value being passed in, instead of changing the reference in the local binding",
213    applicability = "maybe-incorrect"
214)]
215pub(crate) struct UnusedAssignSuggestion {
216    pub pre: &'static str,
217    #[suggestion_part(code = "{pre}mut ")]
218    pub ty_span: Option<Span>,
219    #[suggestion_part(code = "")]
220    pub ty_ref_span: Span,
221    #[suggestion_part(code = "*")]
222    pub pre_lhs_span: Span,
223    #[suggestion_part(code = "")]
224    pub rhs_borrow_span: Span,
225}
226
227#[derive(const _: () =
    {
        impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for
            UnusedAssignPassed 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 {
                    UnusedAssignPassed { name: __binding_0 } => {
                        let mut diag =
                            rustc_errors::Diag::new(dcx, level,
                                rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("value passed to `{$name}` is never read")));
                        diag.help(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("maybe it is overwritten before being read?")));
                        ;
                        diag.arg("name", __binding_0);
                        diag
                    }
                }
            }
        }
    };Diagnostic)]
228#[diag("value passed to `{$name}` is never read")]
229#[help("maybe it is overwritten before being read?")]
230pub(crate) struct UnusedAssignPassed {
231    pub name: Symbol,
232}
233
234#[derive(const _: () =
    {
        impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for UnusedVariable
            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 {
                    UnusedVariable {
                        name: __binding_0,
                        string_interp: __binding_1,
                        sugg: __binding_2 } => {
                        let mut diag =
                            rustc_errors::Diag::new(dcx, level,
                                rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("unused variable: `{$name}`")));
                        ;
                        diag.arg("name", __binding_0);
                        for __binding_1 in __binding_1 {
                            diag.subdiagnostic(__binding_1);
                        }
                        diag.subdiagnostic(__binding_2);
                        diag
                    }
                }
            }
        }
    };Diagnostic)]
235#[diag("unused variable: `{$name}`")]
236pub(crate) struct UnusedVariable {
237    pub name: Symbol,
238    #[subdiagnostic]
239    pub string_interp: Vec<UnusedVariableStringInterp>,
240    #[subdiagnostic]
241    pub sugg: UnusedVariableSugg,
242}
243
244#[derive(const _: () =
    {
        impl rustc_errors::Subdiagnostic for UnusedVariableSugg {
            fn add_to_diag<__G>(self, diag: &mut rustc_errors::Diag<'_, __G>)
                where __G: rustc_errors::EmissionGuarantee {
                match self {
                    UnusedVariableSugg::TryIgnore {
                        shorthands: __binding_0,
                        non_shorthands: __binding_1,
                        name: __binding_2 } => {
                        let mut suggestions = Vec::new();
                        let __code_5 =
                            ::alloc::__export::must_use({
                                    ::alloc::fmt::format(format_args!("{0}: _", __binding_2))
                                });
                        let __code_6 =
                            ::alloc::__export::must_use({
                                    ::alloc::fmt::format(format_args!("_"))
                                });
                        for __binding_0 in __binding_0 {
                            suggestions.push((__binding_0, __code_5.clone()));
                        }
                        for __binding_1 in __binding_1 {
                            suggestions.push((__binding_1, __code_6.clone()));
                        }
                        let mut sub_args = rustc_errors::DiagArgMap::default();
                        sub_args.insert("name".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("try ignoring the field")),
                                &sub_args);
                        diag.multipart_suggestion_with_style(__message, suggestions,
                            rustc_errors::Applicability::MachineApplicable,
                            rustc_errors::SuggestionStyle::ShowCode);
                    }
                    UnusedVariableSugg::TryPrefix {
                        spans: __binding_0, name: __binding_1, typo: __binding_2 }
                        => {
                        let mut suggestions = Vec::new();
                        let __code_7 =
                            ::alloc::__export::must_use({
                                    ::alloc::fmt::format(format_args!("_{0}", __binding_1))
                                });
                        for __binding_0 in __binding_0 {
                            suggestions.push((__binding_0, __code_7.clone()));
                        }
                        if let Some(__binding_2) = __binding_2 {
                            __binding_2.add_to_diag(diag);
                        }
                        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));
                        let __message =
                            rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("if this is intentional, prefix it with an underscore")),
                                &sub_args);
                        diag.multipart_suggestion_with_style(__message, suggestions,
                            rustc_errors::Applicability::MachineApplicable,
                            rustc_errors::SuggestionStyle::ShowCode);
                    }
                    UnusedVariableSugg::NoSugg {
                        span: __binding_0, name: __binding_1 } => {
                        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));
                        let __message =
                            rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("`{$name}` is captured in macro and introduced a unused variable")),
                                &sub_args);
                        diag.span_help(__binding_0, __message);
                    }
                }
            }
        }
    };Subdiagnostic)]
245pub(crate) enum UnusedVariableSugg {
246    #[multipart_suggestion("try ignoring the field", applicability = "machine-applicable")]
247    TryIgnore {
248        #[suggestion_part(code = "{name}: _")]
249        shorthands: Vec<Span>,
250        #[suggestion_part(code = "_")]
251        non_shorthands: Vec<Span>,
252        name: String,
253    },
254
255    #[multipart_suggestion(
256        "if this is intentional, prefix it with an underscore",
257        applicability = "machine-applicable"
258    )]
259    TryPrefix {
260        #[suggestion_part(code = "_{name}")]
261        spans: Vec<Span>,
262        name: Symbol,
263        #[subdiagnostic]
264        typo: Option<PatternTypo>,
265    },
266
267    #[help("`{$name}` is captured in macro and introduced a unused variable")]
268    NoSugg {
269        #[primary_span]
270        span: Span,
271        name: Symbol,
272    },
273}
274
275pub(crate) struct UnusedVariableStringInterp {
276    pub lit: Span,
277}
278
279impl Subdiagnostic for UnusedVariableStringInterp {
280    fn add_to_diag<G: EmissionGuarantee>(self, diag: &mut Diag<'_, G>) {
281        diag.span_label(
282            self.lit,
283            rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("you might have meant to use string interpolation in this string literal"))msg!("you might have meant to use string interpolation in this string literal"),
284        );
285        diag.multipart_suggestion(
286            rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("string interpolation only works in `format!` invocations"))msg!("string interpolation only works in `format!` invocations"),
287            ::alloc::boxed::box_assume_init_into_vec_unsafe(::alloc::intrinsics::write_box_via_move(::alloc::boxed::Box::new_uninit(),
        [(self.lit.shrink_to_lo(), String::from("format!(")),
                (self.lit.shrink_to_hi(), String::from(")"))]))vec![
288                (self.lit.shrink_to_lo(), String::from("format!(")),
289                (self.lit.shrink_to_hi(), String::from(")")),
290            ],
291            Applicability::MachineApplicable,
292        );
293    }
294}
295
296#[derive(const _: () =
    {
        impl rustc_errors::Subdiagnostic for PatternTypo {
            fn add_to_diag<__G>(self, diag: &mut rustc_errors::Diag<'_, __G>)
                where __G: rustc_errors::EmissionGuarantee {
                match self {
                    PatternTypo {
                        span: __binding_0,
                        code: __binding_1,
                        item_name: __binding_2,
                        kind: __binding_3 } => {
                        let mut suggestions = Vec::new();
                        let __code_8 =
                            ::alloc::__export::must_use({
                                    ::alloc::fmt::format(format_args!("{0}", __binding_1))
                                });
                        suggestions.push((__binding_0, __code_8));
                        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("item_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));
                        let __message =
                            rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("you might have meant to pattern match on the similarly named {$kind} `{$item_name}`")),
                                &sub_args);
                        diag.multipart_suggestion_with_style(__message, suggestions,
                            rustc_errors::Applicability::MaybeIncorrect,
                            rustc_errors::SuggestionStyle::ShowAlways);
                    }
                }
            }
        }
    };Subdiagnostic)]
297#[multipart_suggestion(
298    "you might have meant to pattern match on the similarly named {$kind} `{$item_name}`",
299    style = "verbose",
300    applicability = "maybe-incorrect"
301)]
302pub(crate) struct PatternTypo {
303    #[suggestion_part(code = "{code}")]
304    pub span: Span,
305    pub code: String,
306    pub item_name: Symbol,
307    pub kind: &'static str,
308}
309
310pub(crate) struct MustNotSupend<'a, 'tcx> {
311    pub tcx: TyCtxt<'tcx>,
312    pub yield_sp: Span,
313    pub reason: Option<MustNotSuspendReason>,
314    pub src_sp: Span,
315    pub pre: &'a str,
316    pub def_id: DefId,
317    pub post: &'a str,
318}
319
320// Needed for def_path_str
321impl<'a> Diagnostic<'a, ()> for MustNotSupend<'_, '_> {
322    fn into_diag(self, dcx: DiagCtxtHandle<'a>, level: Level) -> Diag<'a, ()> {
323        let mut diag = Diag::new(
324            dcx,
325            level,
326            rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("{$pre}`{$def_path}`{$post} held across a suspend point, but should not be"))msg!("{$pre}`{$def_path}`{$post} held across a suspend point, but should not be"),
327        );
328        diag.span_label(self.yield_sp, rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("the value is held across this suspend point"))msg!("the value is held across this suspend point"));
329        if let Some(reason) = self.reason {
330            diag.subdiagnostic(reason);
331        }
332        diag.span_help(self.src_sp, rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("consider using a block (`{\"{ ... }\"}`) to shrink the value's scope, ending before the suspend point"))msg!("consider using a block (`{\"{ ... }\"}`) to shrink the value's scope, ending before the suspend point"));
333        diag.arg("pre", self.pre);
334        diag.arg("def_path", self.tcx.def_path_str(self.def_id));
335        diag.arg("post", self.post);
336        diag
337    }
338}
339
340#[derive(const _: () =
    {
        impl rustc_errors::Subdiagnostic for MustNotSuspendReason {
            fn add_to_diag<__G>(self, diag: &mut rustc_errors::Diag<'_, __G>)
                where __G: rustc_errors::EmissionGuarantee {
                match self {
                    MustNotSuspendReason {
                        span: __binding_0, reason: __binding_1 } => {
                        let mut sub_args = rustc_errors::DiagArgMap::default();
                        sub_args.insert("reason".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("{$reason}")),
                                &sub_args);
                        diag.span_note(__binding_0, __message);
                    }
                }
            }
        }
    };Subdiagnostic)]
341#[note("{$reason}")]
342pub(crate) struct MustNotSuspendReason {
343    #[primary_span]
344    pub span: Span,
345    pub reason: Symbol,
346}
347
348#[derive(const _: () =
    {
        impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for
            ForceInlineFailure 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 {
                    ForceInlineFailure {
                        caller_span: __binding_0,
                        callee_span: __binding_1,
                        attr_span: __binding_2,
                        call_span: __binding_3,
                        callee: __binding_4,
                        caller: __binding_5,
                        reason: __binding_6,
                        justification: __binding_7 } => {
                        let mut diag =
                            rustc_errors::Diag::new(dcx, level,
                                rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("`{$callee}` could not be inlined into `{$caller}` but is required to be inlined")));
                        diag.note(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("could not be inlined due to: {$reason}")));
                        ;
                        diag.arg("callee", __binding_4);
                        diag.arg("caller", __binding_5);
                        diag.arg("reason", __binding_6);
                        diag.span_label(__binding_0,
                            rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("within `{$caller}`...")));
                        diag.span_label(__binding_1,
                            rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("`{$callee}` defined here")));
                        diag.span_label(__binding_2,
                            rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("annotation here")));
                        diag.span(__binding_3);
                        diag.span_label(__binding_3,
                            rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("...`{$callee}` called here")));
                        if let Some(__binding_7) = __binding_7 {
                            diag.subdiagnostic(__binding_7);
                        }
                        diag
                    }
                }
            }
        }
    };Diagnostic)]
349#[diag("`{$callee}` could not be inlined into `{$caller}` but is required to be inlined")]
350#[note("could not be inlined due to: {$reason}")]
351pub(crate) struct ForceInlineFailure {
352    #[label("within `{$caller}`...")]
353    pub caller_span: Span,
354    #[label("`{$callee}` defined here")]
355    pub callee_span: Span,
356    #[label("annotation here")]
357    pub attr_span: Span,
358    #[primary_span]
359    #[label("...`{$callee}` called here")]
360    pub call_span: Span,
361    pub callee: String,
362    pub caller: String,
363    pub reason: &'static str,
364    #[subdiagnostic]
365    pub justification: Option<ForceInlineJustification>,
366}
367
368#[derive(const _: () =
    {
        impl rustc_errors::Subdiagnostic for ForceInlineJustification {
            fn add_to_diag<__G>(self, diag: &mut rustc_errors::Diag<'_, __G>)
                where __G: rustc_errors::EmissionGuarantee {
                match self {
                    ForceInlineJustification {
                        sym: __binding_0, callee: __binding_1 } => {
                        let mut sub_args = rustc_errors::DiagArgMap::default();
                        sub_args.insert("sym".into(),
                            rustc_errors::IntoDiagArg::into_diag_arg(__binding_0,
                                &mut diag.long_ty_path));
                        sub_args.insert("callee".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("`{$callee}` is required to be inlined to: {$sym}")),
                                &sub_args);
                        diag.note(__message);
                    }
                }
            }
        }
    };Subdiagnostic)]
369#[note("`{$callee}` is required to be inlined to: {$sym}")]
370pub(crate) struct ForceInlineJustification {
371    pub sym: Symbol,
372    pub callee: String,
373}