Skip to main content

rustc_mir_transform/
errors.rs

1use rustc_errors::codes::*;
2use rustc_errors::{Applicability, Diag, EmissionGuarantee, LintDiagnostic, Subdiagnostic};
3use rustc_macros::{Diagnostic, LintDiagnostic, Subdiagnostic};
4use rustc_middle::mir::AssertKind;
5use rustc_middle::query::Key;
6use rustc_middle::ty::TyCtxt;
7use rustc_session::lint::{self, Lint};
8use rustc_span::def_id::DefId;
9use rustc_span::{Ident, Span, Symbol};
10
11use crate::fluent_generated as fluent;
12
13/// Emit diagnostic for calls to `#[inline(always)]`-annotated functions with a
14/// `#[target_feature]` attribute where the caller enables a different set of target features.
15pub(crate) fn emit_inline_always_target_feature_diagnostic<'a, 'tcx>(
16    tcx: TyCtxt<'tcx>,
17    call_span: Span,
18    callee_def_id: DefId,
19    caller_def_id: DefId,
20    callee_only: &[&'a str],
21) {
22    tcx.node_span_lint(
23        lint::builtin::INLINE_ALWAYS_MISMATCHING_TARGET_FEATURES,
24        tcx.local_def_id_to_hir_id(caller_def_id.as_local().unwrap()),
25        call_span,
26        |lint| {
27            let callee = tcx.def_path_str(callee_def_id);
28            let caller = tcx.def_path_str(caller_def_id);
29
30            lint.primary_message(::alloc::__export::must_use({
        ::alloc::fmt::format(format_args!("call to `#[inline(always)]`-annotated `{0}` requires the same target features to be inlined",
                callee))
    })format!(
31                "call to `#[inline(always)]`-annotated `{callee}` \
32                requires the same target features to be inlined"
33            ));
34            lint.note("function will not be inlined");
35
36            lint.note(::alloc::__export::must_use({
        ::alloc::fmt::format(format_args!("the following target features are on `{1}` but missing from `{2}`: {0}",
                callee_only.join(", "), callee, caller))
    })format!(
37                "the following target features are on `{callee}` but missing from `{caller}`: {}",
38                callee_only.join(", ")
39            ));
40            lint.span_note(callee_def_id.default_span(tcx), ::alloc::__export::must_use({
        ::alloc::fmt::format(format_args!("`{0}` is defined here", callee))
    })format!("`{callee}` is defined here"));
41
42            let feats = callee_only.join(",");
43            lint.span_suggestion(
44                tcx.def_span(caller_def_id).shrink_to_lo(),
45                ::alloc::__export::must_use({
        ::alloc::fmt::format(format_args!("add `#[target_feature]` attribute to `{0}`",
                caller))
    })format!("add `#[target_feature]` attribute to `{caller}`"),
46                ::alloc::__export::must_use({
        ::alloc::fmt::format(format_args!("#[target_feature(enable = \"{0}\")]\n",
                feats))
    })format!("#[target_feature(enable = \"{feats}\")]\n"),
47                lint::Applicability::MaybeIncorrect,
48            );
49        },
50    );
51}
52
53#[derive(const _: () =
    {
        impl<'__a> rustc_errors::LintDiagnostic<'__a, ()> for
            UnconditionalRecursion {
            #[track_caller]
            fn decorate_lint<'__b>(self,
                diag: &'__b mut rustc_errors::Diag<'__a, ()>) {
                match self {
                    UnconditionalRecursion {
                        span: __binding_0, call_sites: __binding_1 } => {
                        diag.primary_message(crate::fluent_generated::mir_transform_unconditional_recursion);
                        diag.help(crate::fluent_generated::_subdiag::help);
                        ;
                        diag.span_label(__binding_0,
                            crate::fluent_generated::_subdiag::label);
                        for __binding_1 in __binding_1 {
                            diag.span_label(__binding_1,
                                crate::fluent_generated::mir_transform_unconditional_recursion_call_site_label);
                        }
                        diag
                    }
                };
            }
        }
    };LintDiagnostic)]
