1use std::borrow::Cow;
2use std::fmt::Write;
3
4use either::Either;
5use rustc_abi::WrappingRange;
6use rustc_errors::codes::*;
7use rustc_errors::{
8 Diag, DiagArgValue, DiagMessage, Diagnostic, EmissionGuarantee, Level, MultiSpan,
9 Subdiagnostic, inline_fluent,
10};
11use rustc_hir::ConstContext;
12use rustc_macros::{Diagnostic, LintDiagnostic, Subdiagnostic};
13use rustc_middle::mir::interpret::{
14 CtfeProvenance, ExpectedKind, InterpErrorKind, InvalidMetaKind, InvalidProgramInfo,
15 Misalignment, Pointer, PointerKind, ResourceExhaustionInfo, UndefinedBehaviorInfo,
16 UnsupportedOpInfo, ValidationErrorInfo,
17};
18use rustc_middle::ty::{self, Mutability, Ty};
19use rustc_span::{Span, Symbol};
20
21use crate::interpret::InternKind;
22
23#[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)]
24#[diag(
25 r#"encountered dangling pointer in final value of {$kind ->
26 [static] static
27 [static_mut] mutable static
28 [const] constant
29 [promoted] promoted
30 *[other] {""}
31}"#
32)]
33pub(crate) struct DanglingPtrInFinal {
34 #[primary_span]
35 pub span: Span,
36 pub kind: InternKind,
37}
38
39#[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)]
40#[diag(
41 "#[thread_local] does not support implicit nested statics, please create explicit static items and refer to them instead"
42)]
43pub(crate) struct NestedStaticInThreadLocal {
44 #[primary_span]
45 pub span: Span,
46}
47
48#[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)]
49#[diag(
50 r#"encountered mutable pointer in final value of {$kind ->
51 [static] static
52 [static_mut] mutable static
53 [const] constant
54 [promoted] promoted
55 *[other] {""}
56}"#
57)]
58pub(crate) struct MutablePtrInFinal {
59 #[primary_span]
60 pub span: Span,
61 pub kind: InternKind,
62}
63
64#[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)]
65#[diag("encountered `const_allocate` pointer in final value that was not made global")]
66#[note(
67 "use `const_make_global` to turn allocated pointers into immutable globals before returning"
68)]
69pub(crate) struct ConstHeapPtrInFinal {
70 #[primary_span]
71 pub span: Span,
72}
73
74#[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)]
75#[diag(
76 r#"encountered partial pointer in final value of {$kind ->
77 [static] static
78 [static_mut] mutable static
79 [const] constant
80 [promoted] promoted
81 *[other] {""}
82}"#
83)]
84#[note(
85 "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"
86)]
87pub(crate) struct PartialPtrInFinal {
88 #[primary_span]
89 pub span: Span,
90 pub kind: InternKind,
91}
92
93#[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)]
94#[diag(
95 "const function that might be (indirectly) exposed to stable cannot use `#[feature({$gate})]`"
96)]
97pub(crate) struct UnstableInStableExposed {
98 pub gate: String,
99 #[primary_span]
100 pub span: Span,
101 #[help(
102 "mark the callee as `#[rustc_const_stable_indirect]` if it does not itself require any unstable features"
103 )]
104 pub is_function_call: bool,
105 pub is_function_call2: bool,
107 #[suggestion(
108 "if the {$is_function_call2 ->
109 [true] caller
110 *[false] function
111 } is not (yet) meant to be exposed to stable const contexts, add `#[rustc_const_unstable]`",
112 code = "#[rustc_const_unstable(feature = \"...\", issue = \"...\")]\n",
113 applicability = "has-placeholders"
114 )]
115 pub attr_span: Span,
116}
117
118#[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)]
119#[diag("thread-local statics cannot be accessed at compile-time", code = E0625)]
120pub(crate) struct ThreadLocalAccessErr {
121 #[primary_span]
122 pub span: Span,
123}
124
125#[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)]
126#[diag("pointers cannot be cast to integers during const eval")]
127#[note("at compile-time, pointers do not have an integer value")]
128#[note(
129 "avoiding this restriction via `transmute`, `union`, or raw pointers leads to compile-time undefined behavior"
130)]
131pub(crate) struct RawPtrToIntErr {
132 #[primary_span]
133 pub span: Span,
134}
135
136#[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)]
137#[diag("pointers cannot be reliably compared during const eval")]
138#[note("see issue #53020 <https://github.com/rust-lang/rust/issues/53020> for more information")]
139pub(crate) struct RawPtrComparisonErr {
140 #[primary_span]
141 pub span: Span,
142}
143
144#[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)]
145#[diag("argument to `panic!()` in a const context must have type `&str`")]
146pub(crate) struct PanicNonStrErr {
147 #[primary_span]
148 pub span: Span,
149}
150
151#[derive(const _: () =
{
impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for
UnallowedFnPointerCall where G: rustc_errors::EmissionGuarantee {
#[track_caller]
fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
level: rustc_errors::Level) -> rustc_errors::Diag<'_sess, G> {
match self {
UnallowedFnPointerCall {
span: __binding_0, kind: __binding_1 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("function pointer calls are not allowed in {$kind ->\n [const] constant\n [static] static\n [const_fn] constant function\n *[other] {\"\"}\n}s")));
;
diag.arg("kind", __binding_1);
diag.span(__binding_0);
diag
}
}
}
}
};Diagnostic)]
152#[diag(
153 r#"function pointer calls are not allowed in {$kind ->
154 [const] constant
155 [static] static
156 [const_fn] constant function
157 *[other] {""}
158}s"#
159)]
160pub(crate) struct UnallowedFnPointerCall {
161 #[primary_span]
162 pub span: Span,
163 pub kind: ConstContext,
164}
165
166#[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)]
167#[diag("`{$def_path}` is not yet stable as a const fn")]
168pub(crate) struct UnstableConstFn {
169 #[primary_span]
170 pub span: Span,
171 pub def_path: String,
172}
173
174#[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)]
175#[diag("`{$def_path}` is not yet stable as a const trait")]
176pub(crate) struct UnstableConstTrait {
177 #[primary_span]
178 pub span: Span,
179 pub def_path: String,
180}
181
182#[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)]
183#[diag("`{$name}` is not yet stable as a const intrinsic")]
184pub(crate) struct UnstableIntrinsic {
185 #[primary_span]
186 pub span: Span,
187 pub name: Symbol,
188 pub feature: Symbol,
189 #[suggestion(
190 "add `#![feature({$feature})]` to the crate attributes to enable",
191 code = "#![feature({feature})]\n",
192 applicability = "machine-applicable"
193 )]
194 pub suggestion: Span,
195}
196
197#[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)]
198#[diag("`{$def_path}` cannot be (indirectly) exposed to stable")]
199#[help(
200 "either mark the callee as `#[rustc_const_stable_indirect]`, or the caller as `#[rustc_const_unstable]`"
201)]
202pub(crate) struct UnmarkedConstItemExposed {
203 #[primary_span]
204 pub span: Span,
205 pub def_path: String,
206}
207
208#[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)]
209#[diag("intrinsic `{$def_path}` cannot be (indirectly) exposed to stable")]
210#[help(
211 "mark the caller as `#[rustc_const_unstable]`, or mark the intrinsic `#[rustc_intrinsic_const_stable_indirect]` (but this requires team approval)"
212)]
213pub(crate) struct UnmarkedIntrinsicExposed {
214 #[primary_span]
215 pub span: Span,
216 pub def_path: String,
217}
218
219#[derive(const _: () =
{
impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for
MutableBorrowEscaping where G: rustc_errors::EmissionGuarantee {
#[track_caller]
fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
level: rustc_errors::Level) -> rustc_errors::Diag<'_sess, G> {
match self {
MutableBorrowEscaping { span: __binding_0, kind: __binding_1
} => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("mutable borrows of temporaries that have their lifetime extended until the end of the program are not allowed")));
diag.code(E0764);
diag.note(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("temporaries in constants and statics can have their lifetime extended until the end of the program")));
diag.note(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("to avoid accidentally creating global mutable state, such temporaries must be immutable")));
diag.help(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("if you really want global mutable state, try replacing the temporary by an interior mutable `static` or a `static mut`")));
;
diag.arg("kind", __binding_1);
diag.span(__binding_0);
diag.span_label(__binding_0,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("this mutable borrow refers to such a temporary")));
diag
}
}
}
}
};Diagnostic)]
220#[diag("mutable borrows of temporaries that have their lifetime extended until the end of the program are not allowed", code = E0764)]
221#[note(
222 "temporaries in constants and statics can have their lifetime extended until the end of the program"
223)]
224#[note("to avoid accidentally creating global mutable state, such temporaries must be immutable")]
225#[help(
226 "if you really want global mutable state, try replacing the temporary by an interior mutable `static` or a `static mut`"
227)]
228pub(crate) struct MutableBorrowEscaping {
229 #[primary_span]
230 #[label("this mutable borrow refers to such a temporary")]
231 pub span: Span,
232 pub kind: ConstContext,
233}
234
235#[derive(const _: () =
{
impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for
NonConstFmtMacroCall where G: rustc_errors::EmissionGuarantee {
#[track_caller]
fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
level: rustc_errors::Level) -> rustc_errors::Diag<'_sess, G> {
match self {
NonConstFmtMacroCall {
span: __binding_0,
kind: __binding_1,
non_or_conditionally: __binding_2 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("cannot call {$non_or_conditionally}-const formatting macro in {$kind ->\n [const] constant\n [static] static\n [const_fn] constant function\n *[other] {\"\"}\n}s")));
diag.code(E0015);
;
diag.arg("kind", __binding_1);
diag.arg("non_or_conditionally", __binding_2);
diag.span(__binding_0);
diag
}
}
}
}
};Diagnostic)]
236#[diag(
237 r#"cannot call {$non_or_conditionally}-const formatting macro in {$kind ->
238 [const] constant
239 [static] static
240 [const_fn] constant function
241 *[other] {""}
242}s"#,
243 code = E0015,
244)]
245pub(crate) struct NonConstFmtMacroCall {
246 #[primary_span]
247 pub span: Span,
248 pub kind: ConstContext,
249 pub non_or_conditionally: &'static str,
250}
251
252#[derive(const _: () =
{
impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for NonConstFnCall
where G: rustc_errors::EmissionGuarantee {
#[track_caller]
fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
level: rustc_errors::Level) -> rustc_errors::Diag<'_sess, G> {
match self {
NonConstFnCall {
span: __binding_0,
def_path_str: __binding_1,
def_descr: __binding_2,
kind: __binding_3,
non_or_conditionally: __binding_4 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("cannot call {$non_or_conditionally}-const {$def_descr} `{$def_path_str}` in {$kind ->\n [const] constant\n [static] static\n [const_fn] constant function\n *[other] {\"\"}\n}s")));
diag.code(E0015);
;
diag.arg("def_path_str", __binding_1);
diag.arg("def_descr", __binding_2);
diag.arg("kind", __binding_3);
diag.arg("non_or_conditionally", __binding_4);
diag.span(__binding_0);
diag
}
}
}
}
};Diagnostic)]
253#[diag(r#"cannot call {$non_or_conditionally}-const {$def_descr} `{$def_path_str}` in {$kind ->
254 [const] constant
255 [static] static
256 [const_fn] constant function
257 *[other] {""}
258}s"#, code = E0015)]
259pub(crate) struct NonConstFnCall {
260 #[primary_span]
261 pub span: Span,
262 pub def_path_str: String,
263 pub def_descr: &'static str,
264 pub kind: ConstContext,
265 pub non_or_conditionally: &'static str,
266}
267
268#[derive(const _: () =
{
impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for
NonConstIntrinsic where G: rustc_errors::EmissionGuarantee {
#[track_caller]
fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
level: rustc_errors::Level) -> rustc_errors::Diag<'_sess, G> {
match self {
NonConstIntrinsic {
span: __binding_0, name: __binding_1, kind: __binding_2 } =>
{
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("cannot call non-const intrinsic `{$name}` in {$kind ->\n [const] constant\n [static] static\n [const_fn] constant function\n *[other] {\"\"}\n}s")));
;
diag.arg("name", __binding_1);
diag.arg("kind", __binding_2);
diag.span(__binding_0);
diag
}
}
}
}
};Diagnostic)]
269#[diag(
270 r#"cannot call non-const intrinsic `{$name}` in {$kind ->
271 [const] constant
272 [static] static
273 [const_fn] constant function
274 *[other] {""}
275}s"#
276)]
277pub(crate) struct NonConstIntrinsic {
278 #[primary_span]
279 pub span: Span,
280 pub name: Symbol,
281 pub kind: ConstContext,
282}
283
284#[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)]
285#[diag("{$msg}")]
286pub(crate) struct UnallowedOpInConstContext {
287 #[primary_span]
288 pub span: Span,
289 pub msg: String,
290}
291
292#[derive(const _: () =
{
impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for
UnallowedHeapAllocations 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 {
UnallowedHeapAllocations {
span: __binding_0, kind: __binding_1, teach: __binding_2 }
=> {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("allocations are not allowed in {$kind ->\n [const] constant\n [static] static\n [const_fn] constant function\n *[other] {\"\"}\n}s")));
diag.code(E0010);
;
diag.arg("kind", __binding_1);
diag.span(__binding_0);
diag.span_label(__binding_0,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("allocation not allowed in {$kind ->\n [const] constant\n [static] static\n [const_fn] constant function\n *[other] {\"\"}\n }s")));
if __binding_2 {
diag.note(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("the runtime heap is not yet available at compile-time, so no runtime heap allocations can be created")));
}
diag
}
}
}
}
};Diagnostic)]
293#[diag(r#"allocations are not allowed in {$kind ->
294 [const] constant
295 [static] static
296 [const_fn] constant function
297 *[other] {""}
298}s"#, code = E0010)]
299pub(crate) struct UnallowedHeapAllocations {
300 #[primary_span]
301 #[label(
302 r#"allocation not allowed in {$kind ->
303 [const] constant
304 [static] static
305 [const_fn] constant function
306 *[other] {""}
307 }s"#
308 )]
309 pub span: Span,
310 pub kind: ConstContext,
311 #[note(
312 "the runtime heap is not yet available at compile-time, so no runtime heap allocations can be created"
313 )]
314 pub teach: bool,
315}
316
317#[derive(const _: () =
{
impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for
UnallowedInlineAsm where G: rustc_errors::EmissionGuarantee {
#[track_caller]
fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
level: rustc_errors::Level) -> rustc_errors::Diag<'_sess, G> {
match self {
UnallowedInlineAsm { span: __binding_0, kind: __binding_1 }
=> {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("inline assembly is not allowed in {$kind ->\n [const] constant\n [static] static\n [const_fn] constant function\n *[other] {\"\"}\n}s")));
diag.code(E0015);
;
diag.arg("kind", __binding_1);
diag.span(__binding_0);
diag
}
}
}
}
};Diagnostic)]
318#[diag(r#"inline assembly is not allowed in {$kind ->
319 [const] constant
320 [static] static
321 [const_fn] constant function
322 *[other] {""}
323}s"#, code = E0015)]
324pub(crate) struct UnallowedInlineAsm {
325 #[primary_span]
326 pub span: Span,
327 pub kind: ConstContext,
328}
329
330#[derive(const _: () =
{
impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for
InteriorMutableBorrowEscaping where
G: rustc_errors::EmissionGuarantee {
#[track_caller]
fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
level: rustc_errors::Level) -> rustc_errors::Diag<'_sess, G> {
match self {
InteriorMutableBorrowEscaping {
span: __binding_0, kind: __binding_1 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("interior mutable shared borrows of temporaries that have their lifetime extended until the end of the program are not allowed")));
diag.code(E0492);
diag.note(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("temporaries in constants and statics can have their lifetime extended until the end of the program")));
diag.note(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("to avoid accidentally creating global mutable state, such temporaries must be immutable")));
diag.help(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("if you really want global mutable state, try replacing the temporary by an interior mutable `static` or a `static mut`")));
;
diag.arg("kind", __binding_1);
diag.span(__binding_0);
diag.span_label(__binding_0,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("this borrow of an interior mutable value refers to such a temporary")));
diag
}
}
}
}
};Diagnostic)]
331#[diag("interior mutable shared borrows of temporaries that have their lifetime extended until the end of the program are not allowed", code = E0492)]
332#[note(
333 "temporaries in constants and statics can have their lifetime extended until the end of the program"
334)]
335#[note("to avoid accidentally creating global mutable state, such temporaries must be immutable")]
336#[help(
337 "if you really want global mutable state, try replacing the temporary by an interior mutable `static` or a `static mut`"
338)]
339pub(crate) struct InteriorMutableBorrowEscaping {
340 #[primary_span]
341 #[label("this borrow of an interior mutable value refers to such a temporary")]
342 pub span: Span,
343 pub kind: ConstContext,
344}
345
346#[derive(const _: () =
{
impl<'__a> rustc_errors::LintDiagnostic<'__a, ()> for LongRunning {
#[track_caller]
fn decorate_lint<'__b>(self,
diag: &'__b mut rustc_errors::Diag<'__a, ()>) {
match self {
LongRunning { item_span: __binding_0 } => {
diag.primary_message(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
}
};
}
}
};LintDiagnostic)]
347#[diag("constant evaluation is taking a long time")]
348#[note(
349 "this lint makes sure the compiler doesn't get stuck due to infinite loops in const eval.
350 If your compilation actually takes a long time, you can safely allow the lint"
351)]
352pub struct LongRunning {
353 #[help("the constant being evaluated")]
354 pub item_span: Span,
355}
356
357#[derive(const _: () =
{
impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for
LongRunningWarn where G: rustc_errors::EmissionGuarantee {
#[track_caller]
fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
level: rustc_errors::Level) -> rustc_errors::Diag<'_sess, G> {
match self {
LongRunningWarn {
span: __binding_0,
item_span: __binding_1,
force_duplicate: __binding_2 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("constant evaluation is taking a long time")));
;
diag.arg("force_duplicate", __binding_2);
diag.span(__binding_0);
diag.span_label(__binding_0,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("the const evaluator is currently interpreting this expression")));
diag.span_help(__binding_1,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("the constant being evaluated")));
diag
}
}
}
}
};Diagnostic)]
358#[diag("constant evaluation is taking a long time")]
359pub struct LongRunningWarn {
360 #[primary_span]
361 #[label("the const evaluator is currently interpreting this expression")]
362 pub span: Span,
363 #[help("the constant being evaluated")]
364 pub item_span: Span,
365 pub force_duplicate: usize,
367}
368
369#[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 } => {
diag.store_args();
let __message =
diag.eagerly_translate(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("impl defined here, but it is not `const`")));
diag.span_note(__binding_0, __message);
diag.restore_args();
}
}
}
}
};Subdiagnostic)]
370#[note("impl defined here, but it is not `const`")]
371pub(crate) struct NonConstImplNote {
372 #[primary_span]
373 pub span: Span,
374}
375
376#[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)]
377pub struct FrameNote {
378 pub span: Span,
379 pub times: i32,
380 pub where_: &'static str,
381 pub instance: String,
382 pub has_label: bool,
383}
384
385impl Subdiagnostic for FrameNote {
386 fn add_to_diag<G: EmissionGuarantee>(self, diag: &mut Diag<'_, G>) {
387 diag.arg("times", self.times);
388 diag.arg("where_", self.where_);
389 diag.arg("instance", self.instance);
390 let mut span: MultiSpan = self.span.into();
391 if self.has_label && !self.span.is_dummy() {
392 span.push_span_label(self.span, rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("the failure occurred here"))inline_fluent!("the failure occurred here"));
393 }
394 let msg = diag.eagerly_translate(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed(r#"{$times ->
[0] {const_eval_frame_note_inner}
*[other] [... {$times} additional calls {const_eval_frame_note_inner} ...]
}
const_eval_frame_note_inner = inside {$where_ ->
[closure] closure
[instance] `{$instance}`
*[other] {""}
}
"#))inline_fluent!(
395 r#"{$times ->
396 [0] {const_eval_frame_note_inner}
397 *[other] [... {$times} additional calls {const_eval_frame_note_inner} ...]
398}
399
400const_eval_frame_note_inner = inside {$where_ ->
401 [closure] closure
402 [instance] `{$instance}`
403 *[other] {""}
404}
405"#
406 ));
407 diag.remove_arg("times");
408 diag.remove_arg("where_");
409 diag.remove_arg("instance");
410 diag.span_note(span, msg);
411 }
412}
413
414#[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 }
=> {
diag.store_args();
diag.arg("size", __binding_0);
diag.arg("align", __binding_1);
diag.arg("bytes", __binding_2);
let __message =
diag.eagerly_translate(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("the raw bytes of the constant (size: {$size}, align: {$align}) {\"{\"}{$bytes}{\"}\"}")));
diag.note(__message);
diag.restore_args();
}
}
}
}
};Subdiagnostic)]
415#[note(r#"the raw bytes of the constant (size: {$size}, align: {$align}) {"{"}{$bytes}{"}"}"#)]
416pub struct RawBytesNote {
417 pub size: u64,
418 pub align: u64,
419 pub bytes: String,
420}
421
422#[derive(const _: () =
{
impl<'_sess, 'tcx, G> rustc_errors::Diagnostic<'_sess, G> for
NonConstMatchEq<'tcx> where G: rustc_errors::EmissionGuarantee {
#[track_caller]
fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
level: rustc_errors::Level) -> rustc_errors::Diag<'_sess, G> {
match self {
NonConstMatchEq {
span: __binding_0,
ty: __binding_1,
kind: __binding_2,
non_or_conditionally: __binding_3 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("cannot match on `{$ty}` in {$kind ->\n [const] constant\n [static] static\n [const_fn] constant function\n *[other] {\"\"}\n}s")));
diag.note(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("`{$ty}` cannot be compared in compile-time, and therefore cannot be used in `match`es")));
;
diag.arg("ty", __binding_1);
diag.arg("kind", __binding_2);
diag.arg("non_or_conditionally", __binding_3);
diag.span(__binding_0);
diag
}
}
}
}
};Diagnostic)]
425#[diag(
426 r#"cannot match on `{$ty}` in {$kind ->
427 [const] constant
428 [static] static
429 [const_fn] constant function
430 *[other] {""}
431}s"#
432)]
433#[note("`{$ty}` cannot be compared in compile-time, and therefore cannot be used in `match`es")]
434pub struct NonConstMatchEq<'tcx> {
435 #[primary_span]
436 pub span: Span,
437 pub ty: Ty<'tcx>,
438 pub kind: ConstContext,
439 pub non_or_conditionally: &'static str,
440}
441
442#[derive(const _: () =
{
impl<'_sess, 'tcx, G> rustc_errors::Diagnostic<'_sess, G> for
NonConstForLoopIntoIter<'tcx> where
G: rustc_errors::EmissionGuarantee {
#[track_caller]
fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
level: rustc_errors::Level) -> rustc_errors::Diag<'_sess, G> {
match self {
NonConstForLoopIntoIter {
span: __binding_0,
ty: __binding_1,
kind: __binding_2,
non_or_conditionally: __binding_3 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("cannot use `for` loop on `{$ty}` in {$kind ->\n [const] constant\n [static] static\n [const_fn] constant function\n *[other] {\"\"}\n}s")));
diag.code(E0015);
;
diag.arg("ty", __binding_1);
diag.arg("kind", __binding_2);
diag.arg("non_or_conditionally", __binding_3);
diag.span(__binding_0);
diag
}
}
}
}
};Diagnostic)]
443#[diag(r#"cannot use `for` loop on `{$ty}` in {$kind ->
444 [const] constant
445 [static] static
446 [const_fn] constant function
447 *[other] {""}
448}s"#, code = E0015)]
449pub struct NonConstForLoopIntoIter<'tcx> {
450 #[primary_span]
451 pub span: Span,
452 pub ty: Ty<'tcx>,
453 pub kind: ConstContext,
454 pub non_or_conditionally: &'static str,
455}
456
457#[derive(const _: () =
{
impl<'_sess, 'tcx, G> rustc_errors::Diagnostic<'_sess, G> for
NonConstQuestionBranch<'tcx> where
G: rustc_errors::EmissionGuarantee {
#[track_caller]
fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
level: rustc_errors::Level) -> rustc_errors::Diag<'_sess, G> {
match self {
NonConstQuestionBranch {
span: __binding_0,
ty: __binding_1,
kind: __binding_2,
non_or_conditionally: __binding_3 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("`?` is not allowed on `{$ty}` in {$kind ->\n [const] constant\n [static] static\n [const_fn] constant function\n *[other] {\"\"}\n}s")));
diag.code(E0015);
;
diag.arg("ty", __binding_1);
diag.arg("kind", __binding_2);
diag.arg("non_or_conditionally", __binding_3);
diag.span(__binding_0);
diag
}
}
}
}
};Diagnostic)]
458#[diag(r#"`?` is not allowed on `{$ty}` in {$kind ->
459 [const] constant
460 [static] static
461 [const_fn] constant function
462 *[other] {""}
463}s"#, code = E0015)]
464pub struct NonConstQuestionBranch<'tcx> {
465 #[primary_span]
466 pub span: Span,
467 pub ty: Ty<'tcx>,
468 pub kind: ConstContext,
469 pub non_or_conditionally: &'static str,
470}
471
472#[derive(const _: () =
{
impl<'_sess, 'tcx, G> rustc_errors::Diagnostic<'_sess, G> for
NonConstQuestionFromResidual<'tcx> where
G: rustc_errors::EmissionGuarantee {
#[track_caller]
fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
level: rustc_errors::Level) -> rustc_errors::Diag<'_sess, G> {
match self {
NonConstQuestionFromResidual {
span: __binding_0,
ty: __binding_1,
kind: __binding_2,
non_or_conditionally: __binding_3 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("`?` is not allowed on `{$ty}` in {$kind ->\n [const] constant\n [static] static\n [const_fn] constant function\n *[other] {\"\"}\n}s")));
diag.code(E0015);
;
diag.arg("ty", __binding_1);
diag.arg("kind", __binding_2);
diag.arg("non_or_conditionally", __binding_3);
diag.span(__binding_0);
diag
}
}
}
}
};Diagnostic)]
473#[diag(r#"`?` is not allowed on `{$ty}` in {$kind ->
474 [const] constant
475 [static] static
476 [const_fn] constant function
477 *[other] {""}
478}s"#, code = E0015)]
479pub struct NonConstQuestionFromResidual<'tcx> {
480 #[primary_span]
481 pub span: Span,
482 pub ty: Ty<'tcx>,
483 pub kind: ConstContext,
484 pub non_or_conditionally: &'static str,
485}
486
487#[derive(const _: () =
{
impl<'_sess, 'tcx, G> rustc_errors::Diagnostic<'_sess, G> for
NonConstTryBlockFromOutput<'tcx> where
G: rustc_errors::EmissionGuarantee {
#[track_caller]
fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
level: rustc_errors::Level) -> rustc_errors::Diag<'_sess, G> {
match self {
NonConstTryBlockFromOutput {
span: __binding_0,
ty: __binding_1,
kind: __binding_2,
non_or_conditionally: __binding_3 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("`try` block cannot convert `{$ty}` to the result in {$kind ->\n [const] constant\n [static] static\n [const_fn] constant function\n *[other] {\"\"}\n}s")));
diag.code(E0015);
;
diag.arg("ty", __binding_1);
diag.arg("kind", __binding_2);
diag.arg("non_or_conditionally", __binding_3);
diag.span(__binding_0);
diag
}
}
}
}
};Diagnostic)]
488#[diag(r#"`try` block cannot convert `{$ty}` to the result in {$kind ->
489 [const] constant
490 [static] static
491 [const_fn] constant function
492 *[other] {""}
493}s"#, code = E0015)]
494pub struct NonConstTryBlockFromOutput<'tcx> {
495 #[primary_span]
496 pub span: Span,
497 pub ty: Ty<'tcx>,
498 pub kind: ConstContext,
499 pub non_or_conditionally: &'static str,
500}
501
502#[derive(const _: () =
{
impl<'_sess, 'tcx, G> rustc_errors::Diagnostic<'_sess, G> for
NonConstAwait<'tcx> where G: rustc_errors::EmissionGuarantee {
#[track_caller]
fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
level: rustc_errors::Level) -> rustc_errors::Diag<'_sess, G> {
match self {
NonConstAwait {
span: __binding_0,
ty: __binding_1,
kind: __binding_2,
non_or_conditionally: __binding_3 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("cannot convert `{$ty}` into a future in {$kind ->\n [const] constant\n [static] static\n [const_fn] constant function\n *[other] {\"\"}\n}s")));
diag.code(E0015);
;
diag.arg("ty", __binding_1);
diag.arg("kind", __binding_2);
diag.arg("non_or_conditionally", __binding_3);
diag.span(__binding_0);
diag
}
}
}
}
};Diagnostic)]
503#[diag(r#"cannot convert `{$ty}` into a future in {$kind ->
504 [const] constant
505 [static] static
506 [const_fn] constant function
507 *[other] {""}
508}s"#, code = E0015)]
509pub struct NonConstAwait<'tcx> {
510 #[primary_span]
511 pub span: Span,
512 pub ty: Ty<'tcx>,
513 pub kind: ConstContext,
514 pub non_or_conditionally: &'static str,
515}
516
517#[derive(const _: () =
{
impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for
NonConstClosure where G: rustc_errors::EmissionGuarantee {
#[track_caller]
fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
level: rustc_errors::Level) -> rustc_errors::Diag<'_sess, G> {
match self {
NonConstClosure {
span: __binding_0,
kind: __binding_1,
note: __binding_2,
non_or_conditionally: __binding_3 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("cannot call {$non_or_conditionally}-const closure in {$kind ->\n [const] constant\n [static] static\n [const_fn] constant function\n *[other] {\"\"}\n}s")));
diag.code(E0015);
;
diag.arg("kind", __binding_1);
diag.arg("non_or_conditionally", __binding_3);
diag.span(__binding_0);
if let Some(__binding_2) = __binding_2 {
diag.subdiagnostic(__binding_2);
}
diag
}
}
}
}
};Diagnostic)]
518#[diag(r#"cannot call {$non_or_conditionally}-const closure in {$kind ->
519 [const] constant
520 [static] static
521 [const_fn] constant function
522 *[other] {""}
523}s"#, code = E0015)]
524pub struct NonConstClosure {
525 #[primary_span]
526 pub span: Span,
527 pub kind: ConstContext,
528 #[subdiagnostic]
529 pub note: Option<NonConstClosureNote>,
530 pub non_or_conditionally: &'static str,
531}
532
533#[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 } => {
diag.store_args();
let __message =
diag.eagerly_translate(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("function defined here, but it is not `const`")));
diag.span_note(__binding_0, __message);
diag.restore_args();
}
NonConstClosureNote::FnPtr => {
diag.store_args();
let __message =
diag.eagerly_translate(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("function pointers need an RFC before allowed to be called in {$kind ->\n [const] constant\n [static] static\n [const_fn] constant function\n *[other] {\"\"}\n }s")));
diag.note(__message);
diag.restore_args();
}
NonConstClosureNote::Closure => {
diag.store_args();
let __message =
diag.eagerly_translate(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("closures need an RFC before allowed to be called in {$kind ->\n [const] constant\n [static] static\n [const_fn] constant function\n *[other] {\"\"}\n }s")));
diag.note(__message);
diag.restore_args();
}
}
}
}
};Subdiagnostic)]
534pub enum NonConstClosureNote {
535 #[note("function defined here, but it is not `const`")]
536 FnDef {
537 #[primary_span]
538 span: Span,
539 },
540 #[note(
541 r#"function pointers need an RFC before allowed to be called in {$kind ->
542 [const] constant
543 [static] static
544 [const_fn] constant function
545 *[other] {""}
546 }s"#
547 )]
548 FnPtr,
549 #[note(
550 r#"closures need an RFC before allowed to be called in {$kind ->
551 [const] constant
552 [static] static
553 [const_fn] constant function
554 *[other] {""}
555 }s"#
556 )]
557 Closure,
558}
559
560#[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));
diag.store_args();
diag.arg("deref", __binding_0);
let __message =
diag.eagerly_translate(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("consider dereferencing here")));
diag.multipart_suggestion_with_style(__message, suggestions,
rustc_errors::Applicability::MachineApplicable,
rustc_errors::SuggestionStyle::ShowCode);
diag.restore_args();
}
}
}
}
};Subdiagnostic)]
561#[multipart_suggestion("consider dereferencing here", applicability = "machine-applicable")]
562pub struct ConsiderDereferencing {
563 pub deref: String,
564 #[suggestion_part(code = "{deref}")]
565 pub span: Span,
566 #[suggestion_part(code = "{deref}")]
567 pub rhs_span: Span,
568}
569
570#[derive(const _: () =
{
impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for
NonConstOperator where G: rustc_errors::EmissionGuarantee {
#[track_caller]
fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
level: rustc_errors::Level) -> rustc_errors::Diag<'_sess, G> {
match self {
NonConstOperator {
span: __binding_0,
kind: __binding_1,
sugg: __binding_2,
non_or_conditionally: __binding_3 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("cannot call {$non_or_conditionally}-const operator in {$kind ->\n [const] constant\n [static] static\n [const_fn] constant function\n *[other] {\"\"}\n}s")));
diag.code(E0015);
;
diag.arg("kind", __binding_1);
diag.arg("non_or_conditionally", __binding_3);
diag.span(__binding_0);
if let Some(__binding_2) = __binding_2 {
diag.subdiagnostic(__binding_2);
}
diag
}
}
}
}
};Diagnostic)]
571#[diag(r#"cannot call {$non_or_conditionally}-const operator in {$kind ->
572 [const] constant
573 [static] static
574 [const_fn] constant function
575 *[other] {""}
576}s"#, code = E0015)]
577pub struct NonConstOperator {
578 #[primary_span]
579 pub span: Span,
580 pub kind: ConstContext,
581 #[subdiagnostic]
582 pub sugg: Option<ConsiderDereferencing>,
583 pub non_or_conditionally: &'static str,
584}
585
586#[derive(const _: () =
{
impl<'_sess, 'tcx, G> rustc_errors::Diagnostic<'_sess, G> for
NonConstDerefCoercion<'tcx> where
G: rustc_errors::EmissionGuarantee {
#[track_caller]
fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
level: rustc_errors::Level) -> rustc_errors::Diag<'_sess, G> {
match self {
NonConstDerefCoercion {
span: __binding_0,
ty: __binding_1,
kind: __binding_2,
target_ty: __binding_3,
deref_target: __binding_4,
non_or_conditionally: __binding_5 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("cannot perform {$non_or_conditionally}-const deref coercion on `{$ty}` in {$kind ->\n [const] constant\n [static] static\n [const_fn] constant function\n *[other] {\"\"}\n}s")));
diag.code(E0015);
diag.note(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("attempting to deref into `{$target_ty}`")));
;
diag.arg("ty", __binding_1);
diag.arg("kind", __binding_2);
diag.arg("target_ty", __binding_3);
diag.arg("non_or_conditionally", __binding_5);
diag.span(__binding_0);
if let Some(__binding_4) = __binding_4 {
diag.span_note(__binding_4,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("deref defined here")));
}
diag
}
}
}
}
};Diagnostic)]
587#[diag(r#"cannot perform {$non_or_conditionally}-const deref coercion on `{$ty}` in {$kind ->
588 [const] constant
589 [static] static
590 [const_fn] constant function
591 *[other] {""}
592}s"#, code = E0015)]
593#[note("attempting to deref into `{$target_ty}`")]
594pub struct NonConstDerefCoercion<'tcx> {
595 #[primary_span]
596 pub span: Span,
597 pub ty: Ty<'tcx>,
598 pub kind: ConstContext,
599 pub target_ty: Ty<'tcx>,
600 #[note("deref defined here")]
601 pub deref_target: Option<Span>,
602 pub non_or_conditionally: &'static str,
603}
604
605#[derive(const _: () =
{
impl<'_sess, 'tcx, G> rustc_errors::Diagnostic<'_sess, G> for
LiveDrop<'tcx> where G: rustc_errors::EmissionGuarantee {
#[track_caller]
fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
level: rustc_errors::Level) -> rustc_errors::Diag<'_sess, G> {
match self {
LiveDrop {
span: __binding_0,
kind: __binding_1,
dropped_ty: __binding_2,
dropped_at: __binding_3 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("destructor of `{$dropped_ty}` cannot be evaluated at compile-time")));
diag.code(E0493);
;
diag.arg("kind", __binding_1);
diag.arg("dropped_ty", __binding_2);
diag.span(__binding_0);
diag.span_label(__binding_0,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("the destructor for this type cannot be evaluated in {$kind ->\n [const] constant\n [static] static\n [const_fn] constant function\n *[other] {\"\"}\n }s")));
diag.span_label(__binding_3,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("value is dropped here")));
diag
}
}
}
}
};Diagnostic)]
606#[diag("destructor of `{$dropped_ty}` cannot be evaluated at compile-time", code = E0493)]
607pub struct LiveDrop<'tcx> {
608 #[primary_span]
609 #[label(
610 r#"the destructor for this type cannot be evaluated in {$kind ->
611 [const] constant
612 [static] static
613 [const_fn] constant function
614 *[other] {""}
615 }s"#
616 )]
617 pub span: Span,
618 pub kind: ConstContext,
619 pub dropped_ty: Ty<'tcx>,
620 #[label("value is dropped here")]
621 pub dropped_at: Span,
622}
623
624pub trait ReportErrorExt {
625 fn diagnostic_message(&self) -> DiagMessage;
627 fn add_args<G: EmissionGuarantee>(self, diag: &mut Diag<'_, G>);
628
629 fn debug(self) -> String
630 where
631 Self: Sized,
632 {
633 ty::tls::with(move |tcx| {
634 let dcx = tcx.dcx();
635 let mut diag = dcx.struct_allow(DiagMessage::Str(String::new().into()));
636 let message = self.diagnostic_message();
637 self.add_args(&mut diag);
638 let s = dcx.eagerly_translate_to_string(message, diag.args.iter());
639 diag.cancel();
640 s
641 })
642 }
643}
644
645impl<'a> ReportErrorExt for UndefinedBehaviorInfo<'a> {
646 fn diagnostic_message(&self) -> DiagMessage {
647 use UndefinedBehaviorInfo::*;
648
649 match self {
650 Ub(msg) => msg.clone().into(),
651 Custom(x) => (x.msg)(),
652 ValidationError(e) => e.diagnostic_message(),
653
654 Unreachable => "entering unreachable code".into(),
655 BoundsCheckFailed { .. } => rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("indexing out of bounds: the len is {$len} but the index is {$index}"))inline_fluent!("indexing out of bounds: the len is {$len} but the index is {$index}"),
656 DivisionByZero => "dividing by zero".into(),
657 RemainderByZero => "calculating the remainder with a divisor of zero".into(),
658 DivisionOverflow => "overflow in signed division (dividing MIN by -1)".into(),
659 RemainderOverflow => "overflow in signed remainder (dividing MIN by -1)".into(),
660 PointerArithOverflow => "overflowing pointer arithmetic: the total offset in bytes does not fit in an `isize`".into(),
661 ArithOverflow { .. } => rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("arithmetic overflow in `{$intrinsic}`"))inline_fluent!("arithmetic overflow in `{$intrinsic}`"),
662 ShiftOverflow { .. } => rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("overflowing shift by {$shift_amount} in `{$intrinsic}`"))inline_fluent!("overflowing shift by {$shift_amount} in `{$intrinsic}`"),
663 InvalidMeta(InvalidMetaKind::SliceTooBig) => "invalid metadata in wide pointer: slice is bigger than largest supported object".into(),
664 InvalidMeta(InvalidMetaKind::TooBig) => "invalid metadata in wide pointer: total size is bigger than largest supported object".into(),
665 UnterminatedCString(_) => "reading a null-terminated string starting at {$pointer} with no null found before end of allocation".into(),
666 PointerUseAfterFree(_, _) => rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("{$operation ->
[MemoryAccess] memory access failed
[InboundsPointerArithmetic] in-bounds pointer arithmetic failed
*[Dereferenceable] pointer not dereferenceable
}: {$alloc_id} has been freed, so this pointer is dangling"))inline_fluent!("{$operation ->
667 [MemoryAccess] memory access failed
668 [InboundsPointerArithmetic] in-bounds pointer arithmetic failed
669 *[Dereferenceable] pointer not dereferenceable
670}: {$alloc_id} has been freed, so this pointer is dangling"),
671 PointerOutOfBounds { .. } => rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("{$operation ->
[MemoryAccess] memory access failed
[InboundsPointerArithmetic] in-bounds pointer arithmetic failed
*[Dereferenceable] pointer not dereferenceable
}: {$operation ->
[MemoryAccess] attempting to access {$inbounds_size ->
[1] 1 byte
*[x] {$inbounds_size} bytes
}
[InboundsPointerArithmetic] attempting to offset pointer by {$inbounds_size ->
[1] 1 byte
*[x] {$inbounds_size} bytes
}
*[Dereferenceable] pointer must {$inbounds_size ->
[0] point to some allocation
[1] be dereferenceable for 1 byte
*[x] be dereferenceable for {$inbounds_size} bytes
}
}, but got {$pointer} which {$ptr_offset_is_neg ->
[true] points to before the beginning of the allocation
*[false] {$inbounds_size_is_neg ->
[false] {$alloc_size_minus_ptr_offset ->
[0] is at or beyond the end of the allocation of size {$alloc_size ->
[1] 1 byte
*[x] {$alloc_size} bytes
}
[1] is only 1 byte from the end of the allocation
*[x] is only {$alloc_size_minus_ptr_offset} bytes from the end of the allocation
}
*[true] {$ptr_offset_abs ->
[0] is at the beginning of the allocation
*[other] is only {$ptr_offset_abs} bytes from the beginning of the allocation
}
}
}
"))inline_fluent!("{$operation ->
672 [MemoryAccess] memory access failed
673 [InboundsPointerArithmetic] in-bounds pointer arithmetic failed
674 *[Dereferenceable] pointer not dereferenceable
675}: {$operation ->
676 [MemoryAccess] attempting to access {$inbounds_size ->
677 [1] 1 byte
678 *[x] {$inbounds_size} bytes
679 }
680 [InboundsPointerArithmetic] attempting to offset pointer by {$inbounds_size ->
681 [1] 1 byte
682 *[x] {$inbounds_size} bytes
683 }
684 *[Dereferenceable] pointer must {$inbounds_size ->
685 [0] point to some allocation
686 [1] be dereferenceable for 1 byte
687 *[x] be dereferenceable for {$inbounds_size} bytes
688 }
689}, but got {$pointer} which {$ptr_offset_is_neg ->
690 [true] points to before the beginning of the allocation
691 *[false] {$inbounds_size_is_neg ->
692 [false] {$alloc_size_minus_ptr_offset ->
693 [0] is at or beyond the end of the allocation of size {$alloc_size ->
694 [1] 1 byte
695 *[x] {$alloc_size} bytes
696 }
697 [1] is only 1 byte from the end of the allocation
698 *[x] is only {$alloc_size_minus_ptr_offset} bytes from the end of the allocation
699 }
700 *[true] {$ptr_offset_abs ->
701 [0] is at the beginning of the allocation
702 *[other] is only {$ptr_offset_abs} bytes from the beginning of the allocation
703 }
704 }
705}
706"),
707 DanglingIntPointer { addr: 0, .. } => rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("{$operation ->
[MemoryAccess] memory access failed
[InboundsPointerArithmetic] in-bounds pointer arithmetic failed
*[Dereferenceable] pointer not dereferenceable
}: {$operation ->
[MemoryAccess] attempting to access {$inbounds_size ->
[1] 1 byte
*[x] {$inbounds_size} bytes
}
[InboundsPointerArithmetic] attempting to offset pointer by {$inbounds_size ->
[1] 1 byte
*[x] {$inbounds_size} bytes
}
*[Dereferenceable] pointer must {$inbounds_size ->
[0] point to some allocation
[1] be dereferenceable for 1 byte
*[x] be dereferenceable for {$inbounds_size} bytes
}
}, but got null pointer"))inline_fluent!("{$operation ->
708 [MemoryAccess] memory access failed
709 [InboundsPointerArithmetic] in-bounds pointer arithmetic failed
710 *[Dereferenceable] pointer not dereferenceable
711}: {$operation ->
712 [MemoryAccess] attempting to access {$inbounds_size ->
713 [1] 1 byte
714 *[x] {$inbounds_size} bytes
715 }
716 [InboundsPointerArithmetic] attempting to offset pointer by {$inbounds_size ->
717 [1] 1 byte
718 *[x] {$inbounds_size} bytes
719 }
720 *[Dereferenceable] pointer must {$inbounds_size ->
721 [0] point to some allocation
722 [1] be dereferenceable for 1 byte
723 *[x] be dereferenceable for {$inbounds_size} bytes
724 }
725}, but got null pointer"),
726 DanglingIntPointer { .. } => rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("{$operation ->
[MemoryAccess] memory access failed
[InboundsPointerArithmetic] in-bounds pointer arithmetic failed
*[Dereferenceable] pointer not dereferenceable
}: {$operation ->
[MemoryAccess] attempting to access {$inbounds_size ->
[1] 1 byte
*[x] {$inbounds_size} bytes
}
[InboundsPointerArithmetic] attempting to offset pointer by {$inbounds_size ->
[1] 1 byte
*[x] {$inbounds_size} bytes
}
*[Dereferenceable] pointer must {$inbounds_size ->
[0] point to some allocation
[1] be dereferenceable for 1 byte
*[x] be dereferenceable for {$inbounds_size} bytes
}
}, but got {$pointer} which is a dangling pointer (it has no provenance)"))inline_fluent!("{$operation ->
727 [MemoryAccess] memory access failed
728 [InboundsPointerArithmetic] in-bounds pointer arithmetic failed
729 *[Dereferenceable] pointer not dereferenceable
730}: {$operation ->
731 [MemoryAccess] attempting to access {$inbounds_size ->
732 [1] 1 byte
733 *[x] {$inbounds_size} bytes
734 }
735 [InboundsPointerArithmetic] attempting to offset pointer by {$inbounds_size ->
736 [1] 1 byte
737 *[x] {$inbounds_size} bytes
738 }
739 *[Dereferenceable] pointer must {$inbounds_size ->
740 [0] point to some allocation
741 [1] be dereferenceable for 1 byte
742 *[x] be dereferenceable for {$inbounds_size} bytes
743 }
744}, but got {$pointer} which is a dangling pointer (it has no provenance)"),
745 AlignmentCheckFailed { .. } => rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("{$msg ->
[AccessedPtr] accessing memory
*[other] accessing memory based on pointer
} with alignment {$has}, but alignment {$required} is required"))inline_fluent!("{$msg ->
746 [AccessedPtr] accessing memory
747 *[other] accessing memory based on pointer
748} with alignment {$has}, but alignment {$required} is required"),
749 WriteToReadOnly(_) => rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("writing to {$allocation} which is read-only"))inline_fluent!("writing to {$allocation} which is read-only"),
750 DerefFunctionPointer(_) => rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("accessing {$allocation} which contains a function"))inline_fluent!("accessing {$allocation} which contains a function"),
751 DerefVTablePointer(_) => rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("accessing {$allocation} which contains a vtable"))inline_fluent!("accessing {$allocation} which contains a vtable"),
752 DerefTypeIdPointer(_) => rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("accessing {$allocation} which contains a `TypeId`"))inline_fluent!("accessing {$allocation} which contains a `TypeId`"),
753 InvalidBool(_) => rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("interpreting an invalid 8-bit value as a bool: 0x{$value}"))inline_fluent!("interpreting an invalid 8-bit value as a bool: 0x{$value}"),
754 InvalidChar(_) => rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("interpreting an invalid 32-bit value as a char: 0x{$value}"))inline_fluent!("interpreting an invalid 32-bit value as a char: 0x{$value}"),
755 InvalidTag(_) => rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("enum value has invalid tag: {$tag}"))inline_fluent!("enum value has invalid tag: {$tag}"),
756 InvalidFunctionPointer(_) => rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("using {$pointer} as function pointer but it does not point to a function"))inline_fluent!("using {$pointer} as function pointer but it does not point to a function"),
757 InvalidVTablePointer(_) => rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("using {$pointer} as vtable pointer but it does not point to a vtable"))inline_fluent!("using {$pointer} as vtable pointer but it does not point to a vtable"),
758 InvalidVTableTrait { .. } => rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("using vtable for `{$vtable_dyn_type}` but `{$expected_dyn_type}` was expected"))inline_fluent!("using vtable for `{$vtable_dyn_type}` but `{$expected_dyn_type}` was expected"),
759 InvalidStr(_) => rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("this string is not valid UTF-8: {$err}"))inline_fluent!("this string is not valid UTF-8: {$err}"),
760 InvalidUninitBytes(None) => "using uninitialized data, but this operation requires initialized memory".into(),
761 InvalidUninitBytes(Some(_)) => rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("reading memory at {$alloc}{$access}, but memory is uninitialized at {$uninit}, and this operation requires initialized memory"))inline_fluent!("reading memory at {$alloc}{$access}, but memory is uninitialized at {$uninit}, and this operation requires initialized memory"),
762 DeadLocal => "accessing a dead local variable".into(),
763 ScalarSizeMismatch(_) => rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("scalar size mismatch: expected {$target_size} bytes but got {$data_size} bytes instead"))inline_fluent!("scalar size mismatch: expected {$target_size} bytes but got {$data_size} bytes instead"),
764 UninhabitedEnumVariantWritten(_) => "writing discriminant of an uninhabited enum variant".into(),
765 UninhabitedEnumVariantRead(_) => "read discriminant of an uninhabited enum variant".into(),
766 InvalidNichedEnumVariantWritten { .. } => {
767 rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("trying to set discriminant of a {$ty} to the niched variant, but the value does not match"))inline_fluent!("trying to set discriminant of a {$ty} to the niched variant, but the value does not match")
768 }
769 AbiMismatchArgument { .. } => rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("calling a function whose parameter #{$arg_idx} has type {$callee_ty} passing argument of type {$caller_ty}"))inline_fluent!("calling a function whose parameter #{$arg_idx} has type {$callee_ty} passing argument of type {$caller_ty}"),
770 AbiMismatchReturn { .. } => rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("calling a function with return type {$callee_ty} passing return place of type {$caller_ty}"))inline_fluent!("calling a function with return type {$callee_ty} passing return place of type {$caller_ty}"),
771 }
772 }
773
774 fn add_args<G: EmissionGuarantee>(self, diag: &mut Diag<'_, G>) {
775 use UndefinedBehaviorInfo::*;
776 match self {
777 Ub(_) => {}
778 Custom(custom) => {
779 (custom.add_args)(&mut |name, value| {
780 diag.arg(name, value);
781 });
782 }
783 ValidationError(e) => e.add_args(diag),
784
785 Unreachable
786 | DivisionByZero
787 | RemainderByZero
788 | DivisionOverflow
789 | RemainderOverflow
790 | PointerArithOverflow
791 | InvalidMeta(InvalidMetaKind::SliceTooBig)
792 | InvalidMeta(InvalidMetaKind::TooBig)
793 | InvalidUninitBytes(None)
794 | DeadLocal
795 | UninhabitedEnumVariantWritten(_)
796 | UninhabitedEnumVariantRead(_) => {}
797
798 ArithOverflow { intrinsic } => {
799 diag.arg("intrinsic", intrinsic);
800 }
801 ShiftOverflow { intrinsic, shift_amount } => {
802 diag.arg("intrinsic", intrinsic);
803 diag.arg(
804 "shift_amount",
805 match shift_amount {
806 Either::Left(v) => v.to_string(),
807 Either::Right(v) => v.to_string(),
808 },
809 );
810 }
811 BoundsCheckFailed { len, index } => {
812 diag.arg("len", len);
813 diag.arg("index", index);
814 }
815 UnterminatedCString(ptr) | InvalidFunctionPointer(ptr) | InvalidVTablePointer(ptr) => {
816 diag.arg("pointer", ptr);
817 }
818 InvalidVTableTrait { expected_dyn_type, vtable_dyn_type } => {
819 diag.arg("expected_dyn_type", expected_dyn_type.to_string());
820 diag.arg("vtable_dyn_type", vtable_dyn_type.to_string());
821 }
822 PointerUseAfterFree(alloc_id, msg) => {
823 diag.arg("alloc_id", alloc_id).arg("operation", ::alloc::__export::must_use({
::alloc::fmt::format(format_args!("{0:?}", msg))
})format!("{:?}", msg));
824 }
825 PointerOutOfBounds { alloc_id, alloc_size, ptr_offset, inbounds_size, msg } => {
826 diag.arg("alloc_size", alloc_size.bytes());
827 diag.arg("pointer", {
828 let mut out = ::alloc::__export::must_use({
::alloc::fmt::format(format_args!("{0:?}", alloc_id))
})format!("{:?}", alloc_id);
829 if ptr_offset > 0 {
830 out.write_fmt(format_args!("+{0:#x}", ptr_offset))write!(out, "+{:#x}", ptr_offset).unwrap();
831 } else if ptr_offset < 0 {
832 out.write_fmt(format_args!("-{0:#x}", ptr_offset.unsigned_abs()))write!(out, "-{:#x}", ptr_offset.unsigned_abs()).unwrap();
833 }
834 out
835 });
836 diag.arg("inbounds_size", inbounds_size);
837 diag.arg("inbounds_size_is_neg", inbounds_size < 0);
838 diag.arg("inbounds_size_abs", inbounds_size.unsigned_abs());
839 diag.arg("ptr_offset", ptr_offset);
840 diag.arg("ptr_offset_is_neg", ptr_offset < 0);
841 diag.arg("ptr_offset_abs", ptr_offset.unsigned_abs());
842 diag.arg(
843 "alloc_size_minus_ptr_offset",
844 alloc_size.bytes().saturating_sub(ptr_offset as u64),
845 );
846 diag.arg("operation", ::alloc::__export::must_use({
::alloc::fmt::format(format_args!("{0:?}", msg))
})format!("{:?}", msg));
847 }
848 DanglingIntPointer { addr, inbounds_size, msg } => {
849 if addr != 0 {
850 diag.arg(
851 "pointer",
852 Pointer::<Option<CtfeProvenance>>::without_provenance(addr).to_string(),
853 );
854 }
855
856 diag.arg("inbounds_size", inbounds_size);
857 diag.arg("inbounds_size_is_neg", inbounds_size < 0);
858 diag.arg("inbounds_size_abs", inbounds_size.unsigned_abs());
859 diag.arg("operation", ::alloc::__export::must_use({
::alloc::fmt::format(format_args!("{0:?}", msg))
})format!("{:?}", msg));
860 }
861 AlignmentCheckFailed(Misalignment { required, has }, msg) => {
862 diag.arg("required", required.bytes());
863 diag.arg("has", has.bytes());
864 diag.arg("msg", ::alloc::__export::must_use({
::alloc::fmt::format(format_args!("{0:?}", msg))
})format!("{msg:?}"));
865 }
866 WriteToReadOnly(alloc)
867 | DerefFunctionPointer(alloc)
868 | DerefVTablePointer(alloc)
869 | DerefTypeIdPointer(alloc) => {
870 diag.arg("allocation", alloc);
871 }
872 InvalidBool(b) => {
873 diag.arg("value", ::alloc::__export::must_use({
::alloc::fmt::format(format_args!("{0:02x}", b))
})format!("{b:02x}"));
874 }
875 InvalidChar(c) => {
876 diag.arg("value", ::alloc::__export::must_use({
::alloc::fmt::format(format_args!("{0:08x}", c))
})format!("{c:08x}"));
877 }
878 InvalidTag(tag) => {
879 diag.arg("tag", ::alloc::__export::must_use({
::alloc::fmt::format(format_args!("{0:x}", tag))
})format!("{tag:x}"));
880 }
881 InvalidStr(err) => {
882 diag.arg("err", ::alloc::__export::must_use({
::alloc::fmt::format(format_args!("{0}", err))
})format!("{err}"));
883 }
884 InvalidUninitBytes(Some((alloc, info))) => {
885 diag.arg("alloc", alloc);
886 diag.arg("access", info.access);
887 diag.arg("uninit", info.bad);
888 }
889 ScalarSizeMismatch(info) => {
890 diag.arg("target_size", info.target_size);
891 diag.arg("data_size", info.data_size);
892 }
893 InvalidNichedEnumVariantWritten { enum_ty } => {
894 diag.arg("ty", enum_ty);
895 }
896 AbiMismatchArgument { arg_idx, caller_ty, callee_ty } => {
897 diag.arg("arg_idx", arg_idx + 1); diag.arg("caller_ty", caller_ty);
899 diag.arg("callee_ty", callee_ty);
900 }
901 AbiMismatchReturn { caller_ty, callee_ty } => {
902 diag.arg("caller_ty", caller_ty);
903 diag.arg("callee_ty", callee_ty);
904 }
905 }
906 }
907}
908
909impl<'tcx> ReportErrorExt for ValidationErrorInfo<'tcx> {
910 fn diagnostic_message(&self) -> DiagMessage {
911 use rustc_middle::mir::interpret::ValidationErrorKind::*;
912
913 match self.kind {
914 PtrToUninhabited { ptr_kind: PointerKind::Box, .. } => {
915 rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("{$front_matter}: encountered a box pointing to uninhabited type {$ty}"))inline_fluent!(
916 "{$front_matter}: encountered a box pointing to uninhabited type {$ty}"
917 )
918 }
919 PtrToUninhabited { ptr_kind: PointerKind::Ref(_), .. } => {
920 rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("{$front_matter}: encountered a reference pointing to uninhabited type {$ty}"))inline_fluent!(
921 "{$front_matter}: encountered a reference pointing to uninhabited type {$ty}"
922 )
923 }
924
925 PointerAsInt { .. } => {
926 rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("{$front_matter}: encountered a pointer, but {$expected}"))inline_fluent!("{$front_matter}: encountered a pointer, but {$expected}")
927 }
928 PartialPointer => rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("{$front_matter}: encountered a partial pointer or a mix of pointers"))inline_fluent!(
929 "{$front_matter}: encountered a partial pointer or a mix of pointers"
930 ),
931 MutableRefToImmutable => {
932 rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("{$front_matter}: encountered mutable reference or box pointing to read-only memory"))inline_fluent!(
933 "{$front_matter}: encountered mutable reference or box pointing to read-only memory"
934 )
935 }
936 NullFnPtr { .. } => {
937 rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("{$front_matter}: encountered a {$maybe ->
[true] maybe-null
*[false] null
} function pointer"))inline_fluent!(
938 "{$front_matter}: encountered a {$maybe ->
939 [true] maybe-null
940 *[false] null
941} function pointer"
942 )
943 }
944 NeverVal => {
945 rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("{$front_matter}: encountered a value of the never type `!`"))inline_fluent!("{$front_matter}: encountered a value of the never type `!`")
946 }
947 NonnullPtrMaybeNull { .. } => {
948 rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("{$front_matter}: encountered a maybe-null pointer, but expected something that is definitely non-zero"))inline_fluent!(
949 "{$front_matter}: encountered a maybe-null pointer, but expected something that is definitely non-zero"
950 )
951 }
952 PtrOutOfRange { .. } => {
953 rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("{$front_matter}: encountered a pointer with unknown absolute address, but expected something that is definitely {$in_range}"))inline_fluent!(
954 "{$front_matter}: encountered a pointer with unknown absolute address, but expected something that is definitely {$in_range}"
955 )
956 }
957 OutOfRange { .. } => {
958 rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("{$front_matter}: encountered {$value}, but expected something {$in_range}"))inline_fluent!(
959 "{$front_matter}: encountered {$value}, but expected something {$in_range}"
960 )
961 }
962 UnsafeCellInImmutable => {
963 rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("{$front_matter}: encountered `UnsafeCell` in read-only memory"))inline_fluent!("{$front_matter}: encountered `UnsafeCell` in read-only memory")
964 }
965 UninhabitedVal { .. } => {
966 rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("{$front_matter}: encountered a value of uninhabited type `{$ty}`"))inline_fluent!("{$front_matter}: encountered a value of uninhabited type `{$ty}`")
967 }
968 InvalidEnumTag { .. } => {
969 rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("{$front_matter}: encountered {$value}, but expected a valid enum tag"))inline_fluent!(
970 "{$front_matter}: encountered {$value}, but expected a valid enum tag"
971 )
972 }
973 UninhabitedEnumVariant => {
974 rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("{$front_matter}: encountered an uninhabited enum variant"))inline_fluent!("{$front_matter}: encountered an uninhabited enum variant")
975 }
976 Uninit { .. } => {
977 rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("{$front_matter}: encountered uninitialized memory, but {$expected}"))inline_fluent!("{$front_matter}: encountered uninitialized memory, but {$expected}")
978 }
979 InvalidVTablePtr { .. } => {
980 rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("{$front_matter}: encountered {$value}, but expected a vtable pointer"))inline_fluent!(
981 "{$front_matter}: encountered {$value}, but expected a vtable pointer"
982 )
983 }
984 InvalidMetaWrongTrait { .. } => {
985 rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("{$front_matter}: wrong trait in wide pointer vtable: expected `{$expected_dyn_type}`, but encountered `{$vtable_dyn_type}`"))inline_fluent!(
986 "{$front_matter}: wrong trait in wide pointer vtable: expected `{$expected_dyn_type}`, but encountered `{$vtable_dyn_type}`"
987 )
988 }
989 InvalidMetaSliceTooLarge { ptr_kind: PointerKind::Box } => {
990 rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("{$front_matter}: encountered invalid box metadata: slice is bigger than largest supported object"))inline_fluent!(
991 "{$front_matter}: encountered invalid box metadata: slice is bigger than largest supported object"
992 )
993 }
994 InvalidMetaSliceTooLarge { ptr_kind: PointerKind::Ref(_) } => {
995 rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("{$front_matter}: encountered invalid reference metadata: slice is bigger than largest supported object"))inline_fluent!(
996 "{$front_matter}: encountered invalid reference metadata: slice is bigger than largest supported object"
997 )
998 }
999
1000 InvalidMetaTooLarge { ptr_kind: PointerKind::Box } => {
1001 rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("{$front_matter}: encountered invalid box metadata: total size is bigger than largest supported object"))inline_fluent!(
1002 "{$front_matter}: encountered invalid box metadata: total size is bigger than largest supported object"
1003 )
1004 }
1005 InvalidMetaTooLarge { ptr_kind: PointerKind::Ref(_) } => {
1006 rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("{$front_matter}: encountered invalid reference metadata: total size is bigger than largest supported object"))inline_fluent!(
1007 "{$front_matter}: encountered invalid reference metadata: total size is bigger than largest supported object"
1008 )
1009 }
1010 UnalignedPtr { ptr_kind: PointerKind::Ref(_), .. } => {
1011 rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("{$front_matter}: encountered an unaligned reference (required {$required_bytes} byte alignment but found {$found_bytes})"))inline_fluent!(
1012 "{$front_matter}: encountered an unaligned reference (required {$required_bytes} byte alignment but found {$found_bytes})"
1013 )
1014 }
1015 UnalignedPtr { ptr_kind: PointerKind::Box, .. } => {
1016 rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("{$front_matter}: encountered an unaligned box (required {$required_bytes} byte alignment but found {$found_bytes})"))inline_fluent!(
1017 "{$front_matter}: encountered an unaligned box (required {$required_bytes} byte alignment but found {$found_bytes})"
1018 )
1019 }
1020
1021 NullPtr { ptr_kind: PointerKind::Box, .. } => {
1022 rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("{$front_matter}: encountered a {$maybe ->
[true] maybe-null
*[false] null
} box"))inline_fluent!(
1023 "{$front_matter}: encountered a {$maybe ->
1024 [true] maybe-null
1025 *[false] null
1026} box"
1027 )
1028 }
1029 NullPtr { ptr_kind: PointerKind::Ref(_), .. } => {
1030 rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("{$front_matter}: encountered a {$maybe ->
[true] maybe-null
*[false] null
} reference"))inline_fluent!(
1031 "{$front_matter}: encountered a {$maybe ->
1032 [true] maybe-null
1033 *[false] null
1034} reference"
1035 )
1036 }
1037 DanglingPtrNoProvenance { ptr_kind: PointerKind::Box, .. } => {
1038 rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("{$front_matter}: encountered a dangling box ({$pointer} has no provenance)"))inline_fluent!(
1039 "{$front_matter}: encountered a dangling box ({$pointer} has no provenance)"
1040 )
1041 }
1042 DanglingPtrNoProvenance { ptr_kind: PointerKind::Ref(_), .. } => {
1043 rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("{$front_matter}: encountered a dangling reference ({$pointer} has no provenance)"))inline_fluent!(
1044 "{$front_matter}: encountered a dangling reference ({$pointer} has no provenance)"
1045 )
1046 }
1047 DanglingPtrOutOfBounds { ptr_kind: PointerKind::Box } => {
1048 rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("{$front_matter}: encountered a dangling box (going beyond the bounds of its allocation)"))inline_fluent!(
1049 "{$front_matter}: encountered a dangling box (going beyond the bounds of its allocation)"
1050 )
1051 }
1052 DanglingPtrOutOfBounds { ptr_kind: PointerKind::Ref(_) } => {
1053 rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("{$front_matter}: encountered a dangling reference (going beyond the bounds of its allocation)"))inline_fluent!(
1054 "{$front_matter}: encountered a dangling reference (going beyond the bounds of its allocation)"
1055 )
1056 }
1057 DanglingPtrUseAfterFree { ptr_kind: PointerKind::Box } => {
1058 rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("{$front_matter}: encountered a dangling box (use-after-free)"))inline_fluent!("{$front_matter}: encountered a dangling box (use-after-free)")
1059 }
1060 DanglingPtrUseAfterFree { ptr_kind: PointerKind::Ref(_) } => {
1061 rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("{$front_matter}: encountered a dangling reference (use-after-free)"))inline_fluent!("{$front_matter}: encountered a dangling reference (use-after-free)")
1062 }
1063 InvalidBool { .. } => {
1064 rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("{$front_matter}: encountered {$value}, but expected a boolean"))inline_fluent!("{$front_matter}: encountered {$value}, but expected a boolean")
1065 }
1066 InvalidChar { .. } => {
1067 rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("{$front_matter}: encountered {$value}, but expected a valid unicode scalar value (in `0..=0x10FFFF` but not in `0xD800..=0xDFFF`)"))inline_fluent!(
1068 "{$front_matter}: encountered {$value}, but expected a valid unicode scalar value (in `0..=0x10FFFF` but not in `0xD800..=0xDFFF`)"
1069 )
1070 }
1071 InvalidFnPtr { .. } => {
1072 rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("{$front_matter}: encountered {$value}, but expected a function pointer"))inline_fluent!(
1073 "{$front_matter}: encountered {$value}, but expected a function pointer"
1074 )
1075 }
1076 }
1077 }
1078
1079 fn add_args<G: EmissionGuarantee>(self, err: &mut Diag<'_, G>) {
1080 use rustc_errors::inline_fluent;
1081 use rustc_middle::mir::interpret::ValidationErrorKind::*;
1082
1083 if let PointerAsInt { .. } | PartialPointer = self.kind {
1084 err.help(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("this code performed an operation that depends on the underlying bytes representing a pointer"))inline_fluent!("this code performed an operation that depends on the underlying bytes representing a pointer"));
1085 err.help(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("the absolute address of a pointer is not known at compile-time, so such operations are not supported"))inline_fluent!("the absolute address of a pointer is not known at compile-time, so such operations are not supported"));
1086 }
1087
1088 let message = if let Some(path) = self.path {
1089 err.dcx.eagerly_translate_to_string(
1090 rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("constructing invalid value at {$path}"))inline_fluent!("constructing invalid value at {$path}"),
1091 [("path".into(), DiagArgValue::Str(path.into()))].iter().map(|(a, b)| (a, b)),
1092 )
1093 } else {
1094 err.dcx.eagerly_translate_to_string(
1095 rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("constructing invalid value"))inline_fluent!("constructing invalid value"),
1096 [].into_iter(),
1097 )
1098 };
1099
1100 err.arg("front_matter", message);
1101
1102 fn add_range_arg<G: EmissionGuarantee>(
1103 r: WrappingRange,
1104 max_hi: u128,
1105 err: &mut Diag<'_, G>,
1106 ) {
1107 let WrappingRange { start: lo, end: hi } = r;
1108 if !(hi <= max_hi) {
::core::panicking::panic("assertion failed: hi <= max_hi")
};assert!(hi <= max_hi);
1109 let msg = if lo > hi {
1110 rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("less or equal to {$hi}, or greater or equal to {$lo}"))inline_fluent!("less or equal to {$hi}, or greater or equal to {$lo}")
1111 } else if lo == hi {
1112 rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("equal to {$lo}"))inline_fluent!("equal to {$lo}")
1113 } else if lo == 0 {
1114 if !(hi < max_hi) {
{
::core::panicking::panic_fmt(format_args!("should not be printing if the range covers everything"));
}
};assert!(hi < max_hi, "should not be printing if the range covers everything");
1115 rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("less or equal to {$hi}"))inline_fluent!("less or equal to {$hi}")
1116 } else if hi == max_hi {
1117 if !(lo > 0) {
{
::core::panicking::panic_fmt(format_args!("should not be printing if the range covers everything"));
}
};assert!(lo > 0, "should not be printing if the range covers everything");
1118 rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("greater or equal to {$lo}"))inline_fluent!("greater or equal to {$lo}")
1119 } else {
1120 rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("in the range {$lo}..={$hi}"))inline_fluent!("in the range {$lo}..={$hi}")
1121 };
1122
1123 let args = [
1124 ("lo".into(), DiagArgValue::Str(lo.to_string().into())),
1125 ("hi".into(), DiagArgValue::Str(hi.to_string().into())),
1126 ];
1127 let args = args.iter().map(|(a, b)| (a, b));
1128 let message = err.dcx.eagerly_translate_to_string(msg, args);
1129 err.arg("in_range", message);
1130 }
1131
1132 match self.kind {
1133 PtrToUninhabited { ty, .. } | UninhabitedVal { ty } => {
1134 err.arg("ty", ty);
1135 }
1136 PointerAsInt { expected } | Uninit { expected } => {
1137 let msg = match expected {
1138 ExpectedKind::Reference => rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("expected a reference"))inline_fluent!("expected a reference"),
1139 ExpectedKind::Box => rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("expected a box"))inline_fluent!("expected a box"),
1140 ExpectedKind::RawPtr => rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("expected a raw pointer"))inline_fluent!("expected a raw pointer"),
1141 ExpectedKind::InitScalar => rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("expected initialized scalar value"))inline_fluent!("expected initialized scalar value"),
1142 ExpectedKind::Bool => rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("expected a boolean"))inline_fluent!("expected a boolean"),
1143 ExpectedKind::Char => rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("expected a unicode scalar value"))inline_fluent!("expected a unicode scalar value"),
1144 ExpectedKind::Float => rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("expected a floating point number"))inline_fluent!("expected a floating point number"),
1145 ExpectedKind::Int => rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("expected an integer"))inline_fluent!("expected an integer"),
1146 ExpectedKind::FnPtr => rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("expected a function pointer"))inline_fluent!("expected a function pointer"),
1147 ExpectedKind::EnumTag => rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("expected a valid enum tag"))inline_fluent!("expected a valid enum tag"),
1148 ExpectedKind::Str => rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("expected a string"))inline_fluent!("expected a string"),
1149 };
1150 let msg = err.dcx.eagerly_translate_to_string(msg, [].into_iter());
1151 err.arg("expected", msg);
1152 }
1153 InvalidEnumTag { value }
1154 | InvalidVTablePtr { value }
1155 | InvalidBool { value }
1156 | InvalidChar { value }
1157 | InvalidFnPtr { value } => {
1158 err.arg("value", value);
1159 }
1160 PtrOutOfRange { range, max_value } => add_range_arg(range, max_value, err),
1161 OutOfRange { range, max_value, value } => {
1162 err.arg("value", value);
1163 add_range_arg(range, max_value, err);
1164 }
1165 UnalignedPtr { required_bytes, found_bytes, .. } => {
1166 err.arg("required_bytes", required_bytes);
1167 err.arg("found_bytes", found_bytes);
1168 }
1169 DanglingPtrNoProvenance { pointer, .. } => {
1170 err.arg("pointer", pointer);
1171 }
1172 InvalidMetaWrongTrait { vtable_dyn_type, expected_dyn_type } => {
1173 err.arg("vtable_dyn_type", vtable_dyn_type.to_string());
1174 err.arg("expected_dyn_type", expected_dyn_type.to_string());
1175 }
1176 NullPtr { maybe, .. } | NullFnPtr { maybe } => {
1177 err.arg("maybe", maybe);
1178 }
1179 MutableRefToImmutable
1180 | NonnullPtrMaybeNull
1181 | NeverVal
1182 | UnsafeCellInImmutable
1183 | InvalidMetaSliceTooLarge { .. }
1184 | InvalidMetaTooLarge { .. }
1185 | DanglingPtrUseAfterFree { .. }
1186 | DanglingPtrOutOfBounds { .. }
1187 | UninhabitedEnumVariant
1188 | PartialPointer => {}
1189 }
1190 }
1191}
1192
1193impl ReportErrorExt for UnsupportedOpInfo {
1194 fn diagnostic_message(&self) -> DiagMessage {
1195 match self {
1196 UnsupportedOpInfo::Unsupported(s) => s.clone().into(),
1197 UnsupportedOpInfo::ExternTypeField => {
1198 "`extern type` field does not have a known offset".into()
1199 }
1200 UnsupportedOpInfo::UnsizedLocal => "unsized locals are not supported".into(),
1201 UnsupportedOpInfo::ReadPartialPointer(_) => {
1202 rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("unable to read parts of a pointer from memory at {$ptr}"))inline_fluent!("unable to read parts of a pointer from memory at {$ptr}")
1203 }
1204 UnsupportedOpInfo::ReadPointerAsInt(_) => "unable to turn pointer into integer".into(),
1205 UnsupportedOpInfo::ThreadLocalStatic(_) => {
1206 rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("cannot access thread local static `{$did}`"))inline_fluent!("cannot access thread local static `{$did}`")
1207 }
1208 UnsupportedOpInfo::ExternStatic(_) => {
1209 rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("cannot access extern static `{$did}`"))inline_fluent!("cannot access extern static `{$did}`")
1210 }
1211 }
1212 .into()
1213 }
1214
1215 fn add_args<G: EmissionGuarantee>(self, diag: &mut Diag<'_, G>) {
1216 use UnsupportedOpInfo::*;
1217
1218 if let ReadPointerAsInt(_) | ReadPartialPointer(_) = self {
1219 diag.help("this code performed an operation that depends on the underlying bytes representing a pointer");
1220 diag.help("the absolute address of a pointer is not known at compile-time, so such operations are not supported");
1221 }
1222 match self {
1223 UnsizedLocal
1227 | UnsupportedOpInfo::ExternTypeField
1228 | Unsupported(_)
1229 | ReadPointerAsInt(_) => {}
1230 ReadPartialPointer(ptr) => {
1231 diag.arg("ptr", ptr);
1232 }
1233 ThreadLocalStatic(did) | ExternStatic(did) => rustc_middle::ty::tls::with(|tcx| {
1234 diag.arg("did", tcx.def_path_str(did));
1235 }),
1236 }
1237 }
1238}
1239
1240impl<'tcx> ReportErrorExt for InterpErrorKind<'tcx> {
1241 fn diagnostic_message(&self) -> DiagMessage {
1242 match self {
1243 InterpErrorKind::UndefinedBehavior(ub) => ub.diagnostic_message(),
1244 InterpErrorKind::Unsupported(e) => e.diagnostic_message(),
1245 InterpErrorKind::InvalidProgram(e) => e.diagnostic_message(),
1246 InterpErrorKind::ResourceExhaustion(e) => e.diagnostic_message(),
1247 InterpErrorKind::MachineStop(e) => e.diagnostic_message(),
1248 }
1249 }
1250 fn add_args<G: EmissionGuarantee>(self, diag: &mut Diag<'_, G>) {
1251 match self {
1252 InterpErrorKind::UndefinedBehavior(ub) => ub.add_args(diag),
1253 InterpErrorKind::Unsupported(e) => e.add_args(diag),
1254 InterpErrorKind::InvalidProgram(e) => e.add_args(diag),
1255 InterpErrorKind::ResourceExhaustion(e) => e.add_args(diag),
1256 InterpErrorKind::MachineStop(e) => e.add_args(&mut |name, value| {
1257 diag.arg(name, value);
1258 }),
1259 }
1260 }
1261}
1262
1263impl<'tcx> ReportErrorExt for InvalidProgramInfo<'tcx> {
1264 fn diagnostic_message(&self) -> DiagMessage {
1265 match self {
1266 InvalidProgramInfo::TooGeneric => "encountered overly generic constant".into(),
1267 InvalidProgramInfo::AlreadyReported(_) => {
1268 "an error has already been reported elsewhere (this should not usually be printed)"
1269 .into()
1270 }
1271 InvalidProgramInfo::Layout(e) => e.diagnostic_message(),
1272 }
1273 }
1274 fn add_args<G: EmissionGuarantee>(self, diag: &mut Diag<'_, G>) {
1275 match self {
1276 InvalidProgramInfo::TooGeneric | InvalidProgramInfo::AlreadyReported(_) => {}
1277 InvalidProgramInfo::Layout(e) => {
1278 let dummy_level = Level::Bug;
1280 let dummy_diag: Diag<'_, ()> = e.into_diagnostic().into_diag(diag.dcx, dummy_level);
1281 for (name, val) in dummy_diag.args.iter() {
1282 diag.arg(name.clone(), val.clone());
1283 }
1284 dummy_diag.cancel();
1285 }
1286 }
1287 }
1288}
1289
1290impl ReportErrorExt for ResourceExhaustionInfo {
1291 fn diagnostic_message(&self) -> DiagMessage {
1292 match self {
1293 ResourceExhaustionInfo::StackFrameLimitReached => {
1294 "reached the configured maximum number of stack frames"
1295 }
1296 ResourceExhaustionInfo::MemoryExhausted => {
1297 "tried to allocate more memory than available to compiler"
1298 }
1299 ResourceExhaustionInfo::AddressSpaceFull => {
1300 "there are no more free addresses in the address space"
1301 }
1302 ResourceExhaustionInfo::Interrupted => "compilation was interrupted",
1303 }
1304 .into()
1305 }
1306 fn add_args<G: EmissionGuarantee>(self, _: &mut Diag<'_, G>) {}
1307}
1308
1309impl rustc_errors::IntoDiagArg for InternKind {
1310 fn into_diag_arg(self, _: &mut Option<std::path::PathBuf>) -> DiagArgValue {
1311 DiagArgValue::Str(Cow::Borrowed(match self {
1312 InternKind::Static(Mutability::Not) => "static",
1313 InternKind::Static(Mutability::Mut) => "static_mut",
1314 InternKind::Constant => "const",
1315 InternKind::Promoted => "promoted",
1316 }))
1317 }
1318}