Skip to main content

rustc_const_eval/
errors.rs

1use std::borrow::Cow;
2
3use rustc_errors::codes::*;
4use rustc_errors::formatting::DiagMessageAddArg;
5use rustc_errors::{Diag, DiagArgValue, EmissionGuarantee, MultiSpan, Subdiagnostic, msg};
6use rustc_hir::ConstContext;
7use rustc_macros::{Diagnostic, Subdiagnostic};
8use rustc_middle::ty::{Mutability, Ty};
9use rustc_span::{Span, Symbol};
10
11use crate::interpret::InternKind;
12
13#[derive(const _: () =
    {
        impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for
            DanglingPtrInFinal 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 {
                    DanglingPtrInFinal { span: __binding_0, kind: __binding_1 }
                        => {
                        let mut diag =
                            rustc_errors::Diag::new(dcx, level,
                                rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("encountered dangling pointer in final value of {$kind ->\n    [static] static\n    [static_mut] mutable static\n    [const] constant\n    [promoted] promoted\n    *[other] {\"\"}\n}")));
                        ;
                        diag.arg("kind", __binding_1);
                        diag.span(__binding_0);
                        diag
                    }
                }
            }
        }
    };Diagnostic)]
14#[diag(
15    r#"encountered dangling pointer in final value of {$kind ->
16    [static] static
17    [static_mut] mutable static
18    [const] constant
19    [promoted] promoted
20    *[other] {""}
21}"#
22)]
23pub(crate) struct DanglingPtrInFinal {
24    #[primary_span]
25    pub span: Span,
26    pub kind: InternKind,
27}
28
29#[derive(const _: () =
    {
        impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for
            NestedStaticInThreadLocal 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 {
                    NestedStaticInThreadLocal { span: __binding_0 } => {
                        let mut diag =
                            rustc_errors::Diag::new(dcx, level,
                                rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("#[thread_local] does not support implicit nested statics, please create explicit static items and refer to them instead")));
                        ;
                        diag.span(__binding_0);
                        diag
                    }
                }
            }
        }
    };Diagnostic)]
30#[diag(
31    "#[thread_local] does not support implicit nested statics, please create explicit static items and refer to them instead"
32)]
33pub(crate) struct NestedStaticInThreadLocal {
34    #[primary_span]
35    pub span: Span,
36}
37
38#[derive(const _: () =
    {
        impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for
            MutablePtrInFinal 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 {
                    MutablePtrInFinal { span: __binding_0, kind: __binding_1 }
                        => {
                        let mut diag =
                            rustc_errors::Diag::new(dcx, level,
                                rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("encountered mutable pointer in final value of {$kind ->\n    [static] static\n    [static_mut] mutable static\n    [const] constant\n    [promoted] promoted\n    *[other] {\"\"}\n}")));
                        ;
                        diag.arg("kind", __binding_1);
                        diag.span(__binding_0);
                        diag
                    }
                }
            }
        }
    };Diagnostic)]
39#[diag(
40    r#"encountered mutable pointer in final value of {$kind ->
41    [static] static
42    [static_mut] mutable static
43    [const] constant
44    [promoted] promoted
45    *[other] {""}
46}"#
47)]
48pub(crate) struct MutablePtrInFinal {
49    #[primary_span]
50    pub span: Span,
51    pub kind: InternKind,
52}
53
54#[derive(const _: () =
    {
        impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for
            ConstHeapPtrInFinal 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 {
                    ConstHeapPtrInFinal { span: __binding_0 } => {
                        let mut diag =
                            rustc_errors::Diag::new(dcx, level,
                                rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("encountered `const_allocate` pointer in final value that was not made global")));
                        diag.note(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("use `const_make_global` to turn allocated pointers into immutable globals before returning")));
                        ;
                        diag.span(__binding_0);
                        diag
                    }
                }
            }
        }
    };Diagnostic)]
55#[diag("encountered `const_allocate` pointer in final value that was not made global")]
56#[note(
57    "use `const_make_global` to turn allocated pointers into immutable globals before returning"
58)]
59pub(crate) struct ConstHeapPtrInFinal {
60    #[primary_span]
61    pub span: Span,
62}
63
64#[derive(const _: () =
    {
        impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for
            PartialPtrInFinal 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 {
                    PartialPtrInFinal { span: __binding_0, kind: __binding_1 }
                        => {
                        let mut diag =
                            rustc_errors::Diag::new(dcx, level,
                                rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("encountered partial pointer in final value of {$kind ->\n    [static] static\n    [static_mut] mutable static\n    [const] constant\n    [promoted] promoted\n    *[other] {\"\"}\n}")));
                        diag.note(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("while pointers can be broken apart into individual bytes during const-evaluation, only complete pointers (with all their bytes in the right order) are supported in the final value")));
                        ;
                        diag.arg("kind", __binding_1);
                        diag.span(__binding_0);
                        diag
                    }
                }
            }
        }
    };Diagnostic)]
65#[diag(
66    r#"encountered partial pointer in final value of {$kind ->
67    [static] static
68    [static_mut] mutable static
69    [const] constant
70    [promoted] promoted
71    *[other] {""}
72}"#
73)]
74#[note(
75    "while pointers can be broken apart into individual bytes during const-evaluation, only complete pointers (with all their bytes in the right order) are supported in the final value"
76)]
77pub(crate) struct PartialPtrInFinal {
78    #[primary_span]
79    pub span: Span,
80    pub kind: InternKind,
81}
82
83#[derive(const _: () =
    {
        impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for
            UnstableInStableExposed 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 {
                    UnstableInStableExposed {
                        gate: __binding_0,
                        span: __binding_1,
                        is_function_call: __binding_2,
                        is_function_call2: __binding_3,
                        attr_span: __binding_4 } => {
                        let mut diag =
                            rustc_errors::Diag::new(dcx, level,
                                rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("const function that might be (indirectly) exposed to stable cannot use `#[feature({$gate})]`")));
                        let __code_0 =
                            [::alloc::__export::must_use({
                                                ::alloc::fmt::format(format_args!("#[rustc_const_unstable(feature = \"...\", issue = \"...\")]\n"))
                                            })].into_iter();
                        ;
                        diag.arg("gate", __binding_0);
                        diag.arg("is_function_call2", __binding_3);
                        diag.span(__binding_1);
                        if __binding_2 {
                            diag.help(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("mark the callee as `#[rustc_const_stable_indirect]` if it does not itself require any unstable features")));
                        }
                        diag.span_suggestions_with_style(__binding_4,
                            rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("if the {$is_function_call2 ->\n            [true] caller\n            *[false] function\n        } is not (yet) meant to be exposed to stable const contexts, add `#[rustc_const_unstable]`")),
                            __code_0, rustc_errors::Applicability::HasPlaceholders,
                            rustc_errors::SuggestionStyle::ShowCode);
                        diag
                    }
                }
            }
        }
    };Diagnostic)]