54#[diag(mir_transform_unconditional_recursion)]
55#[help]
56pub(crate) struct UnconditionalRecursion {
57    #[label]
58    pub(crate) span: Span,
59    #[label(mir_transform_unconditional_recursion_call_site_label)]
60    pub(crate) call_sites: Vec<Span>,
61}
62
63#[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,
                                crate::fluent_generated::mir_transform_force_inline_attr);
                        diag.note(crate::fluent_generated::_subdiag::note);
                        ;
                        diag.arg("callee", __binding_2);
                        diag.arg("reason", __binding_3);
                        diag.span(__binding_0);
                        diag.span_label(__binding_1,
                            crate::fluent_generated::mir_transform_callee);
                        diag
                    }
                }
            }
        }
    };Diagnostic)]
64#[diag(mir_transform_force_inline_attr)]
65#[note]
66pub(crate) struct InvalidForceInline {
67    #[primary_span]
68    pub attr_span: Span,
69    #[label(mir_transform_callee)]
70    pub callee_span: Span,
71    pub callee: String,
72    pub reason: &'static str,
73}
74
75#[derive(const _: () =
    {
        impl<'__a> rustc_errors::LintDiagnostic<'__a, ()> for ConstMutate {
            #[track_caller]
            fn decorate_lint<'__b>(self,
                diag: &'__b mut rustc_errors::Diag<'__a, ()>) {
                match self {
                    ConstMutate::Modify { konst: __binding_0 } => {
                        diag.primary_message(crate::fluent_generated::mir_transform_const_modify);
                        diag.note(crate::fluent_generated::_subdiag::note);
                        ;
                        diag.span_note(__binding_0,
                            crate::fluent_generated::mir_transform_const_defined_here);
                        diag
                    }
                    ConstMutate::MutBorrow {
                        method_call: __binding_0, konst: __binding_1 } => {
                        diag.primary_message(crate::fluent_generated::mir_transform_const_mut_borrow);
                        diag.note(crate::fluent_generated::_subdiag::note);
                        diag.note(crate::fluent_generated::mir_transform_note2);
                        ;
                        if let Some(__binding_0) = __binding_0 {
                            diag.span_note(__binding_0,
                                crate::fluent_generated::mir_transform_note3);
                        }
                        diag.span_note(__binding_1,
                            crate::fluent_generated::mir_transform_const_defined_here);
                        diag
                    }
                };
            }
        }
    };LintDiagnostic)]
76pub(crate) enum ConstMutate {
77    #[diag(mir_transform_const_modify)]
78    #[note]
79    Modify {
80        #[note(mir_transform_const_defined_here)]
81        konst: Span,
82    },
83    #[diag(mir_transform_const_mut_borrow)]
84    #[note]
85    #[note(mir_transform_note2)]
86    MutBorrow {
87        #[note(mir_transform_note3)]
88        method_call: Option<Span>,
89        #[note(mir_transform_const_defined_here)]
90        konst: Span,
91    },
92}
93
94#[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,
                                crate::fluent_generated::mir_transform_unaligned_packed_ref);
                        diag.code(E0793);
                        diag.note(crate::fluent_generated::_subdiag::note);
                        diag.note(crate::fluent_generated::mir_transform_note_ub);
                        diag.help(crate::fluent_generated::_subdiag::help);
                        ;
                        diag.arg("ty_descr", __binding_1);
                        diag.arg("align", __binding_2);
                        diag.span(__binding_0);
                        diag
                    }
                }
            }
        }
    };Diagnostic)]
95#[diag(mir_transform_unaligned_packed_ref, code = E0793)]
96#[note]
97#[note(mir_transform_note_ub)]
98#[help]
99pub(crate) struct UnalignedPackedRef {
100    #[primary_span]
101    pub span: Span,
102    pub ty_descr: &'static str,
103    pub align: u64,
104}
105
106#[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,
                                crate::fluent_generated::mir_transform_unknown_pass_name);
                        ;
                        diag.arg("name", __binding_0);
                        diag
                    }
                }
            }
        }
    };Diagnostic)]
