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 ->\n    [const] constant\n    [static] static\n    [const_fn] constant function\n    *[other] {\"\"}\n}s")));
                        ;
                        diag.arg("kind", __binding_1);
                        diag.span(__binding_0);
                        diag
                    }
                }
            }
        }
    };Diagnostic)]
142#[diag(
143    r#"function pointer calls are not allowed in {$kind ->
144    [const] constant
145    [static] static
146    [const_fn] constant function
147    *[other] {""}
148}s"#
149)]
150pub(crate) struct UnallowedFnPointerCall {
151    #[primary_span]
152    pub span: Span,
153    pub kind: ConstContext,
154}
155
156#[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)]
157#[diag("`{$def_path}` is not yet stable as a const fn")]
158pub(crate) struct UnstableConstFn {
159    #[primary_span]
160    pub span: Span,
161    pub def_path: String,
162}
163
164#[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)]
165#[diag("`{$def_path}` is not yet stable as a const trait")]
166pub(crate) struct UnstableConstTrait {
167    #[primary_span]
168    pub span: Span,
169    pub def_path: String,
170}
171
172#[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)]
173#[diag("`{$name}` is not yet stable as a const intrinsic")]
174pub(crate) struct UnstableIntrinsic {
175    #[primary_span]
176    pub span: Span,
177    pub name: Symbol,
178    pub feature: Symbol,
179    #[suggestion(
180        "add `#![feature({$feature})]` to the crate attributes to enable",
181        code = "#![feature({feature})]\n",
182        applicability = "machine-applicable"
183    )]
184    pub suggestion: Span,
185}
186
187#[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)]
188#[diag("`{$def_path}` cannot be (indirectly) exposed to stable")]
189#[help(
190    "either mark the callee as `#[rustc_const_stable_indirect]`, or the caller as `#[rustc_const_unstable]`"
191)]
192pub(crate) struct UnmarkedConstItemExposed {
193    #[primary_span]
194    pub span: Span,
195    pub def_path: String,
196}
197
198#[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)]
199#[diag("intrinsic `{$def_path}` cannot be (indirectly) exposed to stable")]
200#[help(
201    "mark the caller as `#[rustc_const_unstable]`, or mark the intrinsic `#[rustc_intrinsic_const_stable_indirect]` (but this requires team approval)"
202)]
203pub(crate) struct UnmarkedIntrinsicExposed {
204    #[primary_span]
205    pub span: Span,
206    pub def_path: String,
207}
208
209#[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)]
210#[diag("mutable borrows of temporaries that have their lifetime extended until the end of the program are not allowed", code = E0764)]
211#[note(
212    "temporaries in constants and statics can have their lifetime extended until the end of the program"
213)]
214#[note("to avoid accidentally creating global mutable state, such temporaries must be immutable")]
215#[help(
216    "if you really want global mutable state, try replacing the temporary by an interior mutable `static` or a `static mut`"
217)]
218pub(crate) struct MutableBorrowEscaping {
219    #[primary_span]
220    #[label("this mutable borrow refers to such a temporary")]
221    pub span: Span,
222    pub kind: ConstContext,
223}
224
225#[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 ->\n    [const] constant\n    [static] static\n    [const_fn] constant function\n    *[other] {\"\"}\n}s")));
                        diag.code(E0015);
                        ;
                        diag.arg("kind", __binding_1);
                        diag.arg("non_or_conditionally", __binding_2);
                        diag.span(__binding_0);
                        diag
                    }
                }
            }
        }
    };Diagnostic)]
226#[diag(
227    r#"cannot call {$non_or_conditionally}-const formatting macro in {$kind ->
228    [const] constant
229    [static] static
230    [const_fn] constant function
231    *[other] {""}
232}s"#,
233    code = E0015,
234)]
235pub(crate) struct NonConstFmtMacroCall {
236    #[primary_span]
237    pub span: Span,
238    pub kind: ConstContext,
239    pub non_or_conditionally: &'static str,
240}
241
242#[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 ->\n    [const] constant\n    [static] static\n    [const_fn] constant function\n    *[other] {\"\"}\n}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)]
243#[diag(r#"cannot call {$non_or_conditionally}-const {$def_descr} `{$def_path_str}` in {$kind ->
244    [const] constant
245    [static] static
246    [const_fn] constant function
247    *[other] {""}
248}s"#, code = E0015)]
249pub(crate) struct NonConstFnCall {
250    #[primary_span]
251    pub span: Span,
252    pub def_path_str: String,
253    pub def_descr: &'static str,
254    pub kind: ConstContext,
255    pub non_or_conditionally: &'static str,
256}
257
258#[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 ->\n    [const] constant\n    [static] static\n    [const_fn] constant function\n    *[other] {\"\"}\n}s")));
                        ;
                        diag.arg("name", __binding_1);
                        diag.arg("kind", __binding_2);
                        diag.span(__binding_0);
                        diag
                    }
                }
            }
        }
    };Diagnostic)]