84#[diag(
85    "const function that might be (indirectly) exposed to stable cannot use `#[feature({$gate})]`"
86)]
87pub(crate) struct UnstableInStableExposed {
88    pub gate: String,
89    #[primary_span]
90    pub span: Span,
91    #[help(
92        "mark the callee as `#[rustc_const_stable_indirect]` if it does not itself require any unstable features"
93    )]
94    pub is_function_call: bool,
95    /// Need to duplicate the field so that fluent also provides it as a variable...
96    pub is_function_call2: bool,
97    #[suggestion(
98        "if the {$is_function_call2 ->
99            [true] caller
100            *[false] function
101        } is not (yet) meant to be exposed to stable const contexts, add `#[rustc_const_unstable]`",
102        code = "#[rustc_const_unstable(feature = \"...\", issue = \"...\")]\n",
103        applicability = "has-placeholders"
104    )]
105    pub attr_span: Span,
106}
107
108#[derive(const _: () =
    {
        impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for
            ThreadLocalAccessErr 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 {
                    ThreadLocalAccessErr { span: __binding_0 } => {
                        let mut diag =
                            rustc_errors::Diag::new(dcx, level,
                                rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("thread-local statics cannot be accessed at compile-time")));
                        diag.code(E0625);
                        ;
                        diag.span(__binding_0);
                        diag
                    }
                }
            }
        }
    };Diagnostic)]
109#[diag("thread-local statics cannot be accessed at compile-time", code = E0625)]
110pub(crate) struct ThreadLocalAccessErr {
111    #[primary_span]
112    pub span: Span,
113}
114
115#[derive(const _: () =
    {
        impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for RawPtrToIntErr
            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 {
                    RawPtrToIntErr { span: __binding_0 } => {
                        let mut diag =
                            rustc_errors::Diag::new(dcx, level,
                                rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("pointers cannot be cast to integers during const eval")));
                        diag.note(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("at compile-time, pointers do not have an integer value")));
                        diag.note(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("avoiding this restriction via `transmute`, `union`, or raw pointers leads to compile-time undefined behavior")));
                        ;
                        diag.span(__binding_0);
                        diag
                    }
                }
            }
        }
    };Diagnostic)]
116#[diag("pointers cannot be cast to integers during const eval")]
117#[note("at compile-time, pointers do not have an integer value")]
118#[note(
119    "avoiding this restriction via `transmute`, `union`, or raw pointers leads to compile-time undefined behavior"
120)]
121pub(crate) struct RawPtrToIntErr {
122    #[primary_span]
123    pub span: Span,
124}
125
126#[derive(const _: () =
    {
        impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for
            RawPtrComparisonErr 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 {
                    RawPtrComparisonErr { span: __binding_0 } => {
                        let mut diag =
                            rustc_errors::Diag::new(dcx, level,
                                rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("pointers cannot be reliably compared during const eval")));
                        diag.note(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("see issue #53020 <https://github.com/rust-lang/rust/issues/53020> for more information")));
                        ;
                        diag.span(__binding_0);
                        diag
                    }
                }
            }
        }
    };Diagnostic)]
127#[diag("pointers cannot be reliably compared during const eval")]
128#[note("see issue #53020 <https://github.com/rust-lang/rust/issues/53020> for more information")]
129pub(crate) struct RawPtrComparisonErr {
130    #[primary_span]
131    pub span: Span,
132}
133
134#[derive(const _: () =
    {
        impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for PanicNonStrErr
            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 {
                    PanicNonStrErr { span: __binding_0 } => {
                        let mut diag =
                            rustc_errors::Diag::new(dcx, level,
                                rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("argument to `panic!()` in a const context must have type `&str`")));
                        ;
                        diag.span(__binding_0);
                        diag
                    }
                }
            }
        }
    };Diagnostic)]
135#[diag("argument to `panic!()` in a const context must have type `&str`")]
136pub(crate) struct PanicNonStrErr {
137    #[primary_span]
138    pub span: Span,
139}
140
141#[derive(const _: () =
    {
        impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for
            UnallowedFnPointerCall 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 {
                    UnallowedFnPointerCall {
                        span: __binding_0, kind: __binding_1 } => {
                        let mut diag =
                            rustc_errors::Diag::new(dcx, level,
                                rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("function pointer calls are not allowed in {$kind}s")));
                        ;
                        diag.arg("kind", __binding_1);
                        diag.span(__binding_0);
                        diag
                    }
                }
            }
        }
    };Diagnostic)]
142#[diag(r#"function pointer calls are not allowed in {$kind}s"#)]
143pub(crate) struct UnallowedFnPointerCall {
144    #[primary_span]
145    pub span: Span,
146    pub kind: ConstContext,
147}
148
149#[derive(const _: () =
    {
        impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for
            UnstableConstFn 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 {
                    UnstableConstFn { span: __binding_0, def_path: __binding_1 }
                        => {
                        let mut diag =
                            rustc_errors::Diag::new(dcx, level,
                                rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("`{$def_path}` is not yet stable as a const fn")));
                        ;
                        diag.arg("def_path", __binding_1);
                        diag.span(__binding_0);
                        diag
                    }
                }
            }
        }
    };Diagnostic)]