107#[diag(mir_transform_unknown_pass_name)]
108pub(crate) struct UnknownPassName<'a> {
109    pub(crate) name: &'a str,
110}
111
112pub(crate) struct AssertLint<P> {
113    pub span: Span,
114    pub assert_kind: AssertKind<P>,
115    pub lint_kind: AssertLintKind,
116}
117
118pub(crate) enum AssertLintKind {
119    ArithmeticOverflow,
120    UnconditionalPanic,
121}
122
123impl<'a, P: std::fmt::Debug> LintDiagnostic<'a, ()> for AssertLint<P> {
124    fn decorate_lint<'b>(self, diag: &'b mut Diag<'a, ()>) {
125        diag.primary_message(match self.lint_kind {
126            AssertLintKind::ArithmeticOverflow => fluent::mir_transform_arithmetic_overflow,
127            AssertLintKind::UnconditionalPanic => fluent::mir_transform_operation_will_panic,
128        });
129        let label = self.assert_kind.diagnostic_message();
130        self.assert_kind.add_args(&mut |name, value| {
131            diag.arg(name, value);
132        });
133        diag.span_label(self.span, label);
134    }
135}
136
137impl AssertLintKind {
138    pub(crate) fn lint(&self) -> &'static Lint {
139        match self {
140            AssertLintKind::ArithmeticOverflow => lint::builtin::ARITHMETIC_OVERFLOW,
141            AssertLintKind::UnconditionalPanic => lint::builtin::UNCONDITIONAL_PANIC,
142        }
143    }
144}
145
146#[derive(const _: () =
    {
        impl<'__a> rustc_errors::LintDiagnostic<'__a, ()> for AsmUnwindCall {
            #[track_caller]
            fn decorate_lint<'__b>(self,
                diag: &'__b mut rustc_errors::Diag<'__a, ()>) {
                match self {
                    AsmUnwindCall { span: __binding_0 } => {
                        diag.primary_message(crate::fluent_generated::mir_transform_asm_unwind_call);
                        ;
                        diag.span_label(__binding_0,
                            crate::fluent_generated::mir_transform_asm_unwind_call);
                        diag
                    }
                };
            }
        }
    };LintDiagnostic)]
147#[diag(mir_transform_asm_unwind_call)]
148pub(crate) struct AsmUnwindCall {
149    #[label(mir_transform_asm_unwind_call)]
150    pub span: Span,
151}
152
153#[derive(const _: () =
    {
        impl<'__a> rustc_errors::LintDiagnostic<'__a, ()> for FfiUnwindCall {
            #[track_caller]
            fn decorate_lint<'__b>(self,
                diag: &'__b mut rustc_errors::Diag<'__a, ()>) {
                match self {
                    FfiUnwindCall { span: __binding_0, foreign: __binding_1 } =>
                        {
                        diag.primary_message(crate::fluent_generated::mir_transform_ffi_unwind_call);
                        ;
                        diag.arg("foreign", __binding_1);
                        diag.span_label(__binding_0,
                            crate::fluent_generated::mir_transform_ffi_unwind_call);
                        diag
                    }
                };
            }
        }
    };LintDiagnostic)]
154#[diag(mir_transform_ffi_unwind_call)]
155pub(crate) struct FfiUnwindCall {
156    #[label(mir_transform_ffi_unwind_call)]
157    pub span: Span,
158    pub foreign: bool,
159}
160
161#[derive(const _: () =
    {
        impl<'__a> rustc_errors::LintDiagnostic<'__a, ()> for FnItemRef {
            #[track_caller]
            fn decorate_lint<'__b>(self,
                diag: &'__b mut rustc_errors::Diag<'__a, ()>) {
                match self {
                    FnItemRef {
                        span: __binding_0, sugg: __binding_1, ident: __binding_2 }
                        => {
                        diag.primary_message(crate::fluent_generated::mir_transform_fn_item_ref);
                        ;
                        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,
                            crate::fluent_generated::_subdiag::suggestion, __code_0,
                            rustc_errors::Applicability::Unspecified,
                            rustc_errors::SuggestionStyle::ShowCode);
                        diag
                    }
                };
            }
        }
    };LintDiagnostic)]
162#[diag(mir_transform_fn_item_ref)]
163pub(crate) struct FnItemRef {
164    #[suggestion(code = "{sugg}", applicability = "unspecified")]
165    pub span: Span,
166    pub sugg: String,
167    pub ident: Ident,
168}
169
170#[derive(const _: () =
    {
        impl<'__a> rustc_errors::LintDiagnostic<'__a, ()> for
            UnusedCaptureMaybeCaptureRef {
            #[track_caller]
            fn decorate_lint<'__b>(self,
                diag: &'__b mut rustc_errors::Diag<'__a, ()>) {
                match self {
                    UnusedCaptureMaybeCaptureRef { name: __binding_0 } => {
                        diag.primary_message(crate::fluent_generated::mir_transform_unused_capture_maybe_capture_ref);
                        diag.help(crate::fluent_generated::_subdiag::help);
                        ;
                        diag.arg("name", __binding_0);
                        diag
                    }
                };
            }
        }
    };LintDiagnostic)]