259#[diag(
260    r#"cannot call non-const intrinsic `{$name}` in {$kind ->
261    [const] constant
262    [static] static
263    [const_fn] constant function
264    *[other] {""}
265}s"#
266)]
267pub(crate) struct NonConstIntrinsic {
268    #[primary_span]
269    pub span: Span,
270    pub name: Symbol,
271    pub kind: ConstContext,
272}
273
274#[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)]
275#[diag("{$msg}")]
276pub(crate) struct UnallowedOpInConstContext {
277    #[primary_span]
278    pub span: Span,
279    pub msg: String,
280}
281
282#[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 ->\n    [const] constant\n    [static] static\n    [const_fn] constant function\n    *[other] {\"\"}\n}s")));
                        diag.code(E0015);
                        ;
                        diag.arg("kind", __binding_1);
                        diag.span(__binding_0);
                        diag
                    }
                }
            }
        }
    };Diagnostic)]
283#[diag(r#"inline assembly is not allowed in {$kind ->
284    [const] constant
285    [static] static
286    [const_fn] constant function
287    *[other] {""}
288}s"#, code = E0015)]
289pub(crate) struct UnallowedInlineAsm {
290    #[primary_span]
291    pub span: Span,
292    pub kind: ConstContext,
293}
294
295#[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)]
296#[diag("interior mutable shared borrows of temporaries that have their lifetime extended until the end of the program are not allowed", code = E0492)]
297#[note(
298    "temporaries in constants and statics can have their lifetime extended until the end of the program"
299)]
300#[note("to avoid accidentally creating global mutable state, such temporaries must be immutable")]
301#[help(
302    "if you really want global mutable state, try replacing the temporary by an interior mutable `static` or a `static mut`"
303)]
304pub(crate) struct InteriorMutableBorrowEscaping {
305    #[primary_span]
306    #[label("this borrow of an interior mutable value refers to such a temporary")]
307    pub span: Span,
308    pub kind: ConstContext,
309}
310
311#[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)]
312#[diag("constant evaluation is taking a long time")]
313#[note(
314    "this lint makes sure the compiler doesn't get stuck due to infinite loops in const eval.
315    If your compilation actually takes a long time, you can safely allow the lint"
316)]
317pub struct LongRunning {
318    #[help("the constant being evaluated")]
319    pub item_span: Span,
320}
321
322#[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)]
323#[diag("constant evaluation is taking a long time")]
324pub struct LongRunningWarn {
325    #[primary_span]
326    #[label("the const evaluator is currently interpreting this expression")]
327    pub span: Span,
328    #[help("the constant being evaluated")]
329    pub item_span: Span,
330    // Used for evading `-Z deduplicate-diagnostics`.
331    pub force_duplicate: usize,
332}
333
334#[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)]
335#[note("impl defined here, but it is not `const`")]
336pub(crate) struct NonConstImplNote {
337    #[primary_span]
338    pub span: Span,
339}
340
341#[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)]
342pub struct FrameNote {
343    pub span: Span,
344    pub times: i32,
345    pub where_: &'static str,
346    pub instance: String,
347    pub has_label: bool,
348}
349
350impl Subdiagnostic for FrameNote {
351    fn add_to_diag<G: EmissionGuarantee>(self, diag: &mut Diag<'_, G>) {
352        let mut span: MultiSpan = self.span.into();
353        if self.has_label && !self.span.is_dummy() {
354            span.push_span_label(self.span, rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("the failure occurred here"))msg!("the failure occurred here"));
355        }
356        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!(
357            r#"{$times ->
358                [0] inside {$where_ ->
359                    [closure] closure
360                    [instance] `{$instance}`
361                    *[other] {""}
362                }
363                *[other] [... {$times} additional calls inside {$where_ ->
364                    [closure] closure
365                    [instance] `{$instance}`
366                    *[other] {""}
367                } ...]
368            }"#
369        )
370        .arg("times", self.times)
371        .arg("where_", self.where_)
372        .arg("instance", self.instance)
373        .format();
374        diag.span_note(span, msg);
375    }
376}
377
378#[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)]
379#[note(r#"the raw bytes of the constant (size: {$size}, align: {$align}) {"{"}{$bytes}{"}"}"#)]
380pub struct RawBytesNote {
381    pub size: u64,
382    pub align: u64,
383    pub bytes: String,
384}
385
386#[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 ->\n    [const] constant\n    [static] static\n    [const_fn] constant function\n    *[other] {\"\"}\n}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)]
387#[diag(
388    r#"cannot match on `{$ty}` in {$kind ->
389    [const] constant
390    [static] static
391    [const_fn] constant function
392    *[other] {""}
393}s"#
394)]
395#[note("`{$ty}` cannot be compared in compile-time, and therefore cannot be used in `match`es")]
396pub struct NonConstMatchEq<'tcx> {
397    #[primary_span]
398    pub span: Span,
399    pub ty: Ty<'tcx>,
400    pub kind: ConstContext,
401    pub non_or_conditionally: &'static str,
402}
403
404#[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 ->\n    [const] constant\n    [static] static\n    [const_fn] constant function\n    *[other] {\"\"}\n}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)]
405#[diag(r#"cannot use `for` loop on `{$ty}` in {$kind ->
406    [const] constant
407    [static] static
408    [const_fn] constant function
409    *[other] {""}
410}s"#, code = E0015)]
411pub struct NonConstForLoopIntoIter<'tcx> {
412    #[primary_span]
413    pub span: Span,
414    pub ty: Ty<'tcx>,
415    pub kind: ConstContext,
416    pub non_or_conditionally: &'static str,
417}
418
419#[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 ->\n    [const] constant\n    [static] static\n    [const_fn] constant function\n    *[other] {\"\"}\n}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)]
420#[diag(r#"`?` is not allowed on `{$ty}` in {$kind ->
421    [const] constant
422    [static] static
423    [const_fn] constant function
424    *[other] {""}
425}s"#, code = E0015)]
426pub struct NonConstQuestionBranch<'tcx> {
427    #[primary_span]
428    pub span: Span,
429    pub ty: Ty<'tcx>,
430    pub kind: ConstContext,
431    pub non_or_conditionally: &'static str,
432}
433
434#[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 ->\n    [const] constant\n    [static] static\n    [const_fn] constant function\n    *[other] {\"\"}\n}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)]
435#[diag(r#"`?` is not allowed on `{$ty}` in {$kind ->
436    [const] constant
437    [static] static
438    [const_fn] constant function
439    *[other] {""}
440}s"#, code = E0015)]
441pub struct NonConstQuestionFromResidual<'tcx> {
442    #[primary_span]
443    pub span: Span,
444    pub ty: Ty<'tcx>,
445    pub kind: ConstContext,
446    pub non_or_conditionally: &'static str,
447}
448
449#[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 ->\n    [const] constant\n    [static] static\n    [const_fn] constant function\n    *[other] {\"\"}\n}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)]
450#[diag(r#"`try` block cannot convert `{$ty}` to the result in {$kind ->
451    [const] constant
452    [static] static
453    [const_fn] constant function
454    *[other] {""}
455}s"#, code = E0015)]
456pub struct NonConstTryBlockFromOutput<'tcx> {
457    #[primary_span]
458    pub span: Span,
459    pub ty: Ty<'tcx>,
460    pub kind: ConstContext,
461    pub non_or_conditionally: &'static str,
462}
463
464#[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 ->\n    [const] constant\n    [static] static\n    [const_fn] constant function\n    *[other] {\"\"}\n}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)]
465#[diag(r#"cannot convert `{$ty}` into a future in {$kind ->
466    [const] constant
467    [static] static
468    [const_fn] constant function
469    *[other] {""}
470}s"#, code = E0015)]
471pub struct NonConstAwait<'tcx> {
472    #[primary_span]
473    pub span: Span,
474    pub ty: Ty<'tcx>,
475    pub kind: ConstContext,
476    pub non_or_conditionally: &'static str,
477}
478
479#[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 ->\n    [const] constant\n    [static] static\n    [const_fn] constant function\n    *[other] {\"\"}\n}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)]
480#[diag(r#"cannot call {$non_or_conditionally}-const closure in {$kind ->
481    [const] constant
482    [static] static
483    [const_fn] constant function
484    *[other] {""}
485}s"#, code = E0015)]
486pub struct NonConstClosure {
487    #[primary_span]
488    pub span: Span,
489    pub kind: ConstContext,
490    #[subdiagnostic]
491    pub note: Option<NonConstClosureNote>,
492    pub non_or_conditionally: &'static str,
493}
494
495#[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 ->\n    [const] constant\n    [static] static\n    [const_fn] constant function\n    *[other] {\"\"}\n}s")));
                        diag.code(E0015);
                        ;
                        diag.arg("kind", __binding_1);
                        diag.span(__binding_0);
                        diag
                    }
                }
            }
        }
    };Diagnostic)]