150#[diag("`{$def_path}` is not yet stable as a const fn")]
151pub(crate) struct UnstableConstFn {
152    #[primary_span]
153    pub span: Span,
154    pub def_path: String,
155}
156
157#[derive(const _: () =
    {
        impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for
            UnstableConstTrait 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 {
                    UnstableConstTrait {
                        span: __binding_0, def_path: __binding_1 } => {
                        let mut diag =
                            rustc_errors::Diag::new(dcx, level,
                                rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("`{$def_path}` is not yet stable as a const trait")));
                        ;
                        diag.arg("def_path", __binding_1);
                        diag.span(__binding_0);
                        diag
                    }
                }
            }
        }
    };Diagnostic)]
158#[diag("`{$def_path}` is not yet stable as a const trait")]
159pub(crate) struct UnstableConstTrait {
160    #[primary_span]
161    pub span: Span,
162    pub def_path: String,
163}
164
165#[derive(const _: () =
    {
        impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for
            UnstableIntrinsic 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 {
                    UnstableIntrinsic {
                        span: __binding_0,
                        name: __binding_1,
                        feature: __binding_2,
                        suggestion: __binding_3 } => {
                        let mut diag =
                            rustc_errors::Diag::new(dcx, level,
                                rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("`{$name}` is not yet stable as a const intrinsic")));
                        let __code_1 =
                            [::alloc::__export::must_use({
                                                ::alloc::fmt::format(format_args!("#![feature({0})]\n",
                                                        __binding_2))
                                            })].into_iter();
                        ;
                        diag.arg("name", __binding_1);
                        diag.arg("feature", __binding_2);
                        diag.span(__binding_0);
                        diag.span_suggestions_with_style(__binding_3,
                            rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("add `#![feature({$feature})]` to the crate attributes to enable")),
                            __code_1, rustc_errors::Applicability::MachineApplicable,
                            rustc_errors::SuggestionStyle::ShowCode);
                        diag
                    }
                }
            }
        }
    };Diagnostic)]
166#[diag("`{$name}` is not yet stable as a const intrinsic")]
167pub(crate) struct UnstableIntrinsic {
168    #[primary_span]
169    pub span: Span,
170    pub name: Symbol,
171    pub feature: Symbol,
172    #[suggestion(
173        "add `#![feature({$feature})]` to the crate attributes to enable",
174        code = "#![feature({feature})]\n",
175        applicability = "machine-applicable"
176    )]
177    pub suggestion: Span,
178}
179
180#[derive(const _: () =
    {
        impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for
            UnmarkedConstItemExposed 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 {
                    UnmarkedConstItemExposed {
                        span: __binding_0, def_path: __binding_1 } => {
                        let mut diag =
                            rustc_errors::Diag::new(dcx, level,
                                rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("`{$def_path}` cannot be (indirectly) exposed to stable")));
                        diag.help(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("either mark the callee as `#[rustc_const_stable_indirect]`, or the caller as `#[rustc_const_unstable]`")));
                        ;
                        diag.arg("def_path", __binding_1);
                        diag.span(__binding_0);
                        diag
                    }
                }
            }
        }
    };Diagnostic)]
181#[diag("`{$def_path}` cannot be (indirectly) exposed to stable")]
182#[help(
183    "either mark the callee as `#[rustc_const_stable_indirect]`, or the caller as `#[rustc_const_unstable]`"
184)]
185pub(crate) struct UnmarkedConstItemExposed {
186    #[primary_span]
187    pub span: Span,
188    pub def_path: String,
189}
190
191#[derive(const _: () =
    {
        impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for
            UnmarkedIntrinsicExposed 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 {
                    UnmarkedIntrinsicExposed {
                        span: __binding_0, def_path: __binding_1 } => {
                        let mut diag =
                            rustc_errors::Diag::new(dcx, level,
                                rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("intrinsic `{$def_path}` cannot be (indirectly) exposed to stable")));
                        diag.help(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("mark the caller as `#[rustc_const_unstable]`, or mark the intrinsic `#[rustc_intrinsic_const_stable_indirect]` (but this requires team approval)")));
                        ;
                        diag.arg("def_path", __binding_1);
                        diag.span(__binding_0);
                        diag
                    }
                }
            }
        }
    };Diagnostic)]
192#[diag("intrinsic `{$def_path}` cannot be (indirectly) exposed to stable")]
193#[help(
194    "mark the caller as `#[rustc_const_unstable]`, or mark the intrinsic `#[rustc_intrinsic_const_stable_indirect]` (but this requires team approval)"
195)]
196pub(crate) struct UnmarkedIntrinsicExposed {
197    #[primary_span]
198    pub span: Span,
199    pub def_path: String,
200}
201
202#[derive(const _: () =
    {
        impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for
            MutableBorrowEscaping 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 {
                    MutableBorrowEscaping { span: __binding_0, kind: __binding_1
                        } => {
                        let mut diag =
                            rustc_errors::Diag::new(dcx, level,
                                rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("mutable borrows of temporaries that have their lifetime extended until the end of the program are not allowed")));
                        diag.code(E0764);
                        diag.note(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("temporaries in constants and statics can have their lifetime extended until the end of the program")));
                        diag.note(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("to avoid accidentally creating global mutable state, such temporaries must be immutable")));
                        diag.help(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("if you really want global mutable state, try replacing the temporary by an interior mutable `static` or a `static mut`")));
                        ;
                        diag.arg("kind", __binding_1);
                        diag.span(__binding_0);
                        diag.span_label(__binding_0,
                            rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("this mutable borrow refers to such a temporary")));
                        diag
                    }
                }
            }
        }
    };Diagnostic)]