171#[diag(mir_transform_unused_capture_maybe_capture_ref)]
172#[help]
173pub(crate) struct UnusedCaptureMaybeCaptureRef {
174    pub name: Symbol,
175}
176
177#[derive(const _: () =
    {
        impl<'__a> rustc_errors::LintDiagnostic<'__a, ()> for
            UnusedVarAssignedOnly {
            #[track_caller]
            fn decorate_lint<'__b>(self,
                diag: &'__b mut rustc_errors::Diag<'__a, ()>) {
                match self {
                    UnusedVarAssignedOnly { name: __binding_0, typo: __binding_1
                        } => {
                        diag.primary_message(crate::fluent_generated::mir_transform_unused_var_assigned_only);
                        diag.note(crate::fluent_generated::_subdiag::note);
                        ;
                        diag.arg("name", __binding_0);
                        if let Some(__binding_1) = __binding_1 {
                            diag.subdiagnostic(__binding_1);
                        }
                        diag
                    }
                };
            }
        }
    };LintDiagnostic)]
178#[diag(mir_transform_unused_var_assigned_only)]
179#[note]
180pub(crate) struct UnusedVarAssignedOnly {
181    pub name: Symbol,
182    #[subdiagnostic]
183    pub typo: Option<PatternTypo>,
184}
185
186#[derive(const _: () =
    {
        impl<'__a> rustc_errors::LintDiagnostic<'__a, ()> for UnusedAssign {
            #[track_caller]
            fn decorate_lint<'__b>(self,
                diag: &'__b mut rustc_errors::Diag<'__a, ()>) {
                match self {
                    UnusedAssign {
                        name: __binding_0,
                        suggestion: __binding_1,
                        help: __binding_2 } => {
                        diag.primary_message(crate::fluent_generated::mir_transform_unused_assign);
                        ;
                        diag.arg("name", __binding_0);
                        if let Some(__binding_1) = __binding_1 {
                            diag.subdiagnostic(__binding_1);
                        }
                        if __binding_2 {
                            diag.help(crate::fluent_generated::_subdiag::help);
                        }
                        diag
                    }
                };
            }
        }
    };LintDiagnostic)]
187#[diag(mir_transform_unused_assign)]
188pub(crate) struct UnusedAssign {
189    pub name: Symbol,
190    #[subdiagnostic]
191    pub suggestion: Option<UnusedAssignSuggestion>,
192    #[help]
193    pub help: bool,
194}
195
196#[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));
                        diag.store_args();
                        diag.arg("pre", __binding_0);
                        let __message =
                            diag.eagerly_translate(crate::fluent_generated::mir_transform_unused_assign_suggestion);
                        diag.multipart_suggestion_with_style(__message, suggestions,
                            rustc_errors::Applicability::MaybeIncorrect,
                            rustc_errors::SuggestionStyle::ShowCode);
                        diag.restore_args();
                    }
                }
            }
        }
    };Subdiagnostic)]
197#[multipart_suggestion(mir_transform_unused_assign_suggestion, applicability = "maybe-incorrect")]
198pub(crate) struct UnusedAssignSuggestion {
199    pub pre: &'static str,
200    #[suggestion_part(code = "{pre}mut ")]
201    pub ty_span: Option<Span>,
202    #[suggestion_part(code = "")]
203    pub ty_ref_span: Span,
204    #[suggestion_part(code = "*")]
205    pub pre_lhs_span: Span,
206    #[suggestion_part(code = "")]
207    pub rhs_borrow_span: Span,
208}
209
210#[derive(const _: () =
    {
        impl<'__a> rustc_errors::LintDiagnostic<'__a, ()> for
            UnusedAssignPassed {
            #[track_caller]
            fn decorate_lint<'__b>(self,
                diag: &'__b mut rustc_errors::Diag<'__a, ()>) {
                match self {
                    UnusedAssignPassed { name: __binding_0 } => {
                        diag.primary_message(crate::fluent_generated::mir_transform_unused_assign_passed);
                        diag.help(crate::fluent_generated::_subdiag::help);
                        ;
                        diag.arg("name", __binding_0);
                        diag
                    }
                };
            }
        }
    };LintDiagnostic)]