496#[diag(r#"calling const c-variadic functions is unstable in {$kind ->
497    [const] constant
498    [static] static
499    [const_fn] constant function
500    *[other] {""}
501}s"#, code = E0015)]
502pub struct NonConstCVariadicCall {
503    #[primary_span]
504    pub span: Span,
505    pub kind: ConstContext,
506}
507
508#[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 ->\n            [const] constant\n            [static] static\n            [const_fn] constant function\n            *[other] {\"\"}\n        }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 ->\n            [const] constant\n            [static] static\n            [const_fn] constant function\n            *[other] {\"\"}\n        }s")),
                                &sub_args);
                        diag.note(__message);
                    }
                }
            }
        }
    };Subdiagnostic)]
509pub enum NonConstClosureNote {
510    #[note("function defined here, but it is not `const`")]
511    FnDef {
512        #[primary_span]
513        span: Span,
514    },
515    #[note(
516        r#"function pointers need an RFC before allowed to be called in {$kind ->
517            [const] constant
518            [static] static
519            [const_fn] constant function
520            *[other] {""}
521        }s"#
522    )]
523    FnPtr { kind: ConstContext },
524    #[note(
525        r#"closures need an RFC before allowed to be called in {$kind ->
526            [const] constant
527            [static] static
528            [const_fn] constant function
529            *[other] {""}
530        }s"#
531    )]
532    Closure { kind: ConstContext },
533}
534
535#[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)]
536#[multipart_suggestion("consider dereferencing here", applicability = "machine-applicable")]
537pub struct ConsiderDereferencing {
538    pub deref: String,
539    #[suggestion_part(code = "{deref}")]
540    pub span: Span,
541    #[suggestion_part(code = "{deref}")]
542    pub rhs_span: Span,
543}
544
545#[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 ->\n    [const] constant\n    [static] static\n    [const_fn] constant function\n    *[other] {\"\"}\n}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)]
546#[diag(r#"cannot call {$non_or_conditionally}-const operator in {$kind ->
547    [const] constant
548    [static] static
549    [const_fn] constant function
550    *[other] {""}
551}s"#, code = E0015)]
552pub struct NonConstOperator {
553    #[primary_span]
554    pub span: Span,
555    pub kind: ConstContext,
556    #[subdiagnostic]
557    pub sugg: Option<ConsiderDereferencing>,
558    pub non_or_conditionally: &'static str,
559}
560
561#[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 ->\n    [const] constant\n    [static] static\n    [const_fn] constant function\n    *[other] {\"\"}\n}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)]
562#[diag(r#"cannot perform {$non_or_conditionally}-const deref coercion on `{$ty}` in {$kind ->
563    [const] constant
564    [static] static
565    [const_fn] constant function
566    *[other] {""}
567}s"#, code = E0015)]
568#[note("attempting to deref into `{$target_ty}`")]
569pub struct NonConstDerefCoercion<'tcx> {
570    #[primary_span]
571    pub span: Span,
572    pub ty: Ty<'tcx>,
573    pub kind: ConstContext,
574    pub target_ty: Ty<'tcx>,
575    #[note("deref defined here")]
576    pub deref_target: Option<Span>,
577    pub non_or_conditionally: &'static str,
578}
579
580#[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 ->\n            [const] constant\n            [static] static\n            [const_fn] constant function\n            *[other] {\"\"}\n        }s")));
                        diag.span_label(__binding_3,
                            rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("value is dropped here")));
                        diag
                    }
                }
            }
        }
    };Diagnostic)]
581#[diag("destructor of `{$dropped_ty}` cannot be evaluated at compile-time", code = E0493)]
582pub struct LiveDrop<'tcx> {
583    #[primary_span]
584    #[label(
585        r#"the destructor for this type cannot be evaluated in {$kind ->
586            [const] constant
587            [static] static
588            [const_fn] constant function
589            *[other] {""}
590        }s"#
591    )]
592    pub span: Span,
593    pub kind: ConstContext,
594    pub dropped_ty: Ty<'tcx>,
595    #[label("value is dropped here")]
596    pub dropped_at: Span,
597}
598
599impl rustc_errors::IntoDiagArg for InternKind {
600    fn into_diag_arg(self, _: &mut Option<std::path::PathBuf>) -> DiagArgValue {
601        DiagArgValue::Str(Cow::Borrowed(match self {
602            InternKind::Static(Mutability::Not) => "static",
603            InternKind::Static(Mutability::Mut) => "static_mut",
604            InternKind::Constant => "const",
605            InternKind::Promoted => "promoted",
606        }))
607    }
608}