203#[diag("mutable borrows of temporaries that have their lifetime extended until the end of the program are not allowed", code = E0764)]
204#[note(
205    "temporaries in constants and statics can have their lifetime extended until the end of the program"
206)]
207#[note("to avoid accidentally creating global mutable state, such temporaries must be immutable")]
208#[help(
209    "if you really want global mutable state, try replacing the temporary by an interior mutable `static` or a `static mut`"
210)]
211pub(crate) struct MutableBorrowEscaping {
212    #[primary_span]
213    #[label("this mutable borrow refers to such a temporary")]
214    pub span: Span,
215    pub kind: ConstContext,
216}
217
218#[derive(const _: () =
    {
        impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for
            NonConstFmtMacroCall 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 {
                    NonConstFmtMacroCall {
                        span: __binding_0,
                        kind: __binding_1,
                        non_or_conditionally: __binding_2 } => {
                        let mut diag =
                            rustc_errors::Diag::new(dcx, level,
                                rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("cannot call {$non_or_conditionally}-const formatting macro in {$kind}s")));
                        diag.code(E0015);
                        ;
                        diag.arg("kind", __binding_1);
                        diag.arg("non_or_conditionally", __binding_2);
                        diag.span(__binding_0);
                        diag
                    }
                }
            }
        }
    };Diagnostic)]
219#[diag(
220    r#"cannot call {$non_or_conditionally}-const formatting macro in {$kind}s"#,
221    code = E0015,
222)]
223pub(crate) struct NonConstFmtMacroCall {
224    #[primary_span]
225    pub span: Span,
226    pub kind: ConstContext,
227    pub non_or_conditionally: &'static str,
228}
229
230#[derive(const _: () =
    {
        impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for NonConstFnCall
            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 {
                    NonConstFnCall {
                        span: __binding_0,
                        def_path_str: __binding_1,
                        def_descr: __binding_2,
                        kind: __binding_3,
                        non_or_conditionally: __binding_4 } => {
                        let mut diag =
                            rustc_errors::Diag::new(dcx, level,
                                rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("cannot call {$non_or_conditionally}-const {$def_descr} `{$def_path_str}` in {$kind}s")));
                        diag.code(E0015);
                        ;
                        diag.arg("def_path_str", __binding_1);
                        diag.arg("def_descr", __binding_2);
                        diag.arg("kind", __binding_3);
                        diag.arg("non_or_conditionally", __binding_4);
                        diag.span(__binding_0);
                        diag
                    }
                }
            }
        }
    };Diagnostic)]
231#[diag(r#"cannot call {$non_or_conditionally}-const {$def_descr} `{$def_path_str}` in {$kind}s"#, code = E0015)]
232pub(crate) struct NonConstFnCall {
233    #[primary_span]
234    pub span: Span,
235    pub def_path_str: String,
236    pub def_descr: &'static str,
237    pub kind: ConstContext,
238    pub non_or_conditionally: &'static str,
239}
240
241#[derive(const _: () =
    {
        impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for
            NonConstIntrinsic 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 {
                    NonConstIntrinsic {
                        span: __binding_0, name: __binding_1, kind: __binding_2 } =>
                        {
                        let mut diag =
                            rustc_errors::Diag::new(dcx, level,
                                rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("cannot call non-const intrinsic `{$name}` in {$kind}s")));
                        ;
                        diag.arg("name", __binding_1);
                        diag.arg("kind", __binding_2);
                        diag.span(__binding_0);
                        diag
                    }
                }
            }
        }
    };Diagnostic)]
242#[diag(r#"cannot call non-const intrinsic `{$name}` in {$kind}s"#)]
243pub(crate) struct NonConstIntrinsic {
244    #[primary_span]
245    pub span: Span,
246    pub name: Symbol,
247    pub kind: ConstContext,
248}
249
250#[derive(const _: () =
    {
        impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for
            UnallowedOpInConstContext 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 {
                    UnallowedOpInConstContext {
                        span: __binding_0, msg: __binding_1 } => {
                        let mut diag =
                            rustc_errors::Diag::new(dcx, level,
                                rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("{$msg}")));
                        ;
                        diag.arg("msg", __binding_1);
                        diag.span(__binding_0);
                        diag
                    }
                }
            }
        }
    };Diagnostic)]
251#[diag("{$msg}")]
252pub(crate) struct UnallowedOpInConstContext {
253    #[primary_span]
254    pub span: Span,
255    pub msg: String,
256}
257
258#[derive(const _: () =
    {
        impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for
            UnallowedInlineAsm 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 {
                    UnallowedInlineAsm { span: __binding_0, kind: __binding_1 }
                        => {
                        let mut diag =
                            rustc_errors::Diag::new(dcx, level,
                                rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("inline assembly is not allowed in {$kind}s")));
                        diag.code(E0015);
                        ;
                        diag.arg("kind", __binding_1);
                        diag.span(__binding_0);
                        diag
                    }
                }
            }
        }
    };Diagnostic)]
259#[diag(r#"inline assembly is not allowed in {$kind}s"#, code = E0015)]
260pub(crate) struct UnallowedInlineAsm {
261    #[primary_span]
262    pub span: Span,
263    pub kind: ConstContext,
264}
265
266#[derive(const _: () =
    {
        impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for
            InteriorMutableBorrowEscaping 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 {
                    InteriorMutableBorrowEscaping {
                        span: __binding_0, kind: __binding_1 } => {
                        let mut diag =
                            rustc_errors::Diag::new(dcx, level,
                                rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("interior mutable shared borrows of temporaries that have their lifetime extended until the end of the program are not allowed")));
                        diag.code(E0492);
                        diag.note(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("temporaries in constants and statics can have their lifetime extended until the end of the program")));
                        diag.note(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("to avoid accidentally creating global mutable state, such temporaries must be immutable")));
                        diag.help(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("if you really want global mutable state, try replacing the temporary by an interior mutable `static` or a `static mut`")));
                        ;
                        diag.arg("kind", __binding_1);
                        diag.span(__binding_0);
                        diag.span_label(__binding_0,
                            rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("this borrow of an interior mutable value refers to such a temporary")));
                        diag
                    }
                }
            }
        }
    };Diagnostic)]
