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 pub is_function_call2: bool,
97 #[suggestion(
98 "if the {$is_function_call2 ->
99 [true] caller
100 *[false] function
101 } is not (yet) meant to be exposed to stable const contexts, add `#[rustc_const_unstable]`",
102 code = "#[rustc_const_unstable(feature = \"...\", issue = \"...\")]\n",
103 applicability = "has-placeholders"
104 )]
105 pub attr_span: Span,
106}
107
108#[derive(const _: () =
{
impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for
ThreadLocalAccessErr where G: rustc_errors::EmissionGuarantee {
#[track_caller]
fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
level: rustc_errors::Level) -> rustc_errors::Diag<'_sess, G> {
match self {
ThreadLocalAccessErr { span: __binding_0 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("thread-local statics cannot be accessed at compile-time")));
diag.code(E0625);
;
diag.span(__binding_0);
diag
}
}
}
}
};Diagnostic)]
109#[diag("thread-local statics cannot be accessed at compile-time", code = E0625)]
110pub(crate) struct ThreadLocalAccessErr {
111 #[primary_span]
112 pub span: Span,
113}
114
115#[derive(const _: () =
{
impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for RawPtrToIntErr
where G: rustc_errors::EmissionGuarantee {
#[track_caller]
fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
level: rustc_errors::Level) -> rustc_errors::Diag<'_sess, G> {
match self {
RawPtrToIntErr { span: __binding_0 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("pointers cannot be cast to integers during const eval")));
diag.note(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("at compile-time, pointers do not have an integer value")));
diag.note(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("avoiding this restriction via `transmute`, `union`, or raw pointers leads to compile-time undefined behavior")));
;
diag.span(__binding_0);
diag
}
}
}
}
};Diagnostic)]
116#[diag("pointers cannot be cast to integers during const eval")]
117#[note("at compile-time, pointers do not have an integer value")]
118#[note(
119 "avoiding this restriction via `transmute`, `union`, or raw pointers leads to compile-time undefined behavior"
120)]
121pub(crate) struct RawPtrToIntErr {
122 #[primary_span]
123 pub span: Span,
124}
125
126#[derive(const _: () =
{
impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for
RawPtrComparisonErr where G: rustc_errors::EmissionGuarantee {
#[track_caller]
fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
level: rustc_errors::Level) -> rustc_errors::Diag<'_sess, G> {
match self {
RawPtrComparisonErr { span: __binding_0 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("pointers cannot be reliably compared during const eval")));
diag.note(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("see issue #53020 <https://github.com/rust-lang/rust/issues/53020> for more information")));
;
diag.span(__binding_0);
diag
}
}
}
}
};Diagnostic)]
127#[diag("pointers cannot be reliably compared during const eval")]
128#[note("see issue #53020 <https://github.com/rust-lang/rust/issues/53020> for more information")]
129pub(crate) struct RawPtrComparisonErr {
130 #[primary_span]
131 pub span: Span,
132}
133
134#[derive(const _: () =
{
impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for PanicNonStrErr
where G: rustc_errors::EmissionGuarantee {
#[track_caller]
fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
level: rustc_errors::Level) -> rustc_errors::Diag<'_sess, G> {
match self {
PanicNonStrErr { span: __binding_0 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("argument to `panic!()` in a const context must have type `&str`")));
;
diag.span(__binding_0);
diag
}
}
}
}
};Diagnostic)]
135#[diag("argument to `panic!()` in a const context must have type `&str`")]
136pub(crate) struct PanicNonStrErr {
137 #[primary_span]
138 pub span: Span,
139}
140
141#[derive(const _: () =
{
impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for
UnallowedFnPointerCall where G: rustc_errors::EmissionGuarantee {
#[track_caller]
fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
level: rustc_errors::Level) -> rustc_errors::Diag<'_sess, G> {
match self {
UnallowedFnPointerCall {
span: __binding_0, kind: __binding_1 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("function pointer calls are not allowed in {$kind}s")));
;
diag.arg("kind", __binding_1);
diag.span(__binding_0);
diag
}
}
}
}
};Diagnostic)]
142#[diag(r#"function pointer calls are not allowed in {$kind}s"#)]
143pub(crate) struct UnallowedFnPointerCall {
144 #[primary_span]
145 pub span: Span,
146 pub kind: ConstContext,
147}
148
149#[derive(const _: () =
{
impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for
UnstableConstFn where G: rustc_errors::EmissionGuarantee {
#[track_caller]
fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
level: rustc_errors::Level) -> rustc_errors::Diag<'_sess, G> {
match self {
UnstableConstFn { span: __binding_0, def_path: __binding_1 }
=> {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("`{$def_path}` is not yet stable as a const fn")));
;
diag.arg("def_path", __binding_1);
diag.span(__binding_0);
diag
}
}
}
}
};Diagnostic)]
150#[diag("`{$def_path}` is not yet stable as a const fn")]
151pub(crate) struct UnstableConstFn {
152 #[primary_span]
153 pub span: Span,
154 pub def_path: String,
155}
156
157#[derive(const _: () =
{
impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for
UnstableConstTrait where G: rustc_errors::EmissionGuarantee {
#[track_caller]
fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
level: rustc_errors::Level) -> rustc_errors::Diag<'_sess, G> {
match self {
UnstableConstTrait {
span: __binding_0, def_path: __binding_1 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("`{$def_path}` is not yet stable as a const trait")));
;
diag.arg("def_path", __binding_1);
diag.span(__binding_0);
diag
}
}
}
}
};Diagnostic)]
158#[diag("`{$def_path}` is not yet stable as a const trait")]
159pub(crate) struct UnstableConstTrait {
160 #[primary_span]
161 pub span: Span,
162 pub def_path: String,
163}
164
165#[derive(const _: () =
{
impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for
UnstableIntrinsic where G: rustc_errors::EmissionGuarantee {
#[track_caller]
fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
level: rustc_errors::Level) -> rustc_errors::Diag<'_sess, G> {
match self {
UnstableIntrinsic {
span: __binding_0,
name: __binding_1,
feature: __binding_2,
suggestion: __binding_3 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("`{$name}` is not yet stable as a const intrinsic")));
let __code_1 =
[::alloc::__export::must_use({
::alloc::fmt::format(format_args!("#![feature({0})]\n",
__binding_2))
})].into_iter();
;
diag.arg("name", __binding_1);
diag.arg("feature", __binding_2);
diag.span(__binding_0);
diag.span_suggestions_with_style(__binding_3,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("add `#![feature({$feature})]` to the crate attributes to enable")),
__code_1, rustc_errors::Applicability::MachineApplicable,
rustc_errors::SuggestionStyle::ShowCode);
diag
}
}
}
}
};Diagnostic)]
166#[diag("`{$name}` is not yet stable as a const intrinsic")]
167pub(crate) struct UnstableIntrinsic {
168 #[primary_span]
169 pub span: Span,
170 pub name: Symbol,
171 pub feature: Symbol,
172 #[suggestion(
173 "add `#![feature({$feature})]` to the crate attributes to enable",
174 code = "#![feature({feature})]\n",
175 applicability = "machine-applicable"
176 )]
177 pub suggestion: Span,
178}
179
180#[derive(const _: () =
{
impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for
UnmarkedConstItemExposed where G: rustc_errors::EmissionGuarantee
{
#[track_caller]
fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
level: rustc_errors::Level) -> rustc_errors::Diag<'_sess, G> {
match self {
UnmarkedConstItemExposed {
span: __binding_0, def_path: __binding_1 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("`{$def_path}` cannot be (indirectly) exposed to stable")));
diag.help(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("either mark the callee as `#[rustc_const_stable_indirect]`, or the caller as `#[rustc_const_unstable]`")));
;
diag.arg("def_path", __binding_1);
diag.span(__binding_0);
diag
}
}
}
}
};Diagnostic)]
181#[diag("`{$def_path}` cannot be (indirectly) exposed to stable")]
182#[help(
183 "either mark the callee as `#[rustc_const_stable_indirect]`, or the caller as `#[rustc_const_unstable]`"
184)]
185pub(crate) struct UnmarkedConstItemExposed {
186 #[primary_span]
187 pub span: Span,
188 pub def_path: String,
189}
190
191#[derive(const _: () =
{
impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for
UnmarkedIntrinsicExposed where G: rustc_errors::EmissionGuarantee
{
#[track_caller]
fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
level: rustc_errors::Level) -> rustc_errors::Diag<'_sess, G> {
match self {
UnmarkedIntrinsicExposed {
span: __binding_0, def_path: __binding_1 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("intrinsic `{$def_path}` cannot be (indirectly) exposed to stable")));
diag.help(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("mark the caller as `#[rustc_const_unstable]`, or mark the intrinsic `#[rustc_intrinsic_const_stable_indirect]` (but this requires team approval)")));
;
diag.arg("def_path", __binding_1);
diag.span(__binding_0);
diag
}
}
}
}
};Diagnostic)]
192#[diag("intrinsic `{$def_path}` cannot be (indirectly) exposed to stable")]
193#[help(
194 "mark the caller as `#[rustc_const_unstable]`, or mark the intrinsic `#[rustc_intrinsic_const_stable_indirect]` (but this requires team approval)"
195)]
196pub(crate) struct UnmarkedIntrinsicExposed {
197 #[primary_span]
198 pub span: Span,
199 pub def_path: String,
200}
201
202#[derive(const _: () =
{
impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for
MutableBorrowEscaping where G: rustc_errors::EmissionGuarantee {
#[track_caller]
fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
level: rustc_errors::Level) -> rustc_errors::Diag<'_sess, G> {
match self {
MutableBorrowEscaping { span: __binding_0, kind: __binding_1
} => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("mutable borrows of temporaries that have their lifetime extended until the end of the program are not allowed")));
diag.code(E0764);
diag.note(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("temporaries in constants and statics can have their lifetime extended until the end of the program")));
diag.note(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("to avoid accidentally creating global mutable state, such temporaries must be immutable")));
diag.help(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("if you really want global mutable state, try replacing the temporary by an interior mutable `static` or a `static mut`")));
;
diag.span(__binding_0);
diag.span_label(__binding_0,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("this mutable borrow refers to such a temporary")));
diag
}
}
}
}
};Diagnostic)]
203#[diag("mutable borrows of temporaries that have their lifetime extended until the end of the program are not allowed", code = E0764)]
204#[note(
205 "temporaries in constants and statics can have their lifetime extended until the end of the program"
206)]
207#[note("to avoid accidentally creating global mutable state, such temporaries must be immutable")]
208#[help(
209 "if you really want global mutable state, try replacing the temporary by an interior mutable `static` or a `static mut`"
210)]
211pub(crate) struct MutableBorrowEscaping {
212 #[primary_span]
213 #[label("this mutable borrow refers to such a temporary")]
214 pub span: Span,
215 pub kind: ConstContext,
216}
217
218#[derive(const _: () =
{
impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for
NonConstFmtMacroCall where G: rustc_errors::EmissionGuarantee {
#[track_caller]
fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
level: rustc_errors::Level) -> rustc_errors::Diag<'_sess, G> {
match self {
NonConstFmtMacroCall {
span: __binding_0,
kind: __binding_1,
non_or_conditionally: __binding_2 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("cannot call {$non_or_conditionally}-const formatting macro in {$kind}s")));
diag.code(E0015);
;
diag.arg("kind", __binding_1);
diag.arg("non_or_conditionally", __binding_2);
diag.span(__binding_0);
diag
}
}
}
}
};Diagnostic)]
219#[diag(
220 r#"cannot call {$non_or_conditionally}-const formatting macro in {$kind}s"#,
221 code = E0015,
222)]
223pub(crate) struct NonConstFmtMacroCall {
224 #[primary_span]
225 pub span: Span,
226 pub kind: ConstContext,
227 pub non_or_conditionally: &'static str,
228}
229
230#[derive(const _: () =
{
impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for NonConstFnCall
where G: rustc_errors::EmissionGuarantee {
#[track_caller]
fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
level: rustc_errors::Level) -> rustc_errors::Diag<'_sess, G> {
match self {
NonConstFnCall {
span: __binding_0,
def_path_str: __binding_1,
def_descr: __binding_2,
kind: __binding_3,
non_or_conditionally: __binding_4 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("cannot call {$non_or_conditionally}-const {$def_descr} `{$def_path_str}` in {$kind}s")));
diag.code(E0015);
;
diag.arg("def_path_str", __binding_1);
diag.arg("def_descr", __binding_2);
diag.arg("kind", __binding_3);
diag.arg("non_or_conditionally", __binding_4);
diag.span(__binding_0);
diag
}
}
}
}
};Diagnostic)]
231#[diag(r#"cannot call {$non_or_conditionally}-const {$def_descr} `{$def_path_str}` in {$kind}s"#, code = E0015)]
232pub(crate) struct NonConstFnCall {
233 #[primary_span]
234 pub span: Span,
235 pub def_path_str: String,
236 pub def_descr: &'static str,
237 pub kind: ConstContext,
238 pub non_or_conditionally: &'static str,
239}
240
241#[derive(const _: () =
{
impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for
NonConstIntrinsic where G: rustc_errors::EmissionGuarantee {
#[track_caller]
fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
level: rustc_errors::Level) -> rustc_errors::Diag<'_sess, G> {
match self {
NonConstIntrinsic {
span: __binding_0, name: __binding_1, kind: __binding_2 } =>
{
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("cannot call non-const intrinsic `{$name}` in {$kind}s")));
;
diag.arg("name", __binding_1);
diag.arg("kind", __binding_2);
diag.span(__binding_0);
diag
}
}
}
}
};Diagnostic)]
242#[diag(r#"cannot call non-const intrinsic `{$name}` in {$kind}s"#)]
243pub(crate) struct NonConstIntrinsic {
244 #[primary_span]
245 pub span: Span,
246 pub name: Symbol,
247 pub kind: ConstContext,
248}
249
250#[derive(const _: () =
{
impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for
UnallowedOpInConstContext where G: rustc_errors::EmissionGuarantee
{
#[track_caller]
fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
level: rustc_errors::Level) -> rustc_errors::Diag<'_sess, G> {
match self {
UnallowedOpInConstContext {
span: __binding_0, msg: __binding_1 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("{$msg}")));
;
diag.arg("msg", __binding_1);
diag.span(__binding_0);
diag
}
}
}
}
};Diagnostic)]
251#[diag("{$msg}")]
252pub(crate) struct UnallowedOpInConstContext {
253 #[primary_span]
254 pub span: Span,
255 pub msg: String,
256}
257
258#[derive(const _: () =
{
impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for
UnallowedInlineAsm where G: rustc_errors::EmissionGuarantee {
#[track_caller]
fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
level: rustc_errors::Level) -> rustc_errors::Diag<'_sess, G> {
match self {
UnallowedInlineAsm { span: __binding_0, kind: __binding_1 }
=> {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("inline assembly is not allowed in {$kind}s")));
diag.code(E0015);
;
diag.arg("kind", __binding_1);
diag.span(__binding_0);
diag
}
}
}
}
};Diagnostic)]
259#[diag(r#"inline assembly is not allowed in {$kind}s"#, code = E0015)]
260pub(crate) struct UnallowedInlineAsm {
261 #[primary_span]
262 pub span: Span,
263 pub kind: ConstContext,
264}
265
266#[derive(const _: () =
{
impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for
InteriorMutableBorrowEscaping where
G: rustc_errors::EmissionGuarantee {
#[track_caller]
fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
level: rustc_errors::Level) -> rustc_errors::Diag<'_sess, G> {
match self {
InteriorMutableBorrowEscaping {
span: __binding_0, kind: __binding_1 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("interior mutable shared borrows of temporaries that have their lifetime extended until the end of the program are not allowed")));
diag.code(E0492);
diag.note(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("temporaries in constants and statics can have their lifetime extended until the end of the program")));
diag.note(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("to avoid accidentally creating global mutable state, such temporaries must be immutable")));
diag.help(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("if you really want global mutable state, try replacing the temporary by an interior mutable `static` or a `static mut`")));
;
diag.span(__binding_0);
diag.span_label(__binding_0,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("this borrow of an interior mutable value refers to such a temporary")));
diag
}
}
}
}
};Diagnostic)]
267#[diag("interior mutable shared borrows of temporaries that have their lifetime extended until the end of the program are not allowed", code = E0492)]
268#[note(
269 "temporaries in constants and statics can have their lifetime extended until the end of the program"
270)]
271#[note("to avoid accidentally creating global mutable state, such temporaries must be immutable")]
272#[help(
273 "if you really want global mutable state, try replacing the temporary by an interior mutable `static` or a `static mut`"
274)]
275pub(crate) struct InteriorMutableBorrowEscaping {
276 #[primary_span]
277 #[label("this borrow of an interior mutable value refers to such a temporary")]
278 pub span: Span,
279 pub kind: ConstContext,
280}
281
282#[derive(const _: () =
{
impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for LongRunning
where G: rustc_errors::EmissionGuarantee {
#[track_caller]
fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
level: rustc_errors::Level) -> rustc_errors::Diag<'_sess, G> {
match self {
LongRunning { item_span: __binding_0 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("constant evaluation is taking a long time")));
diag.note(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("this lint makes sure the compiler doesn't get stuck due to infinite loops in const eval.\n If your compilation actually takes a long time, you can safely allow the lint")));
;
diag.span_help(__binding_0,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("the constant being evaluated")));
diag
}
}
}
}
};Diagnostic)]
283#[diag("constant evaluation is taking a long time")]
284#[note(
285 "this lint makes sure the compiler doesn't get stuck due to infinite loops in const eval.
286 If your compilation actually takes a long time, you can safely allow the lint"
287)]
288pub(crate) struct LongRunning {
289 #[help("the constant being evaluated")]
290 pub item_span: Span,
291}
292
293#[derive(const _: () =
{
impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for
LongRunningWarn where G: rustc_errors::EmissionGuarantee {
#[track_caller]
fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
level: rustc_errors::Level) -> rustc_errors::Diag<'_sess, G> {
match self {
LongRunningWarn { span: __binding_0, item_span: __binding_1
} => {
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<__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)]
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) -> 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)]
311pub(crate) struct FrameNote {
312 pub span: Span,
313 pub times: i32,
314 pub where_: &'static str,
315 pub instance: String,
316 pub has_label: bool,
317}
318
319impl Subdiagnostic for FrameNote {
320 fn add_to_diag<G: EmissionGuarantee>(self, diag: &mut Diag<'_, G>) {
321 let mut span: MultiSpan = self.span.into();
322 if self.has_label && !self.span.is_dummy() {
323 span.push_span_label(self.span, rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("the failure occurred here"))msg!("the failure occurred here"));
324 }
325 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!(
326 r#"{$times ->
327 [0] inside {$where_ ->
328 [closure] closure
329 [instance] `{$instance}`
330 *[other] {""}
331 }
332 *[other] [... {$times} additional calls inside {$where_ ->
333 [closure] closure
334 [instance] `{$instance}`
335 *[other] {""}
336 } ...]
337 }"#
338 )
339 .arg("times", self.times)
340 .arg("where_", self.where_)
341 .arg("instance", self.instance)
342 .format();
343 diag.span_note(span, msg);
344 }
345}
346
347#[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)]
348#[note(r#"the raw bytes of the constant (size: {$size}, align: {$align}) {"{"}{$bytes}{"}"}"#)]
349pub(crate) struct RawBytesNote {
350 pub size: u64,
351 pub align: u64,
352 pub bytes: String,
353}
354
355#[derive(const _: () =
{
impl<'_sess, 'tcx, G> rustc_errors::Diagnostic<'_sess, G> for
NonConstMatchEq<'tcx> where G: rustc_errors::EmissionGuarantee {
#[track_caller]
fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
level: rustc_errors::Level) -> rustc_errors::Diag<'_sess, G> {
match self {
NonConstMatchEq {
span: __binding_0,
ty: __binding_1,
kind: __binding_2,
non_or_conditionally: __binding_3 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("cannot match on `{$ty}` in {$kind}s")));
diag.note(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("`{$ty}` cannot be compared in compile-time, and therefore cannot be used in `match`es")));
;
diag.arg("ty", __binding_1);
diag.arg("kind", __binding_2);
diag.span(__binding_0);
diag
}
}
}
}
};Diagnostic)]
356#[diag(r#"cannot match on `{$ty}` in {$kind}s"#)]
357#[note("`{$ty}` cannot be compared in compile-time, and therefore cannot be used in `match`es")]
358pub(crate) struct NonConstMatchEq<'tcx> {
359 #[primary_span]
360 pub span: Span,
361 pub ty: Ty<'tcx>,
362 pub kind: ConstContext,
363 pub non_or_conditionally: &'static str,
364}
365
366#[derive(const _: () =
{
impl<'_sess, 'tcx, G> rustc_errors::Diagnostic<'_sess, G> for
NonConstForLoopIntoIter<'tcx> where
G: rustc_errors::EmissionGuarantee {
#[track_caller]
fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
level: rustc_errors::Level) -> rustc_errors::Diag<'_sess, G> {
match self {
NonConstForLoopIntoIter {
span: __binding_0,
ty: __binding_1,
kind: __binding_2,
non_or_conditionally: __binding_3 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("cannot use `for` loop on `{$ty}` in {$kind}s")));
diag.code(E0015);
;
diag.arg("ty", __binding_1);
diag.arg("kind", __binding_2);
diag.span(__binding_0);
diag
}
}
}
}
};Diagnostic)]
367#[diag(r#"cannot use `for` loop on `{$ty}` in {$kind}s"#, code = E0015)]
368pub(crate) struct NonConstForLoopIntoIter<'tcx> {
369 #[primary_span]
370 pub span: Span,
371 pub ty: Ty<'tcx>,
372 pub kind: ConstContext,
373 pub non_or_conditionally: &'static str,
374}
375
376#[derive(const _: () =
{
impl<'_sess, 'tcx, G> rustc_errors::Diagnostic<'_sess, G> for
NonConstQuestionBranch<'tcx> where
G: rustc_errors::EmissionGuarantee {
#[track_caller]
fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
level: rustc_errors::Level) -> rustc_errors::Diag<'_sess, G> {
match self {
NonConstQuestionBranch {
span: __binding_0,
ty: __binding_1,
kind: __binding_2,
non_or_conditionally: __binding_3 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("`?` is not allowed on `{$ty}` in {$kind}s")));
diag.code(E0015);
;
diag.arg("ty", __binding_1);
diag.arg("kind", __binding_2);
diag.span(__binding_0);
diag
}
}
}
}
};Diagnostic)]
377#[diag(r#"`?` is not allowed on `{$ty}` in {$kind}s"#, code = E0015)]
378pub(crate) struct NonConstQuestionBranch<'tcx> {
379 #[primary_span]
380 pub span: Span,
381 pub ty: Ty<'tcx>,
382 pub kind: ConstContext,
383 pub non_or_conditionally: &'static str,
384}
385
386#[derive(const _: () =
{
impl<'_sess, 'tcx, G> rustc_errors::Diagnostic<'_sess, G> for
NonConstQuestionFromResidual<'tcx> where
G: rustc_errors::EmissionGuarantee {
#[track_caller]
fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
level: rustc_errors::Level) -> rustc_errors::Diag<'_sess, G> {
match self {
NonConstQuestionFromResidual {
span: __binding_0,
ty: __binding_1,
kind: __binding_2,
non_or_conditionally: __binding_3 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("`?` is not allowed on `{$ty}` in {$kind}s")));
diag.code(E0015);
;
diag.arg("ty", __binding_1);
diag.arg("kind", __binding_2);
diag.span(__binding_0);
diag
}
}
}
}
};Diagnostic)]
387#[diag(r#"`?` is not allowed on `{$ty}` in {$kind}s"#, code = E0015)]
388pub(crate) struct NonConstQuestionFromResidual<'tcx> {
389 #[primary_span]
390 pub span: Span,
391 pub ty: Ty<'tcx>,
392 pub kind: ConstContext,
393 pub non_or_conditionally: &'static str,
394}
395
396#[derive(const _: () =
{
impl<'_sess, 'tcx, G> rustc_errors::Diagnostic<'_sess, G> for
NonConstTryBlockFromOutput<'tcx> where
G: rustc_errors::EmissionGuarantee {
#[track_caller]
fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
level: rustc_errors::Level) -> rustc_errors::Diag<'_sess, G> {
match self {
NonConstTryBlockFromOutput {
span: __binding_0,
ty: __binding_1,
kind: __binding_2,
non_or_conditionally: __binding_3 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("`try` block cannot convert `{$ty}` to the result in {$kind}s")));
diag.code(E0015);
;
diag.arg("ty", __binding_1);
diag.arg("kind", __binding_2);
diag.span(__binding_0);
diag
}
}
}
}
};Diagnostic)]
397#[diag(r#"`try` block cannot convert `{$ty}` to the result in {$kind}s"#, code = E0015)]
398pub(crate) struct NonConstTryBlockFromOutput<'tcx> {
399 #[primary_span]
400 pub span: Span,
401 pub ty: Ty<'tcx>,
402 pub kind: ConstContext,
403 pub non_or_conditionally: &'static str,
404}
405
406#[derive(const _: () =
{
impl<'_sess, 'tcx, G> rustc_errors::Diagnostic<'_sess, G> for
NonConstAwait<'tcx> where G: rustc_errors::EmissionGuarantee {
#[track_caller]
fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
level: rustc_errors::Level) -> rustc_errors::Diag<'_sess, G> {
match self {
NonConstAwait {
span: __binding_0,
ty: __binding_1,
kind: __binding_2,
non_or_conditionally: __binding_3 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("cannot convert `{$ty}` into a future in {$kind}s")));
diag.code(E0015);
;
diag.arg("ty", __binding_1);
diag.arg("kind", __binding_2);
diag.span(__binding_0);
diag
}
}
}
}
};Diagnostic)]
407#[diag(r#"cannot convert `{$ty}` into a future in {$kind}s"#, code = E0015)]
408pub(crate) struct NonConstAwait<'tcx> {
409 #[primary_span]
410 pub span: Span,
411 pub ty: Ty<'tcx>,
412 pub kind: ConstContext,
413 pub non_or_conditionally: &'static str,
414}
415
416#[derive(const _: () =
{
impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for
NonConstClosure where G: rustc_errors::EmissionGuarantee {
#[track_caller]
fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
level: rustc_errors::Level) -> rustc_errors::Diag<'_sess, G> {
match self {
NonConstClosure {
span: __binding_0,
kind: __binding_1,
note: __binding_2,
non_or_conditionally: __binding_3 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("cannot call {$non_or_conditionally}-const closure in {$kind}s")));
diag.code(E0015);
;
diag.arg("kind", __binding_1);
diag.arg("non_or_conditionally", __binding_3);
diag.span(__binding_0);
if let Some(__binding_2) = __binding_2 {
diag.subdiagnostic(__binding_2);
}
diag
}
}
}
}
};Diagnostic)]
417#[diag(r#"cannot call {$non_or_conditionally}-const closure in {$kind}s"#, code = E0015)]
418pub(crate) struct NonConstClosure {
419 #[primary_span]
420 pub span: Span,
421 pub kind: ConstContext,
422 #[subdiagnostic]
423 pub note: Option<NonConstClosureNote>,
424 pub non_or_conditionally: &'static str,
425}
426
427#[derive(const _: () =
{
impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for
NonConstCVariadicCall where G: rustc_errors::EmissionGuarantee {
#[track_caller]
fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
level: rustc_errors::Level) -> rustc_errors::Diag<'_sess, G> {
match self {
NonConstCVariadicCall { span: __binding_0, kind: __binding_1
} => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("calling const c-variadic functions is unstable in {$kind}s")));
diag.code(E0015);
;
diag.arg("kind", __binding_1);
diag.span(__binding_0);
diag
}
}
}
}
};Diagnostic)]
428#[diag(r#"calling const c-variadic functions is unstable in {$kind}s"#, code = E0015)]
429pub(crate) struct NonConstCVariadicCall {
430 #[primary_span]
431 pub span: Span,
432 pub kind: ConstContext,
433}
434
435#[derive(const _: () =
{
impl rustc_errors::Subdiagnostic for NonConstClosureNote {
fn add_to_diag<__G>(self, diag: &mut rustc_errors::Diag<'_, __G>)
where __G: rustc_errors::EmissionGuarantee {
match self {
NonConstClosureNote::FnDef { span: __binding_0 } => {
let mut sub_args = rustc_errors::DiagArgMap::default();
let __message =
rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("function defined here, but it is not `const`")),
&sub_args);
diag.span_note(__binding_0, __message);
}
NonConstClosureNote::FnPtr { kind: __binding_0 } => {
let mut sub_args = rustc_errors::DiagArgMap::default();
sub_args.insert("kind".into(),
rustc_errors::IntoDiagArg::into_diag_arg(__binding_0,
&mut diag.long_ty_path));
let __message =
rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("function pointers need an RFC before allowed to be called in {$kind}s")),
&sub_args);
diag.note(__message);
}
NonConstClosureNote::Closure { kind: __binding_0 } => {
let mut sub_args = rustc_errors::DiagArgMap::default();
sub_args.insert("kind".into(),
rustc_errors::IntoDiagArg::into_diag_arg(__binding_0,
&mut diag.long_ty_path));
let __message =
rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("closures need an RFC before allowed to be called in {$kind}s")),
&sub_args);
diag.note(__message);
}
}
}
}
};Subdiagnostic)]
436pub(crate) enum NonConstClosureNote {
437 #[note("function defined here, but it is not `const`")]
438 FnDef {
439 #[primary_span]
440 span: Span,
441 },
442 #[note(r#"function pointers need an RFC before allowed to be called in {$kind}s"#)]
443 FnPtr { kind: ConstContext },
444 #[note(r#"closures need an RFC before allowed to be called in {$kind}s"#)]
445 Closure { kind: ConstContext },
446}
447
448#[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();
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)]
449#[multipart_suggestion("consider dereferencing here", applicability = "machine-applicable")]
450pub(crate) struct ConsiderDereferencing {
451 pub deref: String,
452 #[suggestion_part(code = "{deref}")]
453 pub span: Span,
454 #[suggestion_part(code = "{deref}")]
455 pub rhs_span: Span,
456}
457
458#[derive(const _: () =
{
impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for
NonConstOperator where G: rustc_errors::EmissionGuarantee {
#[track_caller]
fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
level: rustc_errors::Level) -> rustc_errors::Diag<'_sess, G> {
match self {
NonConstOperator {
span: __binding_0,
kind: __binding_1,
sugg: __binding_2,
non_or_conditionally: __binding_3 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("cannot call {$non_or_conditionally}-const operator in {$kind}s")));
diag.code(E0015);
;
diag.arg("kind", __binding_1);
diag.arg("non_or_conditionally", __binding_3);
diag.span(__binding_0);
if let Some(__binding_2) = __binding_2 {
diag.subdiagnostic(__binding_2);
}
diag
}
}
}
}
};Diagnostic)]
459#[diag(r#"cannot call {$non_or_conditionally}-const operator in {$kind}s"#, code = E0015)]
460pub(crate) struct NonConstOperator {
461 #[primary_span]
462 pub span: Span,
463 pub kind: ConstContext,
464 #[subdiagnostic]
465 pub sugg: Option<ConsiderDereferencing>,
466 pub non_or_conditionally: &'static str,
467}
468
469#[derive(const _: () =
{
impl<'_sess, 'tcx, G> rustc_errors::Diagnostic<'_sess, G> for
NonConstDerefCoercion<'tcx> where
G: rustc_errors::EmissionGuarantee {
#[track_caller]
fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
level: rustc_errors::Level) -> rustc_errors::Diag<'_sess, G> {
match self {
NonConstDerefCoercion {
span: __binding_0,
ty: __binding_1,
kind: __binding_2,
target_ty: __binding_3,
deref_target: __binding_4,
non_or_conditionally: __binding_5 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("cannot perform {$non_or_conditionally}-const deref coercion on `{$ty}` in {$kind}s")));
diag.code(E0015);
diag.note(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("attempting to deref into `{$target_ty}`")));
;
diag.arg("ty", __binding_1);
diag.arg("kind", __binding_2);
diag.arg("target_ty", __binding_3);
diag.arg("non_or_conditionally", __binding_5);
diag.span(__binding_0);
if let Some(__binding_4) = __binding_4 {
diag.span_note(__binding_4,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("deref defined here")));
}
diag
}
}
}
}
};Diagnostic)]
470#[diag(r#"cannot perform {$non_or_conditionally}-const deref coercion on `{$ty}` in {$kind}s"#, code = E0015)]
471#[note("attempting to deref into `{$target_ty}`")]
472pub(crate) struct NonConstDerefCoercion<'tcx> {
473 #[primary_span]
474 pub span: Span,
475 pub ty: Ty<'tcx>,
476 pub kind: ConstContext,
477 pub target_ty: Ty<'tcx>,
478 #[note("deref defined here")]
479 pub deref_target: Option<Span>,
480 pub non_or_conditionally: &'static str,
481}
482
483#[derive(const _: () =
{
impl<'_sess, 'tcx, G> rustc_errors::Diagnostic<'_sess, G> for
LiveDrop<'tcx> where G: rustc_errors::EmissionGuarantee {
#[track_caller]
fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
level: rustc_errors::Level) -> rustc_errors::Diag<'_sess, G> {
match self {
LiveDrop {
span: __binding_0,
kind: __binding_1,
dropped_ty: __binding_2,
dropped_at: __binding_3 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("destructor of `{$dropped_ty}` cannot be evaluated at compile-time")));
diag.code(E0493);
;
diag.arg("kind", __binding_1);
diag.arg("dropped_ty", __binding_2);
diag.span(__binding_0);
diag.span_label(__binding_0,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("the destructor for this type cannot be evaluated in {$kind}s")));
diag.span_label(__binding_3,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("value is dropped here")));
diag
}
}
}
}
};Diagnostic)]
484#[diag("destructor of `{$dropped_ty}` cannot be evaluated at compile-time", code = E0493)]
485pub(crate) struct LiveDrop<'tcx> {
486 #[primary_span]
487 #[label(r#"the destructor for this type cannot be evaluated in {$kind}s"#)]
488 pub span: Span,
489 pub kind: ConstContext,
490 pub dropped_ty: Ty<'tcx>,
491 #[label("value is dropped here")]
492 pub dropped_at: Span,
493}
494
495impl rustc_errors::IntoDiagArg for InternKind {
496 fn into_diag_arg(self, _: &mut Option<std::path::PathBuf>) -> DiagArgValue {
497 DiagArgValue::Str(Cow::Borrowed(match self {
498 InternKind::Static(Mutability::Not) => "static",
499 InternKind::Static(Mutability::Mut) => "static_mut",
500 InternKind::Constant => "const",
501 InternKind::Promoted => "promoted",
502 }))
503 }
504}