1use std::borrow::Cow;
2
3use rustc_errors::codes::*;
4use rustc_errors::formatting::DiagMessageAddArg;
5use rustc_errors::{Diag, DiagArgValue, 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> rustc_errors::Diagnostic<'_sess> for DanglingPtrInFinal {
#[track_caller]
fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
level: rustc_errors::Level) -> rustc_errors::Diag<'_sess> {
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> rustc_errors::Diagnostic<'_sess> for
NestedStaticInThreadLocal {
#[track_caller]
fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
level: rustc_errors::Level) -> rustc_errors::Diag<'_sess> {
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> rustc_errors::Diagnostic<'_sess> for MutablePtrInFinal {
#[track_caller]
fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
level: rustc_errors::Level) -> rustc_errors::Diag<'_sess> {
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> rustc_errors::Diagnostic<'_sess> for ConstHeapPtrInFinal
{
#[track_caller]
fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
level: rustc_errors::Level) -> rustc_errors::Diag<'_sess> {
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> rustc_errors::Diagnostic<'_sess> for PartialPtrInFinal {
#[track_caller]
fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
level: rustc_errors::Level) -> rustc_errors::Diag<'_sess> {
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> rustc_errors::Diagnostic<'_sess> for
UnstableInStableExposed {
#[track_caller]
fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
level: rustc_errors::Level) -> rustc_errors::Diag<'_sess> {
match self {
UnstableInStableExposed {
gate: __binding_0,
span: __binding_1,
is_function_call: __binding_2,
is_function_call2: __binding_3,
suggest_const_unstable: __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")));
}
if let Some(__binding_4) = __binding_4 {
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 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 suggest_const_unstable: Option<Span>,
106}
107
108#[derive(const _: () =
{
impl<'_sess> rustc_errors::Diagnostic<'_sess> for ThreadLocalAccessErr
{
#[track_caller]
fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
level: rustc_errors::Level) -> rustc_errors::Diag<'_sess> {
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> rustc_errors::Diagnostic<'_sess> for RawPtrToIntErr {
#[track_caller]
fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
level: rustc_errors::Level) -> rustc_errors::Diag<'_sess> {
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> rustc_errors::Diagnostic<'_sess> for RawPtrComparisonErr
{
#[track_caller]
fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
level: rustc_errors::Level) -> rustc_errors::Diag<'_sess> {
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> rustc_errors::Diagnostic<'_sess> for PanicNonStrErr {
#[track_caller]
fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
level: rustc_errors::Level) -> rustc_errors::Diag<'_sess> {
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> rustc_errors::Diagnostic<'_sess> for
UnallowedFnPointerCall {
#[track_caller]
fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
level: rustc_errors::Level) -> rustc_errors::Diag<'_sess> {
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> rustc_errors::Diagnostic<'_sess> for UnstableConstFn {
#[track_caller]
fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
level: rustc_errors::Level) -> rustc_errors::Diag<'_sess> {
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> rustc_errors::Diagnostic<'_sess> for UnstableConstTrait {
#[track_caller]
fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
level: rustc_errors::Level) -> rustc_errors::Diag<'_sess> {
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> rustc_errors::Diagnostic<'_sess> for UnstableIntrinsic {
#[track_caller]
fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
level: rustc_errors::Level) -> rustc_errors::Diag<'_sess> {
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> rustc_errors::Diagnostic<'_sess> for
UnmarkedConstItemExposed {
#[track_caller]
fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
level: rustc_errors::Level) -> rustc_errors::Diag<'_sess> {
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> rustc_errors::Diagnostic<'_sess> for
UnmarkedIntrinsicExposed {
#[track_caller]
fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
level: rustc_errors::Level) -> rustc_errors::Diag<'_sess> {
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> rustc_errors::Diagnostic<'_sess> for
MutableBorrowEscaping {
#[track_caller]
fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
level: rustc_errors::Level) -> rustc_errors::Diag<'_sess> {
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.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> rustc_errors::Diagnostic<'_sess> for NonConstFmtMacroCall
{
#[track_caller]
fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
level: rustc_errors::Level) -> rustc_errors::Diag<'_sess> {
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> rustc_errors::Diagnostic<'_sess> for NonConstFnCall {
#[track_caller]
fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
level: rustc_errors::Level) -> rustc_errors::Diag<'_sess> {
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> rustc_errors::Diagnostic<'_sess> for NonConstIntrinsic {
#[track_caller]
fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
level: rustc_errors::Level) -> rustc_errors::Diag<'_sess> {
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> rustc_errors::Diagnostic<'_sess> for
UnallowedOpInConstContext {
#[track_caller]
fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
level: rustc_errors::Level) -> rustc_errors::Diag<'_sess> {
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> rustc_errors::Diagnostic<'_sess> for UnallowedInlineAsm {
#[track_caller]
fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
level: rustc_errors::Level) -> rustc_errors::Diag<'_sess> {
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> rustc_errors::Diagnostic<'_sess> for
InteriorMutableBorrowEscaping {
#[track_caller]
fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
level: rustc_errors::Level) -> rustc_errors::Diag<'_sess> {
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.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> rustc_errors::Diagnostic<'_sess> for LongRunning {
#[track_caller]
fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
level: rustc_errors::Level) -> rustc_errors::Diag<'_sess> {
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> rustc_errors::Diagnostic<'_sess> for LongRunningWarn {
#[track_caller]
fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
level: rustc_errors::Level) -> rustc_errors::Diag<'_sess> {
match self {
LongRunningWarn { span: __binding_0, item_span: __binding_1
} => {
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.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}
302
303#[derive(const _: () =
{
impl rustc_errors::Subdiagnostic for NonConstImplNote {
fn add_to_diag(self, diag: &mut rustc_errors::Diag<'_>) {
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)]
304#[note("impl defined here, but it is not `const`")]
305pub(crate) struct NonConstImplNote {
306 #[primary_span]
307 pub span: Span,
308}
309
310#[derive(#[automatically_derived]
impl ::core::clone::Clone for FrameNote {
#[inline]
fn clone(&self) -> Self {
FrameNote {
span: ::core::clone::Clone::clone(&self.span),
span_context: ::core::clone::Clone::clone(&self.span_context),
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)]
311pub(crate) struct FrameNote {
312 pub span: Span,
313 pub span_context: Vec<Span>,
314 pub times: i32,
315 pub where_: &'static str,
316 pub instance: String,
317 pub has_label: bool,
318}
319
320impl Subdiagnostic for FrameNote {
321 fn add_to_diag(self, diag: &mut Diag<'_>) {
322 let mut span: MultiSpan = self.span.into();
323 if self.has_label && !self.span.is_dummy() {
324 span.push_span_label(self.span, rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("the failure occurred here"))msg!("the failure occurred here"));
325 }
326 for sp in &self.span_context {
327 span.push_span_context(*sp);
328 }
329 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!(
330 r#"{$times ->
331 [0] inside {$where_ ->
332 [closure] closure
333 [instance] `{$instance}`
334 *[other] {""}
335 }
336 *[other] [... {$times} additional calls inside {$where_ ->
337 [closure] closure
338 [instance] `{$instance}`
339 *[other] {""}
340 } ...]
341 }"#
342 )
343 .arg("times", self.times)
344 .arg("where_", self.where_)
345 .arg("instance", self.instance)
346 .format();
347 diag.span_note(span, msg);
348 }
349}
350
351#[derive(const _: () =
{
impl rustc_errors::Subdiagnostic for RawBytesNote {
fn add_to_diag(self, diag: &mut rustc_errors::Diag<'_>) {
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)]
352#[note(r#"the raw bytes of the constant (size: {$size}, align: {$align}) {"{"}{$bytes}{"}"}"#)]
353pub(crate) struct RawBytesNote {
354 pub size: u64,
355 pub align: u64,
356 pub bytes: String,
357}
358
359#[derive(const _: () =
{
impl<'_sess, 'tcx> rustc_errors::Diagnostic<'_sess> for
NonConstMatchEq<'tcx> {
#[track_caller]
fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
level: rustc_errors::Level) -> rustc_errors::Diag<'_sess> {
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.span(__binding_0);
diag
}
}
}
}
};Diagnostic)]
360#[diag(r#"cannot match on `{$ty}` in {$kind}s"#)]
361#[note("`{$ty}` cannot be compared in compile-time, and therefore cannot be used in `match`es")]
362pub(crate) struct NonConstMatchEq<'tcx> {
363 #[primary_span]
364 pub span: Span,
365 pub ty: Ty<'tcx>,
366 pub kind: ConstContext,
367 pub non_or_conditionally: &'static str,
368}
369
370#[derive(const _: () =
{
impl<'_sess, 'tcx> rustc_errors::Diagnostic<'_sess> for
NonConstForLoopIntoIter<'tcx> {
#[track_caller]
fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
level: rustc_errors::Level) -> rustc_errors::Diag<'_sess> {
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.span(__binding_0);
diag
}
}
}
}
};Diagnostic)]
371#[diag(r#"cannot use `for` loop on `{$ty}` in {$kind}s"#, code = E0015)]
372pub(crate) struct NonConstForLoopIntoIter<'tcx> {
373 #[primary_span]
374 pub span: Span,
375 pub ty: Ty<'tcx>,
376 pub kind: ConstContext,
377 pub non_or_conditionally: &'static str,
378}
379
380#[derive(const _: () =
{
impl<'_sess, 'tcx> rustc_errors::Diagnostic<'_sess> for
NonConstQuestionBranch<'tcx> {
#[track_caller]
fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
level: rustc_errors::Level) -> rustc_errors::Diag<'_sess> {
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.span(__binding_0);
diag
}
}
}
}
};Diagnostic)]
381#[diag(r#"`?` is not allowed on `{$ty}` in {$kind}s"#, code = E0015)]
382pub(crate) struct NonConstQuestionBranch<'tcx> {
383 #[primary_span]
384 pub span: Span,
385 pub ty: Ty<'tcx>,
386 pub kind: ConstContext,
387 pub non_or_conditionally: &'static str,
388}
389
390#[derive(const _: () =
{
impl<'_sess, 'tcx> rustc_errors::Diagnostic<'_sess> for
NonConstQuestionFromResidual<'tcx> {
#[track_caller]
fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
level: rustc_errors::Level) -> rustc_errors::Diag<'_sess> {
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.span(__binding_0);
diag
}
}
}
}
};Diagnostic)]
391#[diag(r#"`?` is not allowed on `{$ty}` in {$kind}s"#, code = E0015)]
392pub(crate) struct NonConstQuestionFromResidual<'tcx> {
393 #[primary_span]
394 pub span: Span,
395 pub ty: Ty<'tcx>,
396 pub kind: ConstContext,
397 pub non_or_conditionally: &'static str,
398}
399
400#[derive(const _: () =
{
impl<'_sess, 'tcx> rustc_errors::Diagnostic<'_sess> for
NonConstTryBlockFromOutput<'tcx> {
#[track_caller]
fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
level: rustc_errors::Level) -> rustc_errors::Diag<'_sess> {
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.span(__binding_0);
diag
}
}
}
}
};Diagnostic)]
401#[diag(r#"`try` block cannot convert `{$ty}` to the result in {$kind}s"#, code = E0015)]
402pub(crate) struct NonConstTryBlockFromOutput<'tcx> {
403 #[primary_span]
404 pub span: Span,
405 pub ty: Ty<'tcx>,
406 pub kind: ConstContext,
407 pub non_or_conditionally: &'static str,
408}
409
410#[derive(const _: () =
{
impl<'_sess, 'tcx> rustc_errors::Diagnostic<'_sess> for
NonConstAwait<'tcx> {
#[track_caller]
fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
level: rustc_errors::Level) -> rustc_errors::Diag<'_sess> {
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.span(__binding_0);
diag
}
}
}
}
};Diagnostic)]
411#[diag(r#"cannot convert `{$ty}` into a future in {$kind}s"#, code = E0015)]
412pub(crate) struct NonConstAwait<'tcx> {
413 #[primary_span]
414 pub span: Span,
415 pub ty: Ty<'tcx>,
416 pub kind: ConstContext,
417 pub non_or_conditionally: &'static str,
418}
419
420#[derive(const _: () =
{
impl<'_sess> rustc_errors::Diagnostic<'_sess> for NonConstClosure {
#[track_caller]
fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
level: rustc_errors::Level) -> rustc_errors::Diag<'_sess> {
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)]
421#[diag(r#"cannot call {$non_or_conditionally}-const closure in {$kind}s"#, code = E0015)]
422pub(crate) struct NonConstClosure {
423 #[primary_span]
424 pub span: Span,
425 pub kind: ConstContext,
426 #[subdiagnostic]
427 pub note: Option<NonConstClosureNote>,
428 pub non_or_conditionally: &'static str,
429}
430
431#[derive(const _: () =
{
impl<'_sess> rustc_errors::Diagnostic<'_sess> for
NonConstCVariadicCall {
#[track_caller]
fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
level: rustc_errors::Level) -> rustc_errors::Diag<'_sess> {
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)]
432#[diag(r#"calling const c-variadic functions is unstable in {$kind}s"#, code = E0015)]
433pub(crate) struct NonConstCVariadicCall {
434 #[primary_span]
435 pub span: Span,
436 pub kind: ConstContext,
437}
438
439#[derive(const _: () =
{
impl rustc_errors::Subdiagnostic for NonConstClosureNote {
fn add_to_diag(self, diag: &mut rustc_errors::Diag<'_>) {
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)]
440pub(crate) enum NonConstClosureNote {
441 #[note("function defined here, but it is not `const`")]
442 FnDef {
443 #[primary_span]
444 span: Span,
445 },
446 #[note(r#"function pointers need an RFC before allowed to be called in {$kind}s"#)]
447 FnPtr { kind: ConstContext },
448 #[note(r#"closures need an RFC before allowed to be called in {$kind}s"#)]
449 Closure { kind: ConstContext },
450}
451
452#[derive(const _: () =
{
impl rustc_errors::Subdiagnostic for ConsiderDereferencing {
fn add_to_diag(self, diag: &mut rustc_errors::Diag<'_>) {
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();
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)]
453#[multipart_suggestion("consider dereferencing here", applicability = "machine-applicable")]
454pub(crate) struct ConsiderDereferencing {
455 pub deref: String,
456 #[suggestion_part(code = "{deref}")]
457 pub span: Span,
458 #[suggestion_part(code = "{deref}")]
459 pub rhs_span: Span,
460}
461
462#[derive(const _: () =
{
impl<'_sess> rustc_errors::Diagnostic<'_sess> for NonConstOperator {
#[track_caller]
fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
level: rustc_errors::Level) -> rustc_errors::Diag<'_sess> {
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)]
463#[diag(r#"cannot call {$non_or_conditionally}-const operator in {$kind}s"#, code = E0015)]
464pub(crate) struct NonConstOperator {
465 #[primary_span]
466 pub span: Span,
467 pub kind: ConstContext,
468 #[subdiagnostic]
469 pub sugg: Option<ConsiderDereferencing>,
470 pub non_or_conditionally: &'static str,
471}
472
473#[derive(const _: () =
{
impl<'_sess, 'tcx> rustc_errors::Diagnostic<'_sess> for
NonConstDerefCoercion<'tcx> {
#[track_caller]
fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
level: rustc_errors::Level) -> rustc_errors::Diag<'_sess> {
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)]
474#[diag(r#"cannot perform {$non_or_conditionally}-const deref coercion on `{$ty}` in {$kind}s"#, code = E0015)]
475#[note("attempting to deref into `{$target_ty}`")]
476pub(crate) struct NonConstDerefCoercion<'tcx> {
477 #[primary_span]
478 pub span: Span,
479 pub ty: Ty<'tcx>,
480 pub kind: ConstContext,
481 pub target_ty: Ty<'tcx>,
482 #[note("deref defined here")]
483 pub deref_target: Option<Span>,
484 pub non_or_conditionally: &'static str,
485}
486
487#[derive(const _: () =
{
impl<'_sess, 'tcx> rustc_errors::Diagnostic<'_sess> for LiveDrop<'tcx>
{
#[track_caller]
fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
level: rustc_errors::Level) -> rustc_errors::Diag<'_sess> {
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)]
488#[diag("destructor of `{$dropped_ty}` cannot be evaluated at compile-time", code = E0493)]
489pub(crate) struct LiveDrop<'tcx> {
490 #[primary_span]
491 #[label(r#"the destructor for this type cannot be evaluated in {$kind}s"#)]
492 pub span: Span,
493 pub kind: ConstContext,
494 pub dropped_ty: Ty<'tcx>,
495 #[label("value is dropped here")]
496 pub dropped_at: Span,
497}
498
499impl rustc_errors::IntoDiagArg for InternKind {
500 fn into_diag_arg(self, _: &mut Option<std::path::PathBuf>) -> DiagArgValue {
501 DiagArgValue::Str(Cow::Borrowed(match self {
502 InternKind::Static(Mutability::Not) => "static",
503 InternKind::Static(Mutability::Mut) => "static_mut",
504 InternKind::Constant => "const",
505 InternKind::Promoted => "promoted",
506 }))
507 }
508}