267#[diag("interior mutable shared borrows of temporaries that have their lifetime extended until the end of the program are not allowed", code = E0492)]
268#[note(
269    "temporaries in constants and statics can have their lifetime extended until the end of the program"
270)]
271#[note("to avoid accidentally creating global mutable state, such temporaries must be immutable")]
272#[help(
273    "if you really want global mutable state, try replacing the temporary by an interior mutable `static` or a `static mut`"
274)]
275pub(crate) struct InteriorMutableBorrowEscaping {
276    #[primary_span]
277    #[label("this borrow of an interior mutable value refers to such a temporary")]
278    pub span: Span,
279    pub kind: ConstContext,
280}
281
282#[derive(const _: () =
    {
        impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for LongRunning
            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 {
                    LongRunning { item_span: __binding_0 } => {
                        let mut diag =
                            rustc_errors::Diag::new(dcx, level,
                                rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("constant evaluation is taking a long time")));
                        diag.note(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("this lint makes sure the compiler doesn't get stuck due to infinite loops in const eval.\n    If your compilation actually takes a long time, you can safely allow the lint")));
                        ;
                        diag.span_help(__binding_0,
                            rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("the constant being evaluated")));
                        diag
                    }
                }
            }
        }
    };Diagnostic)]
283#[diag("constant evaluation is taking a long time")]
284#[note(
285    "this lint makes sure the compiler doesn't get stuck due to infinite loops in const eval.
286    If your compilation actually takes a long time, you can safely allow the lint"
287)]
288pub(crate) struct LongRunning {
289    #[help("the constant being evaluated")]
290    pub item_span: Span,
291}
292
293#[derive(const _: () =
    {
        impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for
            LongRunningWarn 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 {
                    LongRunningWarn {
                        span: __binding_0,
                        item_span: __binding_1,
                        force_duplicate: __binding_2 } => {
                        let mut diag =
                            rustc_errors::Diag::new(dcx, level,
                                rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("constant evaluation is taking a long time")));
                        ;
                        diag.arg("force_duplicate", __binding_2);
                        diag.span(__binding_0);
                        diag.span_label(__binding_0,
                            rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("the const evaluator is currently interpreting this expression")));
                        diag.span_help(__binding_1,
                            rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("the constant being evaluated")));
                        diag
                    }
                }
            }
        }
    };Diagnostic)]
294#[diag("constant evaluation is taking a long time")]
295pub(crate) struct LongRunningWarn {
296    #[primary_span]
297    #[label("the const evaluator is currently interpreting this expression")]
298    pub span: Span,
299    #[help("the constant being evaluated")]
300    pub item_span: Span,
301    // Used for evading `-Z deduplicate-diagnostics`.
302    pub force_duplicate: usize,
303}
304
305#[derive(const _: () =
    {
        impl rustc_errors::Subdiagnostic for NonConstImplNote {
            fn add_to_diag<__G>(self, diag: &mut rustc_errors::Diag<'_, __G>)
                where __G: rustc_errors::EmissionGuarantee {
                match self {
                    NonConstImplNote { span: __binding_0 } => {
                        let mut sub_args = rustc_errors::DiagArgMap::default();
                        let __message =
                            rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("impl defined here, but it is not `const`")),
                                &sub_args);
                        diag.span_note(__binding_0, __message);
                    }
                }
            }
        }
    };Subdiagnostic)]
306#[note("impl defined here, but it is not `const`")]
307pub(crate) struct NonConstImplNote {
308    #[primary_span]
309    pub span: Span,
310}
311
312#[derive(#[automatically_derived]
impl ::core::clone::Clone for FrameNote {
    #[inline]
    fn clone(&self) -> FrameNote {
        FrameNote {
            span: ::core::clone::Clone::clone(&self.span),
            times: ::core::clone::Clone::clone(&self.times),
            where_: ::core::clone::Clone::clone(&self.where_),
            instance: ::core::clone::Clone::clone(&self.instance),
            has_label: ::core::clone::Clone::clone(&self.has_label),
        }
    }
}Clone)]
313pub(crate) struct FrameNote {
314    pub span: Span,
315    pub times: i32,
316    pub where_: &'static str,
317    pub instance: String,
318    pub has_label: bool,
319}
320
321impl Subdiagnostic for FrameNote {
322    fn add_to_diag<G: EmissionGuarantee>(self, diag: &mut Diag<'_, G>) {
323        let mut span: MultiSpan = self.span.into();
324        if self.has_label && !self.span.is_dummy() {
325            span.push_span_label(self.span, rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("the failure occurred here"))msg!("the failure occurred here"));
326        }
327        let msg = rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("{$times ->\n                [0] inside {$where_ ->\n                    [closure] closure\n                    [instance] `{$instance}`\n                    *[other] {\"\"}\n                }\n                *[other] [... {$times} additional calls inside {$where_ ->\n                    [closure] closure\n                    [instance] `{$instance}`\n                    *[other] {\"\"}\n                } ...]\n            }"))msg!(
328            r#"{$times ->
329                [0] inside {$where_ ->
330                    [closure] closure
331                    [instance] `{$instance}`
332                    *[other] {""}
333                }
334                *[other] [... {$times} additional calls inside {$where_ ->
335                    [closure] closure
336                    [instance] `{$instance}`
337                    *[other] {""}
338                } ...]
339            }"#
340        )
341        .arg("times", self.times)
342        .arg("where_", self.where_)
343        .arg("instance", self.instance)
344        .format();
345        diag.span_note(span, msg);
346    }
347}
348
349#[derive(const _: () =
    {
        impl rustc_errors::Subdiagnostic for RawBytesNote {
            fn add_to_diag<__G>(self, diag: &mut rustc_errors::Diag<'_, __G>)
                where __G: rustc_errors::EmissionGuarantee {
                match self {
                    RawBytesNote {
                        size: __binding_0, align: __binding_1, bytes: __binding_2 }
                        => {
                        let mut sub_args = rustc_errors::DiagArgMap::default();
                        sub_args.insert("size".into(),
                            rustc_errors::IntoDiagArg::into_diag_arg(__binding_0,
                                &mut diag.long_ty_path));
                        sub_args.insert("align".into(),
                            rustc_errors::IntoDiagArg::into_diag_arg(__binding_1,
                                &mut diag.long_ty_path));
                        sub_args.insert("bytes".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("the raw bytes of the constant (size: {$size}, align: {$align}) {\"{\"}{$bytes}{\"}\"}")),
                                &sub_args);
                        diag.note(__message);
                    }
                }
            }
        }
    };Subdiagnostic)]
