Skip to main content

rustc_mir_transform/
diagnostics.rs

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