211#[diag(mir_transform_unused_assign_passed)]
212#[help]
213pub(crate) struct UnusedAssignPassed {
214    pub name: Symbol,
215}
216
217#[derive(const _: () =
    {
        impl<'__a> rustc_errors::LintDiagnostic<'__a, ()> for UnusedVariable {
            #[track_caller]
            fn decorate_lint<'__b>(self,
                diag: &'__b mut rustc_errors::Diag<'__a, ()>) {
                match self {
                    UnusedVariable {
                        name: __binding_0,
                        string_interp: __binding_1,
                        sugg: __binding_2 } => {
                        diag.primary_message(crate::fluent_generated::mir_transform_unused_variable);
                        ;
                        diag.arg("name", __binding_0);
                        for __binding_1 in __binding_1 {
                            diag.subdiagnostic(__binding_1);
                        }
                        diag.subdiagnostic(__binding_2);
                        diag
                    }
                };
            }
        }
    };LintDiagnostic)]
218#[diag(mir_transform_unused_variable)]
219pub(crate) struct UnusedVariable {
220    pub name: Symbol,
221    #[subdiagnostic]
222    pub string_interp: Vec<UnusedVariableStringInterp>,
223    #[subdiagnostic]
224    pub sugg: UnusedVariableSugg,
225}
226
227#[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()));
                        }
                        diag.store_args();
                        diag.arg("name", __binding_2);
                        let __message =
                            diag.eagerly_translate(crate::fluent_generated::mir_transform_unused_variable_try_ignore);
                        diag.multipart_suggestion_with_style(__message, suggestions,
                            rustc_errors::Applicability::MachineApplicable,
                            rustc_errors::SuggestionStyle::ShowCode);
                        diag.restore_args();
                    }
                    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);
                        }
                        diag.store_args();
                        diag.arg("name", __binding_1);
                        let __message =
                            diag.eagerly_translate(crate::fluent_generated::mir_transform_unused_var_underscore);
                        diag.multipart_suggestion_with_style(__message, suggestions,
                            rustc_errors::Applicability::MachineApplicable,
                            rustc_errors::SuggestionStyle::ShowCode);
                        diag.restore_args();
                    }
                    UnusedVariableSugg::NoSugg {
                        span: __binding_0, name: __binding_1 } => {
                        diag.store_args();
                        diag.arg("name", __binding_1);
                        let __message =
                            diag.eagerly_translate(crate::fluent_generated::mir_transform_unused_variable_args_in_macro);
                        diag.span_help(__binding_0, __message);
                        diag.restore_args();
                    }
                }
            }
        }
    };Subdiagnostic)]
228pub(crate) enum UnusedVariableSugg {
229    #[multipart_suggestion(
230        mir_transform_unused_variable_try_ignore,
231        applicability = "machine-applicable"
232    )]
233    TryIgnore {
234        #[suggestion_part(code = "{name}: _")]
235        shorthands: Vec<Span>,
236        #[suggestion_part(code = "_")]
237        non_shorthands: Vec<Span>,
238        name: Symbol,
239    },
240
241    #[multipart_suggestion(
242        mir_transform_unused_var_underscore,
243        applicability = "machine-applicable"
244    )]
245    TryPrefix {
246        #[suggestion_part(code = "_{name}")]
247        spans: Vec<Span>,
248        name: Symbol,
249        #[subdiagnostic]
250        typo: Option<PatternTypo>,
251    },
252
253    #[help(mir_transform_unused_variable_args_in_macro)]
254    NoSugg {
255        #[primary_span]
256        span: Span,
257        name: Symbol,
258    },
259}
260
261pub(crate) struct UnusedVariableStringInterp {
262    pub lit: Span,
263}
264
265impl Subdiagnostic for UnusedVariableStringInterp {
266    fn add_to_diag<G: EmissionGuarantee>(self, diag: &mut Diag<'_, G>) {
267        diag.span_label(
268            self.lit,
269            crate::fluent_generated::mir_transform_maybe_string_interpolation,
270        );
271        diag.multipart_suggestion(
272            crate::fluent_generated::mir_transform_string_interpolation_only_works,
273            <[_]>::into_vec(::alloc::boxed::box_new([(self.lit.shrink_to_lo(),
                    String::from("format!(")),
                (self.lit.shrink_to_hi(), String::from(")"))]))vec![
274                (self.lit.shrink_to_lo(), String::from("format!(")),
275                (self.lit.shrink_to_hi(), String::from(")")),
276            ],
277            Applicability::MachineApplicable,
278        );
279    }
280}
281
282#[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));
                        diag.store_args();
                        diag.arg("code", __binding_1);
                        diag.arg("item_name", __binding_2);
                        diag.arg("kind", __binding_3);
                        let __message =
                            diag.eagerly_translate(crate::fluent_generated::mir_transform_unused_variable_typo);
                        diag.multipart_suggestion_with_style(__message, suggestions,
                            rustc_errors::Applicability::MaybeIncorrect,
                            rustc_errors::SuggestionStyle::ShowAlways);
                        diag.restore_args();
                    }
                }
            }
        }
    };Subdiagnostic)]