350#[note(r#"the raw bytes of the constant (size: {$size}, align: {$align}) {"{"}{$bytes}{"}"}"#)]
351pub(crate) struct RawBytesNote {
352    pub size: u64,
353    pub align: u64,
354    pub bytes: String,
355}
356
357#[derive(const _: () =
    {
        impl<'_sess, 'tcx, G> rustc_errors::Diagnostic<'_sess, G> for
            NonConstMatchEq<'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 {
                    NonConstMatchEq {
                        span: __binding_0,
                        ty: __binding_1,
                        kind: __binding_2,
                        non_or_conditionally: __binding_3 } => {
                        let mut diag =
                            rustc_errors::Diag::new(dcx, level,
                                rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("cannot match on `{$ty}` in {$kind}s")));
                        diag.note(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("`{$ty}` cannot be compared in compile-time, and therefore cannot be used in `match`es")));
                        ;
                        diag.arg("ty", __binding_1);
                        diag.arg("kind", __binding_2);
                        diag.arg("non_or_conditionally", __binding_3);
                        diag.span(__binding_0);
                        diag
                    }
                }
            }
        }
    };Diagnostic)]
358#[diag(r#"cannot match on `{$ty}` in {$kind}s"#)]
359#[note("`{$ty}` cannot be compared in compile-time, and therefore cannot be used in `match`es")]
360pub(crate) struct NonConstMatchEq<'tcx> {
361    #[primary_span]
362    pub span: Span,
363    pub ty: Ty<'tcx>,
364    pub kind: ConstContext,
365    pub non_or_conditionally: &'static str,
366}
367
368#[derive(const _: () =
    {
        impl<'_sess, 'tcx, G> rustc_errors::Diagnostic<'_sess, G> for
            NonConstForLoopIntoIter<'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 {
                    NonConstForLoopIntoIter {
                        span: __binding_0,
                        ty: __binding_1,
                        kind: __binding_2,
                        non_or_conditionally: __binding_3 } => {
                        let mut diag =
                            rustc_errors::Diag::new(dcx, level,
                                rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("cannot use `for` loop on `{$ty}` in {$kind}s")));
                        diag.code(E0015);
                        ;
                        diag.arg("ty", __binding_1);
                        diag.arg("kind", __binding_2);
                        diag.arg("non_or_conditionally", __binding_3);
                        diag.span(__binding_0);
                        diag
                    }
                }
            }
        }
    };Diagnostic)]
369#[diag(r#"cannot use `for` loop on `{$ty}` in {$kind}s"#, code = E0015)]
370pub(crate) struct NonConstForLoopIntoIter<'tcx> {
371    #[primary_span]
372    pub span: Span,
373    pub ty: Ty<'tcx>,
374    pub kind: ConstContext,
375    pub non_or_conditionally: &'static str,
376}
377
378#[derive(const _: () =
    {
        impl<'_sess, 'tcx, G> rustc_errors::Diagnostic<'_sess, G> for
            NonConstQuestionBranch<'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 {
                    NonConstQuestionBranch {
                        span: __binding_0,
                        ty: __binding_1,
                        kind: __binding_2,
                        non_or_conditionally: __binding_3 } => {
                        let mut diag =
                            rustc_errors::Diag::new(dcx, level,
                                rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("`?` is not allowed on `{$ty}` in {$kind}s")));
                        diag.code(E0015);
                        ;
                        diag.arg("ty", __binding_1);
                        diag.arg("kind", __binding_2);
                        diag.arg("non_or_conditionally", __binding_3);
                        diag.span(__binding_0);
                        diag
                    }
                }
            }
        }
    };Diagnostic)]
379#[diag(r#"`?` is not allowed on `{$ty}` in {$kind}s"#, code = E0015)]
380pub(crate) struct NonConstQuestionBranch<'tcx> {
381    #[primary_span]
382    pub span: Span,
383    pub ty: Ty<'tcx>,
384    pub kind: ConstContext,
385    pub non_or_conditionally: &'static str,
386}
387
388#[derive(const _: () =
    {
        impl<'_sess, 'tcx, G> rustc_errors::Diagnostic<'_sess, G> for
            NonConstQuestionFromResidual<'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 {
                    NonConstQuestionFromResidual {
                        span: __binding_0,
                        ty: __binding_1,
                        kind: __binding_2,
                        non_or_conditionally: __binding_3 } => {
                        let mut diag =
                            rustc_errors::Diag::new(dcx, level,
                                rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("`?` is not allowed on `{$ty}` in {$kind}s")));
                        diag.code(E0015);
                        ;
                        diag.arg("ty", __binding_1);
                        diag.arg("kind", __binding_2);
                        diag.arg("non_or_conditionally", __binding_3);
                        diag.span(__binding_0);
                        diag
                    }
                }
            }
        }
    };Diagnostic)]
389#[diag(r#"`?` is not allowed on `{$ty}` in {$kind}s"#, code = E0015)]
390pub(crate) struct NonConstQuestionFromResidual<'tcx> {
391    #[primary_span]
392    pub span: Span,
393    pub ty: Ty<'tcx>,
394    pub kind: ConstContext,
395    pub non_or_conditionally: &'static str,
396}
397
398#[derive(const _: () =
    {
        impl<'_sess, 'tcx, G> rustc_errors::Diagnostic<'_sess, G> for
            NonConstTryBlockFromOutput<'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 {
                    NonConstTryBlockFromOutput {
                        span: __binding_0,
                        ty: __binding_1,
                        kind: __binding_2,
                        non_or_conditionally: __binding_3 } => {
                        let mut diag =
                            rustc_errors::Diag::new(dcx, level,
                                rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("`try` block cannot convert `{$ty}` to the result in {$kind}s")));
                        diag.code(E0015);
                        ;
                        diag.arg("ty", __binding_1);
                        diag.arg("kind", __binding_2);
                        diag.arg("non_or_conditionally", __binding_3);
                        diag.span(__binding_0);
                        diag
                    }
                }
            }
        }
    };Diagnostic)]