283#[multipart_suggestion(
284    mir_transform_unused_variable_typo,
285    style = "verbose",
286    applicability = "maybe-incorrect"
287)]
288pub(crate) struct PatternTypo {
289    #[suggestion_part(code = "{code}")]
290    pub span: Span,
291    pub code: String,
292    pub item_name: Symbol,
293    pub kind: &'static str,
294}
295
296pub(crate) struct MustNotSupend<'a, 'tcx> {
297    pub tcx: TyCtxt<'tcx>,
298    pub yield_sp: Span,
299    pub reason: Option<MustNotSuspendReason>,
300    pub src_sp: Span,
301    pub pre: &'a str,
302    pub def_id: DefId,
303    pub post: &'a str,
304}
305
306// Needed for def_path_str
307impl<'a> LintDiagnostic<'a, ()> for MustNotSupend<'_, '_> {
308    fn decorate_lint<'b>(self, diag: &'b mut rustc_errors::Diag<'a, ()>) {
309        diag.primary_message(fluent::mir_transform_must_not_suspend);
310        diag.span_label(self.yield_sp, fluent::_subdiag::label);
311        if let Some(reason) = self.reason {
312            diag.subdiagnostic(reason);
313        }
314        diag.span_help(self.src_sp, fluent::_subdiag::help);
315        diag.arg("pre", self.pre);
316        diag.arg("def_path", self.tcx.def_path_str(self.def_id));
317        diag.arg("post", self.post);
318    }
319}
320
321#[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 } => {
                        diag.store_args();
                        diag.arg("reason", __binding_1);
                        let __message =
                            diag.eagerly_translate(crate::fluent_generated::mir_transform_note);
                        diag.span_note(__binding_0, __message);
                        diag.restore_args();
                    }
                }
            }
        }
    };Subdiagnostic)]
322#[note(mir_transform_note)]
323pub(crate) struct MustNotSuspendReason {
324    #[primary_span]
325    pub span: Span,
326    pub reason: Symbol,
327}
328
329#[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,
                                crate::fluent_generated::mir_transform_force_inline);
                        diag.note(crate::fluent_generated::_subdiag::note);
                        ;
                        diag.arg("callee", __binding_4);
                        diag.arg("caller", __binding_5);
                        diag.arg("reason", __binding_6);
                        diag.span_label(__binding_0,
                            crate::fluent_generated::mir_transform_caller);
                        diag.span_label(__binding_1,
                            crate::fluent_generated::mir_transform_callee);
                        diag.span_label(__binding_2,
                            crate::fluent_generated::mir_transform_attr);
                        diag.span(__binding_3);
                        diag.span_label(__binding_3,
                            crate::fluent_generated::mir_transform_call);
                        if let Some(__binding_7) = __binding_7 {
                            diag.subdiagnostic(__binding_7);
                        }
                        diag
                    }
                }
            }
        }
    };Diagnostic)]
330#[diag(mir_transform_force_inline)]
331#[note]
332pub(crate) struct ForceInlineFailure {
333    #[label(mir_transform_caller)]
334    pub caller_span: Span,
335    #[label(mir_transform_callee)]
336    pub callee_span: Span,
337    #[label(mir_transform_attr)]
338    pub attr_span: Span,
339    #[primary_span]
340    #[label(mir_transform_call)]
341    pub call_span: Span,
342    pub callee: String,
343    pub caller: String,
344    pub reason: &'static str,
345    #[subdiagnostic]
346    pub justification: Option<ForceInlineJustification>,
347}
348
349#[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 } => {
                        diag.store_args();
                        diag.arg("sym", __binding_0);
                        let __message =
                            diag.eagerly_translate(crate::fluent_generated::mir_transform_force_inline_justification);
                        diag.note(__message);
                        diag.restore_args();
                    }
                }
            }
        }
    };Subdiagnostic)]
350#[note(mir_transform_force_inline_justification)]
351pub(crate) struct ForceInlineJustification {
352    pub sym: Symbol,
353}