399#[diag(r#"`try` block cannot convert `{$ty}` to the result in {$kind}s"#, code = E0015)]
400pub(crate) struct NonConstTryBlockFromOutput<'tcx> {
401    #[primary_span]
402    pub span: Span,
403    pub ty: Ty<'tcx>,
404    pub kind: ConstContext,
405    pub non_or_conditionally: &'static str,
406}
407
408#[derive(const _: () =
    {
        impl<'_sess, 'tcx, G> rustc_errors::Diagnostic<'_sess, G> for
            NonConstAwait<'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 {
                    NonConstAwait {
                        span: __binding_0,
                        ty: __binding_1,
                        kind: __binding_2,
                        non_or_conditionally: __binding_3 } => {
                        let mut diag =
                            rustc_errors::Diag::new(dcx, level,
                                rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("cannot convert `{$ty}` into a future in {$kind}s")));
                        diag.code(E0015);
                        ;
                        diag.arg("ty", __binding_1);
                        diag.arg("kind", __binding_2);
                        diag.arg("non_or_conditionally", __binding_3);
                        diag.span(__binding_0);
                        diag
                    }
                }
            }
        }
    };Diagnostic)]
409#[diag(r#"cannot convert `{$ty}` into a future in {$kind}s"#, code = E0015)]
410pub(crate) struct NonConstAwait<'tcx> {
411    #[primary_span]
412    pub span: Span,
413    pub ty: Ty<'tcx>,
414    pub kind: ConstContext,
415    pub non_or_conditionally: &'static str,
416}
417
418#[derive(const _: () =
    {
        impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for
            NonConstClosure 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 {
                    NonConstClosure {
                        span: __binding_0,
                        kind: __binding_1,
                        note: __binding_2,
                        non_or_conditionally: __binding_3 } => {
                        let mut diag =
                            rustc_errors::Diag::new(dcx, level,
                                rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("cannot call {$non_or_conditionally}-const closure in {$kind}s")));
                        diag.code(E0015);
                        ;
                        diag.arg("kind", __binding_1);
                        diag.arg("non_or_conditionally", __binding_3);
                        diag.span(__binding_0);
                        if let Some(__binding_2) = __binding_2 {
                            diag.subdiagnostic(__binding_2);
                        }
                        diag
                    }
                }
            }
        }
    };Diagnostic)]
419#[diag(r#"cannot call {$non_or_conditionally}-const closure in {$kind}s"#, code = E0015)]
420pub(crate) struct NonConstClosure {
421    #[primary_span]
422    pub span: Span,
423    pub kind: ConstContext,
424    #[subdiagnostic]
425    pub note: Option<NonConstClosureNote>,
426    pub non_or_conditionally: &'static str,
427}
428
429#[derive(const _: () =
    {
        impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for
            NonConstCVariadicCall 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 {
                    NonConstCVariadicCall { span: __binding_0, kind: __binding_1
                        } => {
                        let mut diag =
                            rustc_errors::Diag::new(dcx, level,
                                rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("calling const c-variadic functions is unstable in {$kind}s")));
                        diag.code(E0015);
                        ;
                        diag.arg("kind", __binding_1);
                        diag.span(__binding_0);
                        diag
                    }
                }
            }
        }
    };Diagnostic)]
430#[diag(r#"calling const c-variadic functions is unstable in {$kind}s"#, code = E0015)]
431pub(crate) struct NonConstCVariadicCall {
432    #[primary_span]
433    pub span: Span,
434    pub kind: ConstContext,
435}
436
437#[derive(const _: () =
    {
        impl rustc_errors::Subdiagnostic for NonConstClosureNote {
            fn add_to_diag<__G>(self, diag: &mut rustc_errors::Diag<'_, __G>)
                where __G: rustc_errors::EmissionGuarantee {
                match self {
                    NonConstClosureNote::FnDef { span: __binding_0 } => {
                        let mut sub_args = rustc_errors::DiagArgMap::default();
                        let __message =
                            rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("function defined here, but it is not `const`")),
                                &sub_args);
                        diag.span_note(__binding_0, __message);
                    }
                    NonConstClosureNote::FnPtr { kind: __binding_0 } => {
                        let mut sub_args = rustc_errors::DiagArgMap::default();
                        sub_args.insert("kind".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("function pointers need an RFC before allowed to be called in {$kind}s")),
                                &sub_args);
                        diag.note(__message);
                    }
                    NonConstClosureNote::Closure { kind: __binding_0 } => {
                        let mut sub_args = rustc_errors::DiagArgMap::default();
                        sub_args.insert("kind".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("closures need an RFC before allowed to be called in {$kind}s")),
                                &sub_args);
                        diag.note(__message);
                    }
                }
            }
        }
    };Subdiagnostic)]
438pub(crate) enum NonConstClosureNote {
439    #[note("function defined here, but it is not `const`")]
440    FnDef {
441        #[primary_span]
442        span: Span,
443    },
444    #[note(r#"function pointers need an RFC before allowed to be called in {$kind}s"#)]
445    FnPtr { kind: ConstContext },
446    #[note(r#"closures need an RFC before allowed to be called in {$kind}s"#)]
447    Closure { kind: ConstContext },
448}
449
450#[derive(const _: () =
    {
        impl rustc_errors::Subdiagnostic for ConsiderDereferencing {
            fn add_to_diag<__G>(self, diag: &mut rustc_errors::Diag<'_, __G>)
                where __G: rustc_errors::EmissionGuarantee {
                match self {
                    ConsiderDereferencing {
                        deref: __binding_0, span: __binding_1, rhs_span: __binding_2
                        } => {
                        let mut suggestions = Vec::new();
                        let __code_2 =
                            ::alloc::__export::must_use({
                                    ::alloc::fmt::format(format_args!("{0}", __binding_0))
                                });
                        let __code_3 =
                            ::alloc::__export::must_use({
                                    ::alloc::fmt::format(format_args!("{0}", __binding_0))
                                });
                        suggestions.push((__binding_1, __code_2));
                        suggestions.push((__binding_2, __code_3));
                        let mut sub_args = rustc_errors::DiagArgMap::default();
                        sub_args.insert("deref".into(),
                            rustc_errors::IntoDiagArg::into_diag_arg(__binding_0,
                                &mut diag.long_ty_path));
                        let __message =
                            rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("consider dereferencing here")),
                                &sub_args);
                        diag.multipart_suggestion_with_style(__message, suggestions,
                            rustc_errors::Applicability::MachineApplicable,
                            rustc_errors::SuggestionStyle::ShowCode);
                    }
                }
            }
        }
    };Subdiagnostic)]
451#[multipart_suggestion("consider dereferencing here", applicability = "machine-applicable")]
452pub(crate) struct ConsiderDereferencing {
453    pub deref: String,
454    #[suggestion_part(code = "{deref}")]
455    pub span: Span,
456    #[suggestion_part(code = "{deref}")]
457    pub rhs_span: Span,
458}
459
460#[derive(const _: () =
    {
        impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for
            NonConstOperator 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 {
                    NonConstOperator {
                        span: __binding_0,
                        kind: __binding_1,
                        sugg: __binding_2,
                        non_or_conditionally: __binding_3 } => {
                        let mut diag =
                            rustc_errors::Diag::new(dcx, level,
                                rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("cannot call {$non_or_conditionally}-const operator in {$kind}s")));
                        diag.code(E0015);
                        ;
                        diag.arg("kind", __binding_1);
                        diag.arg("non_or_conditionally", __binding_3);
                        diag.span(__binding_0);
                        if let Some(__binding_2) = __binding_2 {
                            diag.subdiagnostic(__binding_2);
                        }
                        diag
                    }
                }
            }
        }
    };Diagnostic)]
461#[diag(r#"cannot call {$non_or_conditionally}-const operator in {$kind}s"#, code = E0015)]
462pub(crate) struct NonConstOperator {
463    #[primary_span]
464    pub span: Span,
465    pub kind: ConstContext,
466    #[subdiagnostic]
467    pub sugg: Option<ConsiderDereferencing>,
468    pub non_or_conditionally: &'static str,
469}
470
471#[derive(const _: () =
    {
        impl<'_sess, 'tcx, G> rustc_errors::Diagnostic<'_sess, G> for
            NonConstDerefCoercion<'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 {
                    NonConstDerefCoercion {
                        span: __binding_0,
                        ty: __binding_1,
                        kind: __binding_2,
                        target_ty: __binding_3,
                        deref_target: __binding_4,
                        non_or_conditionally: __binding_5 } => {
                        let mut diag =
                            rustc_errors::Diag::new(dcx, level,
                                rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("cannot perform {$non_or_conditionally}-const deref coercion on `{$ty}` in {$kind}s")));
                        diag.code(E0015);
                        diag.note(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("attempting to deref into `{$target_ty}`")));
                        ;
                        diag.arg("ty", __binding_1);
                        diag.arg("kind", __binding_2);
                        diag.arg("target_ty", __binding_3);
                        diag.arg("non_or_conditionally", __binding_5);
                        diag.span(__binding_0);
                        if let Some(__binding_4) = __binding_4 {
                            diag.span_note(__binding_4,
                                rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("deref defined here")));
                        }
                        diag
                    }
                }
            }
        }
    };Diagnostic)]
472#[diag(r#"cannot perform {$non_or_conditionally}-const deref coercion on `{$ty}` in {$kind}s"#, code = E0015)]
473#[note("attempting to deref into `{$target_ty}`")]
474pub(crate) struct NonConstDerefCoercion<'tcx> {
475    #[primary_span]
476    pub span: Span,
477    pub ty: Ty<'tcx>,
478    pub kind: ConstContext,
479    pub target_ty: Ty<'tcx>,
480    #[note("deref defined here")]
481    pub deref_target: Option<Span>,
482    pub non_or_conditionally: &'static str,
483}
484
485#[derive(const _: () =
    {
        impl<'_sess, 'tcx, G> rustc_errors::Diagnostic<'_sess, G> for
            LiveDrop<'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 {
                    LiveDrop {
                        span: __binding_0,
                        kind: __binding_1,
                        dropped_ty: __binding_2,
                        dropped_at: __binding_3 } => {
                        let mut diag =
                            rustc_errors::Diag::new(dcx, level,
                                rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("destructor of `{$dropped_ty}` cannot be evaluated at compile-time")));
                        diag.code(E0493);
                        ;
                        diag.arg("kind", __binding_1);
                        diag.arg("dropped_ty", __binding_2);
                        diag.span(__binding_0);
                        diag.span_label(__binding_0,
                            rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("the destructor for this type cannot be evaluated in {$kind}s")));
                        diag.span_label(__binding_3,
                            rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("value is dropped here")));
                        diag
                    }
                }
            }
        }
    };Diagnostic)]
486#[diag("destructor of `{$dropped_ty}` cannot be evaluated at compile-time", code = E0493)]
487pub(crate) struct LiveDrop<'tcx> {
488    #[primary_span]
489    #[label(r#"the destructor for this type cannot be evaluated in {$kind}s"#)]
490    pub span: Span,
491    pub kind: ConstContext,
492    pub dropped_ty: Ty<'tcx>,
493    #[label("value is dropped here")]
494    pub dropped_at: Span,
495}
496
497impl rustc_errors::IntoDiagArg for InternKind {
498    fn into_diag_arg(self, _: &mut Option<std::path::PathBuf>) -> DiagArgValue {
499        DiagArgValue::Str(Cow::Borrowed(match self {
500            InternKind::Static(Mutability::Not) => "static",
501            InternKind::Static(Mutability::Mut) => "static_mut",
502            InternKind::Constant => "const",
503            InternKind::Promoted => "promoted",
504        }))
505    }
506}