2023-12-16 15:24:25 +00:00
|
|
|
use std::borrow::Cow;
|
2024-07-29 14:40:21 +00:00
|
|
|
use std::fmt::Write;
|
2023-12-16 15:24:25 +00:00
|
|
|
|
2024-05-21 10:17:34 +00:00
|
|
|
use either::Either;
|
2024-11-03 02:32:52 +00:00
|
|
|
use rustc_abi::WrappingRange;
|
2023-05-17 10:30:14 +00:00
|
|
|
use rustc_errors::codes::*;
|
|
|
|
use rustc_errors::{
|
2024-06-18 10:35:56 +00:00
|
|
|
Diag, DiagArgValue, DiagCtxtHandle, DiagMessage, Diagnostic, EmissionGuarantee, Level,
|
Shorten span of panic failures in const context
Previously, we included a redundant prefix on the panic message and a postfix of the location of the panic. The prefix didn't carry any additional information beyond "something failed", and the location of the panic is redundant with the diagnostic's span, which gets printed out even if its code is not shown.
```
error[E0080]: evaluation of constant value failed
--> $DIR/assert-type-intrinsics.rs:11:9
|
LL | MaybeUninit::<!>::uninit().assume_init();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ evaluation panicked: aborted execution: attempted to instantiate uninhabited type `!`
```
```
error[E0080]: evaluation of `Fail::<i32>::C` failed
--> $DIR/collect-in-dead-closure.rs:9:19
|
LL | const C: () = panic!();
| ^^^^^^^^ evaluation panicked: explicit panic
|
= note: this error originates in the macro
`$crate::panic::panic_2015` which comes from the expansion of the macro
`panic` (in Nightly builds, run with -Z macro-backtrace for more info)
```
```
error[E0080]: evaluation of constant value failed
--> $DIR/uninhabited.rs:41:9
|
LL | assert!(false);
| ^^^^^^^^^^^^^^ evaluation panicked: assertion failed: false
|
= note: this error originates in the macro `assert` (in Nightly builds, run with -Z macro-backtrace for more info)
```
---
When the primary span for a const error is the same as the first frame in the const error report, skip it.
```
error[E0080]: evaluation of constant value failed
--> $DIR/issue-88434-removal-index-should-be-less.rs:3:24
|
LL | const _CONST: &[u8] = &f(&[], |_| {});
| ^^^^^^^^^^^^^^ evaluation panicked: explicit panic
|
note: inside `f::<{closure@$DIR/issue-88434-removal-index-should-be-less.rs:3:31: 3:34}>`
--> $DIR/issue-88434-removal-index-should-be-less.rs:10:5
|
LL | panic!()
| ^^^^^^^^ the failure occurred here
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
```
instead of
```
error[E0080]: evaluation of constant value failed
--> $DIR/issue-88434-removal-index-should-be-less.rs:10:5
|
LL | panic!()
| ^^^^^^^^ explicit panic
|
note: inside `f::<{closure@$DIR/issue-88434-removal-index-should-be-less.rs:3:31: 3:34}>`
--> $DIR/issue-88434-removal-index-should-be-less.rs:10:5
|
LL | panic!()
| ^^^^^^^^
note: inside `_CONST`
--> $DIR/issue-88434-removal-index-should-be-less.rs:3:24
|
LL | const _CONST: &[u8] = &f(&[], |_| {});
| ^^^^^^^^^^^^^^
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
```
---
Revert order of constant evaluation errors
Point at the code the user wrote first and std functions last.
```
error[E0080]: evaluation of constant value failed
--> $DIR/const-errs-dont-conflict-103369.rs:5:25
|
LL | impl ConstGenericTrait<{my_fn(1)}> for () {}
| ^^^^^^^^ evaluation panicked: Some error occurred
|
note: called from `my_fn`
--> $DIR/const-errs-dont-conflict-103369.rs:10:5
|
LL | panic!("Some error occurred");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
```
instead of
```
error[E0080]: evaluation of constant value failed
--> $DIR/const-errs-dont-conflict-103369.rs:10:5
|
LL | panic!("Some error occurred");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Some error occurred
|
note: called from `<() as ConstGenericTrait<{my_fn(1)}>>::{constant#0}`
--> $DIR/const-errs-dont-conflict-103369.rs:5:25
|
LL | impl ConstGenericTrait<{my_fn(1)}> for () {}
| ^^^^^^^^
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
```
2025-02-03 18:43:55 +00:00
|
|
|
MultiSpan, SubdiagMessageOp, Subdiagnostic,
|
2023-05-17 10:30:14 +00:00
|
|
|
};
|
2022-06-29 05:32:32 +00:00
|
|
|
use rustc_hir::ConstContext;
|
2023-05-17 10:30:14 +00:00
|
|
|
use rustc_macros::{Diagnostic, LintDiagnostic, Subdiagnostic};
|
|
|
|
use rustc_middle::mir::interpret::{
|
2024-10-19 06:49:13 +00:00
|
|
|
CheckInAllocMsg, CtfeProvenance, ExpectedKind, InterpErrorKind, InvalidMetaKind,
|
2024-07-27 16:09:50 +00:00
|
|
|
InvalidProgramInfo, Misalignment, Pointer, PointerKind, ResourceExhaustionInfo,
|
|
|
|
UndefinedBehaviorInfo, UnsupportedOpInfo, ValidationErrorInfo,
|
2023-05-17 10:30:14 +00:00
|
|
|
};
|
2024-02-27 18:11:23 +00:00
|
|
|
use rustc_middle::ty::{self, Mutability, Ty};
|
2024-10-06 17:59:19 +00:00
|
|
|
use rustc_span::{Span, Symbol};
|
2023-12-16 15:24:25 +00:00
|
|
|
|
Shorten span of panic failures in const context
Previously, we included a redundant prefix on the panic message and a postfix of the location of the panic. The prefix didn't carry any additional information beyond "something failed", and the location of the panic is redundant with the diagnostic's span, which gets printed out even if its code is not shown.
```
error[E0080]: evaluation of constant value failed
--> $DIR/assert-type-intrinsics.rs:11:9
|
LL | MaybeUninit::<!>::uninit().assume_init();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ evaluation panicked: aborted execution: attempted to instantiate uninhabited type `!`
```
```
error[E0080]: evaluation of `Fail::<i32>::C` failed
--> $DIR/collect-in-dead-closure.rs:9:19
|
LL | const C: () = panic!();
| ^^^^^^^^ evaluation panicked: explicit panic
|
= note: this error originates in the macro
`$crate::panic::panic_2015` which comes from the expansion of the macro
`panic` (in Nightly builds, run with -Z macro-backtrace for more info)
```
```
error[E0080]: evaluation of constant value failed
--> $DIR/uninhabited.rs:41:9
|
LL | assert!(false);
| ^^^^^^^^^^^^^^ evaluation panicked: assertion failed: false
|
= note: this error originates in the macro `assert` (in Nightly builds, run with -Z macro-backtrace for more info)
```
---
When the primary span for a const error is the same as the first frame in the const error report, skip it.
```
error[E0080]: evaluation of constant value failed
--> $DIR/issue-88434-removal-index-should-be-less.rs:3:24
|
LL | const _CONST: &[u8] = &f(&[], |_| {});
| ^^^^^^^^^^^^^^ evaluation panicked: explicit panic
|
note: inside `f::<{closure@$DIR/issue-88434-removal-index-should-be-less.rs:3:31: 3:34}>`
--> $DIR/issue-88434-removal-index-should-be-less.rs:10:5
|
LL | panic!()
| ^^^^^^^^ the failure occurred here
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
```
instead of
```
error[E0080]: evaluation of constant value failed
--> $DIR/issue-88434-removal-index-should-be-less.rs:10:5
|
LL | panic!()
| ^^^^^^^^ explicit panic
|
note: inside `f::<{closure@$DIR/issue-88434-removal-index-should-be-less.rs:3:31: 3:34}>`
--> $DIR/issue-88434-removal-index-should-be-less.rs:10:5
|
LL | panic!()
| ^^^^^^^^
note: inside `_CONST`
--> $DIR/issue-88434-removal-index-should-be-less.rs:3:24
|
LL | const _CONST: &[u8] = &f(&[], |_| {});
| ^^^^^^^^^^^^^^
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
```
---
Revert order of constant evaluation errors
Point at the code the user wrote first and std functions last.
```
error[E0080]: evaluation of constant value failed
--> $DIR/const-errs-dont-conflict-103369.rs:5:25
|
LL | impl ConstGenericTrait<{my_fn(1)}> for () {}
| ^^^^^^^^ evaluation panicked: Some error occurred
|
note: called from `my_fn`
--> $DIR/const-errs-dont-conflict-103369.rs:10:5
|
LL | panic!("Some error occurred");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
```
instead of
```
error[E0080]: evaluation of constant value failed
--> $DIR/const-errs-dont-conflict-103369.rs:10:5
|
LL | panic!("Some error occurred");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Some error occurred
|
note: called from `<() as ConstGenericTrait<{my_fn(1)}>>::{constant#0}`
--> $DIR/const-errs-dont-conflict-103369.rs:5:25
|
LL | impl ConstGenericTrait<{my_fn(1)}> for () {}
| ^^^^^^^^
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
```
2025-02-03 18:43:55 +00:00
|
|
|
use crate::fluent_generated as fluent;
|
2023-12-16 15:24:25 +00:00
|
|
|
use crate::interpret::InternKind;
|
2023-05-17 10:30:14 +00:00
|
|
|
|
|
|
|
#[derive(Diagnostic)]
|
|
|
|
#[diag(const_eval_dangling_ptr_in_final)]
|
|
|
|
pub(crate) struct DanglingPtrInFinal {
|
|
|
|
#[primary_span]
|
|
|
|
pub span: Span,
|
2023-12-16 15:24:25 +00:00
|
|
|
pub kind: InternKind,
|
|
|
|
}
|
|
|
|
|
2024-04-02 13:00:46 +00:00
|
|
|
#[derive(Diagnostic)]
|
|
|
|
#[diag(const_eval_nested_static_in_thread_local)]
|
|
|
|
pub(crate) struct NestedStaticInThreadLocal {
|
|
|
|
#[primary_span]
|
|
|
|
pub span: Span,
|
|
|
|
}
|
|
|
|
|
2024-08-02 13:34:59 +00:00
|
|
|
#[derive(Diagnostic)]
|
2023-12-16 15:24:25 +00:00
|
|
|
#[diag(const_eval_mutable_ptr_in_final)]
|
|
|
|
pub(crate) struct MutablePtrInFinal {
|
2024-08-02 13:34:59 +00:00
|
|
|
#[primary_span]
|
2023-12-16 15:24:25 +00:00
|
|
|
pub span: Span,
|
|
|
|
pub kind: InternKind,
|
2023-05-17 10:30:14 +00:00
|
|
|
}
|
2022-06-29 04:26:05 +00:00
|
|
|
|
2022-09-18 15:46:56 +00:00
|
|
|
#[derive(Diagnostic)]
|
2024-10-06 17:59:19 +00:00
|
|
|
#[diag(const_eval_unstable_in_stable_exposed)]
|
|
|
|
pub(crate) struct UnstableInStableExposed {
|
2022-06-29 04:26:05 +00:00
|
|
|
pub gate: String,
|
|
|
|
#[primary_span]
|
|
|
|
pub span: Span,
|
2024-10-06 17:59:19 +00:00
|
|
|
#[help(const_eval_is_function_call)]
|
|
|
|
pub is_function_call: bool,
|
|
|
|
/// Need to duplicate the field so that fluent also provides it as a variable...
|
|
|
|
pub is_function_call2: bool,
|
2022-06-29 04:26:05 +00:00
|
|
|
#[suggestion(
|
2022-10-13 09:13:02 +00:00
|
|
|
const_eval_unstable_sugg,
|
2022-06-29 04:26:05 +00:00
|
|
|
code = "#[rustc_const_unstable(feature = \"...\", issue = \"...\")]\n",
|
|
|
|
applicability = "has-placeholders"
|
|
|
|
)]
|
|
|
|
#[suggestion(
|
2022-10-13 09:13:02 +00:00
|
|
|
const_eval_bypass_sugg,
|
2022-06-29 04:26:05 +00:00
|
|
|
code = "#[rustc_allow_const_fn_unstable({gate})]\n",
|
|
|
|
applicability = "has-placeholders"
|
|
|
|
)]
|
|
|
|
pub attr_span: Span,
|
|
|
|
}
|
2022-06-29 04:46:01 +00:00
|
|
|
|
2022-09-18 15:46:56 +00:00
|
|
|
#[derive(Diagnostic)]
|
Stop using `String` for error codes.
Error codes are integers, but `String` is used everywhere to represent
them. Gross!
This commit introduces `ErrCode`, an integral newtype for error codes,
replacing `String`. It also introduces a constant for every error code,
e.g. `E0123`, and removes the `error_code!` macro. The constants are
imported wherever used with `use rustc_errors::codes::*`.
With the old code, we have three different ways to specify an error code
at a use point:
```
error_code!(E0123) // macro call
struct_span_code_err!(dcx, span, E0123, "msg"); // bare ident arg to macro call
\#[diag(name, code = "E0123")] // string
struct Diag;
```
With the new code, they all use the `E0123` constant.
```
E0123 // constant
struct_span_code_err!(dcx, span, E0123, "msg"); // constant
\#[diag(name, code = E0123)] // constant
struct Diag;
```
The commit also changes the structure of the error code definitions:
- `rustc_error_codes` now just defines a higher-order macro listing the
used error codes and nothing else.
- Because that's now the only thing in the `rustc_error_codes` crate, I
moved it into the `lib.rs` file and removed the `error_codes.rs` file.
- `rustc_errors` uses that macro to define everything, e.g. the error
code constants and the `DIAGNOSTIC_TABLES`. This is in its new
`codes.rs` file.
2024-01-13 23:57:07 +00:00
|
|
|
#[diag(const_eval_thread_local_access, code = E0625)]
|
2024-01-05 11:18:11 +00:00
|
|
|
pub(crate) struct ThreadLocalAccessErr {
|
2022-06-29 04:46:01 +00:00
|
|
|
#[primary_span]
|
|
|
|
pub span: Span,
|
|
|
|
}
|
2022-06-29 05:32:32 +00:00
|
|
|
|
2022-09-18 15:46:56 +00:00
|
|
|
#[derive(Diagnostic)]
|
2022-10-22 09:07:54 +00:00
|
|
|
#[diag(const_eval_raw_ptr_to_int)]
|
2022-06-29 05:46:25 +00:00
|
|
|
#[note]
|
2022-10-13 09:13:02 +00:00
|
|
|
#[note(const_eval_note2)]
|
2022-06-29 05:46:25 +00:00
|
|
|
pub(crate) struct RawPtrToIntErr {
|
|
|
|
#[primary_span]
|
|
|
|
pub span: Span,
|
|
|
|
}
|
|
|
|
|
2022-09-18 15:46:56 +00:00
|
|
|
#[derive(Diagnostic)]
|
2022-10-22 09:07:54 +00:00
|
|
|
#[diag(const_eval_raw_ptr_comparison)]
|
2022-06-29 05:46:25 +00:00
|
|
|
#[note]
|
|
|
|
pub(crate) struct RawPtrComparisonErr {
|
|
|
|
#[primary_span]
|
|
|
|
pub span: Span,
|
|
|
|
}
|
|
|
|
|
2022-09-18 15:46:56 +00:00
|
|
|
#[derive(Diagnostic)]
|
2022-10-22 09:07:54 +00:00
|
|
|
#[diag(const_eval_panic_non_str)]
|
2022-06-29 05:46:25 +00:00
|
|
|
pub(crate) struct PanicNonStrErr {
|
|
|
|
#[primary_span]
|
|
|
|
pub span: Span,
|
|
|
|
}
|
2022-06-29 06:22:15 +00:00
|
|
|
|
2022-09-18 15:46:56 +00:00
|
|
|
#[derive(Diagnostic)]
|
2022-10-22 09:07:54 +00:00
|
|
|
#[diag(const_eval_max_num_nodes_in_const)]
|
2022-08-20 19:27:41 +00:00
|
|
|
pub(crate) struct MaxNumNodesInConstErr {
|
2022-08-18 04:54:11 +00:00
|
|
|
#[primary_span]
|
2023-05-17 10:30:14 +00:00
|
|
|
pub span: Option<Span>,
|
2022-08-22 15:14:49 +00:00
|
|
|
pub global_const_id: String,
|
2022-08-18 04:54:11 +00:00
|
|
|
}
|
2022-08-18 05:11:52 +00:00
|
|
|
|
2022-09-18 15:46:56 +00:00
|
|
|
#[derive(Diagnostic)]
|
2022-10-22 09:07:54 +00:00
|
|
|
#[diag(const_eval_unallowed_fn_pointer_call)]
|
2022-08-18 05:11:52 +00:00
|
|
|
pub(crate) struct UnallowedFnPointerCall {
|
|
|
|
#[primary_span]
|
|
|
|
pub span: Span,
|
|
|
|
pub kind: ConstContext,
|
|
|
|
}
|
2022-08-19 01:49:59 +00:00
|
|
|
|
2022-09-18 15:46:56 +00:00
|
|
|
#[derive(Diagnostic)]
|
2022-10-22 09:07:54 +00:00
|
|
|
#[diag(const_eval_unstable_const_fn)]
|
2022-08-19 01:49:59 +00:00
|
|
|
pub(crate) struct UnstableConstFn {
|
|
|
|
#[primary_span]
|
|
|
|
pub span: Span,
|
2022-08-20 19:27:41 +00:00
|
|
|
pub def_path: String,
|
2022-08-19 01:49:59 +00:00
|
|
|
}
|
2022-08-19 18:36:09 +00:00
|
|
|
|
2025-01-25 13:38:15 +00:00
|
|
|
#[derive(Diagnostic)]
|
|
|
|
#[diag(const_eval_unstable_const_trait)]
|
|
|
|
pub(crate) struct UnstableConstTrait {
|
|
|
|
#[primary_span]
|
|
|
|
pub span: Span,
|
|
|
|
pub def_path: String,
|
|
|
|
}
|
|
|
|
|
2024-10-06 17:59:19 +00:00
|
|
|
#[derive(Diagnostic)]
|
|
|
|
#[diag(const_eval_unstable_intrinsic)]
|
|
|
|
pub(crate) struct UnstableIntrinsic {
|
|
|
|
#[primary_span]
|
|
|
|
pub span: Span,
|
|
|
|
pub name: Symbol,
|
|
|
|
pub feature: Symbol,
|
2024-12-28 18:37:16 +00:00
|
|
|
#[suggestion(
|
|
|
|
const_eval_unstable_intrinsic_suggestion,
|
|
|
|
code = "#![feature({feature})]\n",
|
|
|
|
applicability = "machine-applicable"
|
|
|
|
)]
|
|
|
|
pub suggestion: Option<Span>,
|
|
|
|
#[help(const_eval_unstable_intrinsic_suggestion)]
|
|
|
|
pub help: bool,
|
2024-10-06 17:59:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Diagnostic)]
|
2025-01-25 13:38:15 +00:00
|
|
|
#[diag(const_eval_unmarked_const_item_exposed)]
|
2024-10-06 17:59:19 +00:00
|
|
|
#[help]
|
2025-01-25 13:38:15 +00:00
|
|
|
pub(crate) struct UnmarkedConstItemExposed {
|
2024-10-06 17:59:19 +00:00
|
|
|
#[primary_span]
|
|
|
|
pub span: Span,
|
|
|
|
pub def_path: String,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Diagnostic)]
|
|
|
|
#[diag(const_eval_unmarked_intrinsic_exposed)]
|
|
|
|
#[help]
|
|
|
|
pub(crate) struct UnmarkedIntrinsicExposed {
|
|
|
|
#[primary_span]
|
|
|
|
pub span: Span,
|
|
|
|
pub def_path: String,
|
|
|
|
}
|
|
|
|
|
2022-09-18 15:46:56 +00:00
|
|
|
#[derive(Diagnostic)]
|
2024-10-08 10:25:26 +00:00
|
|
|
#[diag(const_eval_mutable_ref_escaping, code = E0764)]
|
|
|
|
pub(crate) struct MutableRefEscaping {
|
2022-08-19 18:36:09 +00:00
|
|
|
#[primary_span]
|
|
|
|
pub span: Span,
|
|
|
|
pub kind: ConstContext,
|
2022-10-13 09:13:02 +00:00
|
|
|
#[note(const_eval_teach_note)]
|
2024-08-21 04:57:58 +00:00
|
|
|
pub teach: bool,
|
2022-08-19 18:36:09 +00:00
|
|
|
}
|
|
|
|
|
2022-09-18 15:46:56 +00:00
|
|
|
#[derive(Diagnostic)]
|
2024-10-08 10:25:26 +00:00
|
|
|
#[diag(const_eval_mutable_raw_escaping, code = E0764)]
|
|
|
|
pub(crate) struct MutableRawEscaping {
|
2022-08-19 18:36:09 +00:00
|
|
|
#[primary_span]
|
|
|
|
pub span: Span,
|
|
|
|
pub kind: ConstContext,
|
2022-10-13 09:13:02 +00:00
|
|
|
#[note(const_eval_teach_note)]
|
2024-08-21 04:57:58 +00:00
|
|
|
pub teach: bool,
|
2022-08-19 18:36:09 +00:00
|
|
|
}
|
2022-09-18 15:46:56 +00:00
|
|
|
#[derive(Diagnostic)]
|
Stop using `String` for error codes.
Error codes are integers, but `String` is used everywhere to represent
them. Gross!
This commit introduces `ErrCode`, an integral newtype for error codes,
replacing `String`. It also introduces a constant for every error code,
e.g. `E0123`, and removes the `error_code!` macro. The constants are
imported wherever used with `use rustc_errors::codes::*`.
With the old code, we have three different ways to specify an error code
at a use point:
```
error_code!(E0123) // macro call
struct_span_code_err!(dcx, span, E0123, "msg"); // bare ident arg to macro call
\#[diag(name, code = "E0123")] // string
struct Diag;
```
With the new code, they all use the `E0123` constant.
```
E0123 // constant
struct_span_code_err!(dcx, span, E0123, "msg"); // constant
\#[diag(name, code = E0123)] // constant
struct Diag;
```
The commit also changes the structure of the error code definitions:
- `rustc_error_codes` now just defines a higher-order macro listing the
used error codes and nothing else.
- Because that's now the only thing in the `rustc_error_codes` crate, I
moved it into the `lib.rs` file and removed the `error_codes.rs` file.
- `rustc_errors` uses that macro to define everything, e.g. the error
code constants and the `DIAGNOSTIC_TABLES`. This is in its new
`codes.rs` file.
2024-01-13 23:57:07 +00:00
|
|
|
#[diag(const_eval_non_const_fmt_macro_call, code = E0015)]
|
2022-08-19 18:36:09 +00:00
|
|
|
pub(crate) struct NonConstFmtMacroCall {
|
|
|
|
#[primary_span]
|
|
|
|
pub span: Span,
|
|
|
|
pub kind: ConstContext,
|
2024-12-23 21:53:07 +00:00
|
|
|
pub non_or_conditionally: &'static str,
|
2024-11-09 21:19:35 +00:00
|
|
|
}
|
|
|
|
|
2022-09-18 15:46:56 +00:00
|
|
|
#[derive(Diagnostic)]
|
Stop using `String` for error codes.
Error codes are integers, but `String` is used everywhere to represent
them. Gross!
This commit introduces `ErrCode`, an integral newtype for error codes,
replacing `String`. It also introduces a constant for every error code,
e.g. `E0123`, and removes the `error_code!` macro. The constants are
imported wherever used with `use rustc_errors::codes::*`.
With the old code, we have three different ways to specify an error code
at a use point:
```
error_code!(E0123) // macro call
struct_span_code_err!(dcx, span, E0123, "msg"); // bare ident arg to macro call
\#[diag(name, code = "E0123")] // string
struct Diag;
```
With the new code, they all use the `E0123` constant.
```
E0123 // constant
struct_span_code_err!(dcx, span, E0123, "msg"); // constant
\#[diag(name, code = E0123)] // constant
struct Diag;
```
The commit also changes the structure of the error code definitions:
- `rustc_error_codes` now just defines a higher-order macro listing the
used error codes and nothing else.
- Because that's now the only thing in the `rustc_error_codes` crate, I
moved it into the `lib.rs` file and removed the `error_codes.rs` file.
- `rustc_errors` uses that macro to define everything, e.g. the error
code constants and the `DIAGNOSTIC_TABLES`. This is in its new
`codes.rs` file.
2024-01-13 23:57:07 +00:00
|
|
|
#[diag(const_eval_non_const_fn_call, code = E0015)]
|
2022-08-19 18:36:09 +00:00
|
|
|
pub(crate) struct NonConstFnCall {
|
|
|
|
#[primary_span]
|
|
|
|
pub span: Span,
|
|
|
|
pub def_path_str: String,
|
2024-12-23 21:49:48 +00:00
|
|
|
pub def_descr: &'static str,
|
2022-08-19 18:36:09 +00:00
|
|
|
pub kind: ConstContext,
|
2024-12-23 21:53:07 +00:00
|
|
|
pub non_or_conditionally: &'static str,
|
2022-08-19 18:36:09 +00:00
|
|
|
}
|
|
|
|
|
2024-10-06 17:59:19 +00:00
|
|
|
#[derive(Diagnostic)]
|
|
|
|
#[diag(const_eval_non_const_intrinsic)]
|
|
|
|
pub(crate) struct NonConstIntrinsic {
|
|
|
|
#[primary_span]
|
|
|
|
pub span: Span,
|
|
|
|
pub name: Symbol,
|
|
|
|
pub kind: ConstContext,
|
|
|
|
}
|
|
|
|
|
2022-09-18 15:46:56 +00:00
|
|
|
#[derive(Diagnostic)]
|
2022-10-22 09:07:54 +00:00
|
|
|
#[diag(const_eval_unallowed_op_in_const_context)]
|
2022-08-19 18:36:09 +00:00
|
|
|
pub(crate) struct UnallowedOpInConstContext {
|
|
|
|
#[primary_span]
|
|
|
|
pub span: Span,
|
|
|
|
pub msg: String,
|
|
|
|
}
|
|
|
|
|
2022-09-18 15:46:56 +00:00
|
|
|
#[derive(Diagnostic)]
|
Stop using `String` for error codes.
Error codes are integers, but `String` is used everywhere to represent
them. Gross!
This commit introduces `ErrCode`, an integral newtype for error codes,
replacing `String`. It also introduces a constant for every error code,
e.g. `E0123`, and removes the `error_code!` macro. The constants are
imported wherever used with `use rustc_errors::codes::*`.
With the old code, we have three different ways to specify an error code
at a use point:
```
error_code!(E0123) // macro call
struct_span_code_err!(dcx, span, E0123, "msg"); // bare ident arg to macro call
\#[diag(name, code = "E0123")] // string
struct Diag;
```
With the new code, they all use the `E0123` constant.
```
E0123 // constant
struct_span_code_err!(dcx, span, E0123, "msg"); // constant
\#[diag(name, code = E0123)] // constant
struct Diag;
```
The commit also changes the structure of the error code definitions:
- `rustc_error_codes` now just defines a higher-order macro listing the
used error codes and nothing else.
- Because that's now the only thing in the `rustc_error_codes` crate, I
moved it into the `lib.rs` file and removed the `error_codes.rs` file.
- `rustc_errors` uses that macro to define everything, e.g. the error
code constants and the `DIAGNOSTIC_TABLES`. This is in its new
`codes.rs` file.
2024-01-13 23:57:07 +00:00
|
|
|
#[diag(const_eval_unallowed_heap_allocations, code = E0010)]
|
2022-08-19 18:36:09 +00:00
|
|
|
pub(crate) struct UnallowedHeapAllocations {
|
|
|
|
#[primary_span]
|
2022-08-20 19:27:41 +00:00
|
|
|
#[label]
|
2022-08-19 18:36:09 +00:00
|
|
|
pub span: Span,
|
|
|
|
pub kind: ConstContext,
|
2022-10-13 09:13:02 +00:00
|
|
|
#[note(const_eval_teach_note)]
|
2024-08-21 04:57:58 +00:00
|
|
|
pub teach: bool,
|
2022-08-19 18:36:09 +00:00
|
|
|
}
|
|
|
|
|
2022-09-18 15:46:56 +00:00
|
|
|
#[derive(Diagnostic)]
|
Stop using `String` for error codes.
Error codes are integers, but `String` is used everywhere to represent
them. Gross!
This commit introduces `ErrCode`, an integral newtype for error codes,
replacing `String`. It also introduces a constant for every error code,
e.g. `E0123`, and removes the `error_code!` macro. The constants are
imported wherever used with `use rustc_errors::codes::*`.
With the old code, we have three different ways to specify an error code
at a use point:
```
error_code!(E0123) // macro call
struct_span_code_err!(dcx, span, E0123, "msg"); // bare ident arg to macro call
\#[diag(name, code = "E0123")] // string
struct Diag;
```
With the new code, they all use the `E0123` constant.
```
E0123 // constant
struct_span_code_err!(dcx, span, E0123, "msg"); // constant
\#[diag(name, code = E0123)] // constant
struct Diag;
```
The commit also changes the structure of the error code definitions:
- `rustc_error_codes` now just defines a higher-order macro listing the
used error codes and nothing else.
- Because that's now the only thing in the `rustc_error_codes` crate, I
moved it into the `lib.rs` file and removed the `error_codes.rs` file.
- `rustc_errors` uses that macro to define everything, e.g. the error
code constants and the `DIAGNOSTIC_TABLES`. This is in its new
`codes.rs` file.
2024-01-13 23:57:07 +00:00
|
|
|
#[diag(const_eval_unallowed_inline_asm, code = E0015)]
|
2022-08-19 18:36:09 +00:00
|
|
|
pub(crate) struct UnallowedInlineAsm {
|
|
|
|
#[primary_span]
|
|
|
|
pub span: Span,
|
|
|
|
pub kind: ConstContext,
|
|
|
|
}
|
|
|
|
|
2022-09-18 15:46:56 +00:00
|
|
|
#[derive(Diagnostic)]
|
2024-10-08 10:25:26 +00:00
|
|
|
#[diag(const_eval_interior_mutable_ref_escaping, code = E0492)]
|
|
|
|
pub(crate) struct InteriorMutableRefEscaping {
|
2022-08-19 18:36:09 +00:00
|
|
|
#[primary_span]
|
2022-08-20 19:27:41 +00:00
|
|
|
#[label]
|
2022-08-19 18:36:09 +00:00
|
|
|
pub span: Span,
|
|
|
|
#[help]
|
2024-08-21 04:57:58 +00:00
|
|
|
pub opt_help: bool,
|
2022-08-19 18:36:09 +00:00
|
|
|
pub kind: ConstContext,
|
2022-10-13 09:13:02 +00:00
|
|
|
#[note(const_eval_teach_note)]
|
2024-08-21 04:57:58 +00:00
|
|
|
pub teach: bool,
|
2022-08-19 18:36:09 +00:00
|
|
|
}
|
|
|
|
|
2022-11-02 11:57:40 +00:00
|
|
|
#[derive(LintDiagnostic)]
|
|
|
|
#[diag(const_eval_long_running)]
|
|
|
|
#[note]
|
|
|
|
pub struct LongRunning {
|
|
|
|
#[help]
|
|
|
|
pub item_span: Span,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Diagnostic)]
|
|
|
|
#[diag(const_eval_long_running)]
|
|
|
|
pub struct LongRunningWarn {
|
|
|
|
#[primary_span]
|
|
|
|
#[label]
|
|
|
|
pub span: Span,
|
|
|
|
#[help]
|
|
|
|
pub item_span: Span,
|
2024-09-21 15:23:34 +00:00
|
|
|
// Used for evading `-Z deduplicate-diagnostics`.
|
|
|
|
pub force_duplicate: usize,
|
2022-11-02 11:57:40 +00:00
|
|
|
}
|
2023-05-17 10:30:14 +00:00
|
|
|
|
|
|
|
#[derive(Subdiagnostic)]
|
|
|
|
#[note(const_eval_non_const_impl)]
|
|
|
|
pub(crate) struct NonConstImplNote {
|
|
|
|
#[primary_span]
|
|
|
|
pub span: Span,
|
|
|
|
}
|
|
|
|
|
Shorten span of panic failures in const context
Previously, we included a redundant prefix on the panic message and a postfix of the location of the panic. The prefix didn't carry any additional information beyond "something failed", and the location of the panic is redundant with the diagnostic's span, which gets printed out even if its code is not shown.
```
error[E0080]: evaluation of constant value failed
--> $DIR/assert-type-intrinsics.rs:11:9
|
LL | MaybeUninit::<!>::uninit().assume_init();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ evaluation panicked: aborted execution: attempted to instantiate uninhabited type `!`
```
```
error[E0080]: evaluation of `Fail::<i32>::C` failed
--> $DIR/collect-in-dead-closure.rs:9:19
|
LL | const C: () = panic!();
| ^^^^^^^^ evaluation panicked: explicit panic
|
= note: this error originates in the macro
`$crate::panic::panic_2015` which comes from the expansion of the macro
`panic` (in Nightly builds, run with -Z macro-backtrace for more info)
```
```
error[E0080]: evaluation of constant value failed
--> $DIR/uninhabited.rs:41:9
|
LL | assert!(false);
| ^^^^^^^^^^^^^^ evaluation panicked: assertion failed: false
|
= note: this error originates in the macro `assert` (in Nightly builds, run with -Z macro-backtrace for more info)
```
---
When the primary span for a const error is the same as the first frame in the const error report, skip it.
```
error[E0080]: evaluation of constant value failed
--> $DIR/issue-88434-removal-index-should-be-less.rs:3:24
|
LL | const _CONST: &[u8] = &f(&[], |_| {});
| ^^^^^^^^^^^^^^ evaluation panicked: explicit panic
|
note: inside `f::<{closure@$DIR/issue-88434-removal-index-should-be-less.rs:3:31: 3:34}>`
--> $DIR/issue-88434-removal-index-should-be-less.rs:10:5
|
LL | panic!()
| ^^^^^^^^ the failure occurred here
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
```
instead of
```
error[E0080]: evaluation of constant value failed
--> $DIR/issue-88434-removal-index-should-be-less.rs:10:5
|
LL | panic!()
| ^^^^^^^^ explicit panic
|
note: inside `f::<{closure@$DIR/issue-88434-removal-index-should-be-less.rs:3:31: 3:34}>`
--> $DIR/issue-88434-removal-index-should-be-less.rs:10:5
|
LL | panic!()
| ^^^^^^^^
note: inside `_CONST`
--> $DIR/issue-88434-removal-index-should-be-less.rs:3:24
|
LL | const _CONST: &[u8] = &f(&[], |_| {});
| ^^^^^^^^^^^^^^
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
```
---
Revert order of constant evaluation errors
Point at the code the user wrote first and std functions last.
```
error[E0080]: evaluation of constant value failed
--> $DIR/const-errs-dont-conflict-103369.rs:5:25
|
LL | impl ConstGenericTrait<{my_fn(1)}> for () {}
| ^^^^^^^^ evaluation panicked: Some error occurred
|
note: called from `my_fn`
--> $DIR/const-errs-dont-conflict-103369.rs:10:5
|
LL | panic!("Some error occurred");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
```
instead of
```
error[E0080]: evaluation of constant value failed
--> $DIR/const-errs-dont-conflict-103369.rs:10:5
|
LL | panic!("Some error occurred");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Some error occurred
|
note: called from `<() as ConstGenericTrait<{my_fn(1)}>>::{constant#0}`
--> $DIR/const-errs-dont-conflict-103369.rs:5:25
|
LL | impl ConstGenericTrait<{my_fn(1)}> for () {}
| ^^^^^^^^
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
```
2025-02-03 18:43:55 +00:00
|
|
|
#[derive(Clone)]
|
2023-05-17 10:30:14 +00:00
|
|
|
pub struct FrameNote {
|
|
|
|
pub span: Span,
|
|
|
|
pub times: i32,
|
|
|
|
pub where_: &'static str,
|
|
|
|
pub instance: String,
|
Shorten span of panic failures in const context
Previously, we included a redundant prefix on the panic message and a postfix of the location of the panic. The prefix didn't carry any additional information beyond "something failed", and the location of the panic is redundant with the diagnostic's span, which gets printed out even if its code is not shown.
```
error[E0080]: evaluation of constant value failed
--> $DIR/assert-type-intrinsics.rs:11:9
|
LL | MaybeUninit::<!>::uninit().assume_init();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ evaluation panicked: aborted execution: attempted to instantiate uninhabited type `!`
```
```
error[E0080]: evaluation of `Fail::<i32>::C` failed
--> $DIR/collect-in-dead-closure.rs:9:19
|
LL | const C: () = panic!();
| ^^^^^^^^ evaluation panicked: explicit panic
|
= note: this error originates in the macro
`$crate::panic::panic_2015` which comes from the expansion of the macro
`panic` (in Nightly builds, run with -Z macro-backtrace for more info)
```
```
error[E0080]: evaluation of constant value failed
--> $DIR/uninhabited.rs:41:9
|
LL | assert!(false);
| ^^^^^^^^^^^^^^ evaluation panicked: assertion failed: false
|
= note: this error originates in the macro `assert` (in Nightly builds, run with -Z macro-backtrace for more info)
```
---
When the primary span for a const error is the same as the first frame in the const error report, skip it.
```
error[E0080]: evaluation of constant value failed
--> $DIR/issue-88434-removal-index-should-be-less.rs:3:24
|
LL | const _CONST: &[u8] = &f(&[], |_| {});
| ^^^^^^^^^^^^^^ evaluation panicked: explicit panic
|
note: inside `f::<{closure@$DIR/issue-88434-removal-index-should-be-less.rs:3:31: 3:34}>`
--> $DIR/issue-88434-removal-index-should-be-less.rs:10:5
|
LL | panic!()
| ^^^^^^^^ the failure occurred here
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
```
instead of
```
error[E0080]: evaluation of constant value failed
--> $DIR/issue-88434-removal-index-should-be-less.rs:10:5
|
LL | panic!()
| ^^^^^^^^ explicit panic
|
note: inside `f::<{closure@$DIR/issue-88434-removal-index-should-be-less.rs:3:31: 3:34}>`
--> $DIR/issue-88434-removal-index-should-be-less.rs:10:5
|
LL | panic!()
| ^^^^^^^^
note: inside `_CONST`
--> $DIR/issue-88434-removal-index-should-be-less.rs:3:24
|
LL | const _CONST: &[u8] = &f(&[], |_| {});
| ^^^^^^^^^^^^^^
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
```
---
Revert order of constant evaluation errors
Point at the code the user wrote first and std functions last.
```
error[E0080]: evaluation of constant value failed
--> $DIR/const-errs-dont-conflict-103369.rs:5:25
|
LL | impl ConstGenericTrait<{my_fn(1)}> for () {}
| ^^^^^^^^ evaluation panicked: Some error occurred
|
note: called from `my_fn`
--> $DIR/const-errs-dont-conflict-103369.rs:10:5
|
LL | panic!("Some error occurred");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
```
instead of
```
error[E0080]: evaluation of constant value failed
--> $DIR/const-errs-dont-conflict-103369.rs:10:5
|
LL | panic!("Some error occurred");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Some error occurred
|
note: called from `<() as ConstGenericTrait<{my_fn(1)}>>::{constant#0}`
--> $DIR/const-errs-dont-conflict-103369.rs:5:25
|
LL | impl ConstGenericTrait<{my_fn(1)}> for () {}
| ^^^^^^^^
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
```
2025-02-03 18:43:55 +00:00
|
|
|
pub has_label: bool,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Subdiagnostic for FrameNote {
|
|
|
|
fn add_to_diag_with<G: EmissionGuarantee, F: SubdiagMessageOp<G>>(
|
|
|
|
self,
|
|
|
|
diag: &mut Diag<'_, G>,
|
|
|
|
f: &F,
|
|
|
|
) {
|
|
|
|
diag.arg("times", self.times);
|
|
|
|
diag.arg("where_", self.where_);
|
|
|
|
diag.arg("instance", self.instance);
|
|
|
|
let mut span: MultiSpan = self.span.into();
|
|
|
|
if self.has_label && !self.span.is_dummy() {
|
|
|
|
span.push_span_label(self.span, fluent::const_eval_frame_note_last);
|
|
|
|
}
|
|
|
|
let msg = f(diag, fluent::const_eval_frame_note.into());
|
|
|
|
diag.span_note(span, msg);
|
|
|
|
}
|
2023-05-17 10:30:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Subdiagnostic)]
|
|
|
|
#[note(const_eval_raw_bytes)]
|
|
|
|
pub struct RawBytesNote {
|
|
|
|
pub size: u64,
|
|
|
|
pub align: u64,
|
|
|
|
pub bytes: String,
|
|
|
|
}
|
|
|
|
|
2023-06-18 05:24:38 +00:00
|
|
|
// FIXME(fee1-dead) do not use stringly typed `ConstContext`
|
|
|
|
|
|
|
|
#[derive(Diagnostic)]
|
2024-12-23 21:17:36 +00:00
|
|
|
#[diag(const_eval_non_const_match_eq, code = E0015)]
|
2023-06-18 05:24:38 +00:00
|
|
|
#[note]
|
|
|
|
pub struct NonConstMatchEq<'tcx> {
|
|
|
|
#[primary_span]
|
|
|
|
pub span: Span,
|
|
|
|
pub ty: Ty<'tcx>,
|
|
|
|
pub kind: ConstContext,
|
2024-12-23 21:53:07 +00:00
|
|
|
pub non_or_conditionally: &'static str,
|
2023-06-18 05:24:38 +00:00
|
|
|
}
|
|
|
|
|
2023-05-17 10:30:14 +00:00
|
|
|
#[derive(Diagnostic)]
|
2024-12-23 21:17:36 +00:00
|
|
|
#[diag(const_eval_non_const_for_loop_into_iter, code = E0015)]
|
2023-05-17 10:30:14 +00:00
|
|
|
pub struct NonConstForLoopIntoIter<'tcx> {
|
|
|
|
#[primary_span]
|
|
|
|
pub span: Span,
|
|
|
|
pub ty: Ty<'tcx>,
|
|
|
|
pub kind: ConstContext,
|
2024-12-23 21:53:07 +00:00
|
|
|
pub non_or_conditionally: &'static str,
|
2023-05-17 10:30:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Diagnostic)]
|
2024-12-23 21:17:36 +00:00
|
|
|
#[diag(const_eval_non_const_question_branch, code = E0015)]
|
2023-05-17 10:30:14 +00:00
|
|
|
pub struct NonConstQuestionBranch<'tcx> {
|
|
|
|
#[primary_span]
|
|
|
|
pub span: Span,
|
|
|
|
pub ty: Ty<'tcx>,
|
|
|
|
pub kind: ConstContext,
|
2024-12-23 21:53:07 +00:00
|
|
|
pub non_or_conditionally: &'static str,
|
2023-05-17 10:30:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Diagnostic)]
|
2024-12-23 21:17:36 +00:00
|
|
|
#[diag(const_eval_non_const_question_from_residual, code = E0015)]
|
2023-05-17 10:30:14 +00:00
|
|
|
pub struct NonConstQuestionFromResidual<'tcx> {
|
|
|
|
#[primary_span]
|
|
|
|
pub span: Span,
|
|
|
|
pub ty: Ty<'tcx>,
|
|
|
|
pub kind: ConstContext,
|
2024-12-23 21:53:07 +00:00
|
|
|
pub non_or_conditionally: &'static str,
|
2023-05-17 10:30:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Diagnostic)]
|
2024-12-23 21:17:36 +00:00
|
|
|
#[diag(const_eval_non_const_try_block_from_output, code = E0015)]
|
2023-05-17 10:30:14 +00:00
|
|
|
pub struct NonConstTryBlockFromOutput<'tcx> {
|
|
|
|
#[primary_span]
|
|
|
|
pub span: Span,
|
|
|
|
pub ty: Ty<'tcx>,
|
|
|
|
pub kind: ConstContext,
|
2024-12-23 21:53:07 +00:00
|
|
|
pub non_or_conditionally: &'static str,
|
2023-05-17 10:30:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Diagnostic)]
|
2024-12-23 21:17:36 +00:00
|
|
|
#[diag(const_eval_non_const_await, code = E0015)]
|
2023-05-17 10:30:14 +00:00
|
|
|
pub struct NonConstAwait<'tcx> {
|
|
|
|
#[primary_span]
|
|
|
|
pub span: Span,
|
|
|
|
pub ty: Ty<'tcx>,
|
|
|
|
pub kind: ConstContext,
|
2024-12-23 21:53:07 +00:00
|
|
|
pub non_or_conditionally: &'static str,
|
2023-05-17 10:30:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Diagnostic)]
|
2024-12-23 21:17:36 +00:00
|
|
|
#[diag(const_eval_non_const_closure, code = E0015)]
|
2023-05-17 10:30:14 +00:00
|
|
|
pub struct NonConstClosure {
|
|
|
|
#[primary_span]
|
|
|
|
pub span: Span,
|
|
|
|
pub kind: ConstContext,
|
|
|
|
#[subdiagnostic]
|
|
|
|
pub note: Option<NonConstClosureNote>,
|
2024-12-23 21:53:07 +00:00
|
|
|
pub non_or_conditionally: &'static str,
|
2023-05-17 10:30:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Subdiagnostic)]
|
|
|
|
pub enum NonConstClosureNote {
|
|
|
|
#[note(const_eval_closure_fndef_not_const)]
|
|
|
|
FnDef {
|
|
|
|
#[primary_span]
|
|
|
|
span: Span,
|
|
|
|
},
|
|
|
|
#[note(const_eval_fn_ptr_call)]
|
|
|
|
FnPtr,
|
|
|
|
#[note(const_eval_closure_call)]
|
|
|
|
Closure,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Subdiagnostic)]
|
|
|
|
#[multipart_suggestion(const_eval_consider_dereferencing, applicability = "machine-applicable")]
|
|
|
|
pub struct ConsiderDereferencing {
|
|
|
|
pub deref: String,
|
|
|
|
#[suggestion_part(code = "{deref}")]
|
|
|
|
pub span: Span,
|
|
|
|
#[suggestion_part(code = "{deref}")]
|
|
|
|
pub rhs_span: Span,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Diagnostic)]
|
2024-12-23 21:17:36 +00:00
|
|
|
#[diag(const_eval_non_const_operator, code = E0015)]
|
2023-05-17 10:30:14 +00:00
|
|
|
pub struct NonConstOperator {
|
|
|
|
#[primary_span]
|
|
|
|
pub span: Span,
|
|
|
|
pub kind: ConstContext,
|
|
|
|
#[subdiagnostic]
|
|
|
|
pub sugg: Option<ConsiderDereferencing>,
|
2024-12-23 21:53:07 +00:00
|
|
|
pub non_or_conditionally: &'static str,
|
2023-05-17 10:30:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Diagnostic)]
|
2024-12-23 21:17:36 +00:00
|
|
|
#[diag(const_eval_non_const_deref_coercion, code = E0015)]
|
2023-05-17 10:30:14 +00:00
|
|
|
#[note]
|
|
|
|
pub struct NonConstDerefCoercion<'tcx> {
|
|
|
|
#[primary_span]
|
|
|
|
pub span: Span,
|
|
|
|
pub ty: Ty<'tcx>,
|
|
|
|
pub kind: ConstContext,
|
|
|
|
pub target_ty: Ty<'tcx>,
|
|
|
|
#[note(const_eval_target_note)]
|
|
|
|
pub deref_target: Option<Span>,
|
2024-12-23 21:53:07 +00:00
|
|
|
pub non_or_conditionally: &'static str,
|
2023-05-17 10:30:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Diagnostic)]
|
Stop using `String` for error codes.
Error codes are integers, but `String` is used everywhere to represent
them. Gross!
This commit introduces `ErrCode`, an integral newtype for error codes,
replacing `String`. It also introduces a constant for every error code,
e.g. `E0123`, and removes the `error_code!` macro. The constants are
imported wherever used with `use rustc_errors::codes::*`.
With the old code, we have three different ways to specify an error code
at a use point:
```
error_code!(E0123) // macro call
struct_span_code_err!(dcx, span, E0123, "msg"); // bare ident arg to macro call
\#[diag(name, code = "E0123")] // string
struct Diag;
```
With the new code, they all use the `E0123` constant.
```
E0123 // constant
struct_span_code_err!(dcx, span, E0123, "msg"); // constant
\#[diag(name, code = E0123)] // constant
struct Diag;
```
The commit also changes the structure of the error code definitions:
- `rustc_error_codes` now just defines a higher-order macro listing the
used error codes and nothing else.
- Because that's now the only thing in the `rustc_error_codes` crate, I
moved it into the `lib.rs` file and removed the `error_codes.rs` file.
- `rustc_errors` uses that macro to define everything, e.g. the error
code constants and the `DIAGNOSTIC_TABLES`. This is in its new
`codes.rs` file.
2024-01-13 23:57:07 +00:00
|
|
|
#[diag(const_eval_live_drop, code = E0493)]
|
2023-05-17 10:30:14 +00:00
|
|
|
pub struct LiveDrop<'tcx> {
|
|
|
|
#[primary_span]
|
|
|
|
#[label]
|
|
|
|
pub span: Span,
|
|
|
|
pub kind: ConstContext,
|
|
|
|
pub dropped_ty: Ty<'tcx>,
|
|
|
|
#[label(const_eval_dropped_at_label)]
|
2024-11-19 17:18:54 +00:00
|
|
|
pub dropped_at: Span,
|
2023-05-17 10:30:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Diagnostic)]
|
Stop using `String` for error codes.
Error codes are integers, but `String` is used everywhere to represent
them. Gross!
This commit introduces `ErrCode`, an integral newtype for error codes,
replacing `String`. It also introduces a constant for every error code,
e.g. `E0123`, and removes the `error_code!` macro. The constants are
imported wherever used with `use rustc_errors::codes::*`.
With the old code, we have three different ways to specify an error code
at a use point:
```
error_code!(E0123) // macro call
struct_span_code_err!(dcx, span, E0123, "msg"); // bare ident arg to macro call
\#[diag(name, code = "E0123")] // string
struct Diag;
```
With the new code, they all use the `E0123` constant.
```
E0123 // constant
struct_span_code_err!(dcx, span, E0123, "msg"); // constant
\#[diag(name, code = E0123)] // constant
struct Diag;
```
The commit also changes the structure of the error code definitions:
- `rustc_error_codes` now just defines a higher-order macro listing the
used error codes and nothing else.
- Because that's now the only thing in the `rustc_error_codes` crate, I
moved it into the `lib.rs` file and removed the `error_codes.rs` file.
- `rustc_errors` uses that macro to define everything, e.g. the error
code constants and the `DIAGNOSTIC_TABLES`. This is in its new
`codes.rs` file.
2024-01-13 23:57:07 +00:00
|
|
|
#[diag(const_eval_error, code = E0080)]
|
2023-05-17 10:30:14 +00:00
|
|
|
pub struct ConstEvalError {
|
|
|
|
#[primary_span]
|
|
|
|
pub span: Span,
|
|
|
|
/// One of "const", "const_with_path", and "static"
|
|
|
|
pub error_kind: &'static str,
|
|
|
|
pub instance: String,
|
|
|
|
#[subdiagnostic]
|
|
|
|
pub frame_notes: Vec<FrameNote>,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Diagnostic)]
|
|
|
|
#[diag(const_eval_nullary_intrinsic_fail)]
|
|
|
|
pub struct NullaryIntrinsicError {
|
|
|
|
#[primary_span]
|
|
|
|
pub span: Span,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Diagnostic)]
|
2024-03-13 09:25:20 +00:00
|
|
|
#[diag(const_eval_validation_failure, code = E0080)]
|
|
|
|
pub struct ValidationFailure {
|
2023-05-17 10:30:14 +00:00
|
|
|
#[primary_span]
|
|
|
|
pub span: Span,
|
2024-03-13 09:25:20 +00:00
|
|
|
#[note(const_eval_validation_failure_note)]
|
2024-06-22 14:26:30 +00:00
|
|
|
pub ub_note: (),
|
2023-05-17 10:30:14 +00:00
|
|
|
#[subdiagnostic]
|
|
|
|
pub frames: Vec<FrameNote>,
|
|
|
|
#[subdiagnostic]
|
|
|
|
pub raw_bytes: RawBytesNote,
|
|
|
|
}
|
|
|
|
|
|
|
|
pub trait ReportErrorExt {
|
|
|
|
/// Returns the diagnostic message for this error.
|
2024-02-29 00:58:51 +00:00
|
|
|
fn diagnostic_message(&self) -> DiagMessage;
|
2024-02-22 23:20:45 +00:00
|
|
|
fn add_args<G: EmissionGuarantee>(self, diag: &mut Diag<'_, G>);
|
2023-05-29 03:32:38 +00:00
|
|
|
|
2023-05-29 06:40:15 +00:00
|
|
|
fn debug(self) -> String
|
2023-05-29 03:32:38 +00:00
|
|
|
where
|
|
|
|
Self: Sized,
|
|
|
|
{
|
2023-05-29 06:40:15 +00:00
|
|
|
ty::tls::with(move |tcx| {
|
2023-12-18 11:21:37 +00:00
|
|
|
let dcx = tcx.dcx();
|
2024-02-29 00:58:51 +00:00
|
|
|
let mut diag = dcx.struct_allow(DiagMessage::Str(String::new().into()));
|
2023-05-29 06:40:15 +00:00
|
|
|
let message = self.diagnostic_message();
|
2024-02-12 04:18:18 +00:00
|
|
|
self.add_args(&mut diag);
|
2024-02-15 19:07:49 +00:00
|
|
|
let s = dcx.eagerly_translate_to_string(message, diag.args.iter());
|
2024-02-12 04:18:18 +00:00
|
|
|
diag.cancel();
|
2023-05-29 06:40:15 +00:00
|
|
|
s
|
|
|
|
})
|
2023-05-29 03:32:38 +00:00
|
|
|
}
|
2023-05-17 10:30:14 +00:00
|
|
|
}
|
|
|
|
|
2024-06-18 10:35:56 +00:00
|
|
|
fn bad_pointer_message(msg: CheckInAllocMsg, dcx: DiagCtxtHandle<'_>) -> String {
|
2023-05-17 10:30:14 +00:00
|
|
|
use crate::fluent_generated::*;
|
|
|
|
|
|
|
|
let msg = match msg {
|
|
|
|
CheckInAllocMsg::MemoryAccessTest => const_eval_memory_access_test,
|
|
|
|
CheckInAllocMsg::PointerArithmeticTest => const_eval_pointer_arithmetic_test,
|
|
|
|
CheckInAllocMsg::OffsetFromTest => const_eval_offset_from_test,
|
|
|
|
CheckInAllocMsg::InboundsTest => const_eval_in_bounds_test,
|
|
|
|
};
|
|
|
|
|
2023-12-17 23:15:45 +00:00
|
|
|
dcx.eagerly_translate_to_string(msg, [].into_iter())
|
2023-05-17 10:30:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl<'a> ReportErrorExt for UndefinedBehaviorInfo<'a> {
|
2024-02-29 00:58:51 +00:00
|
|
|
fn diagnostic_message(&self) -> DiagMessage {
|
2023-05-17 10:30:14 +00:00
|
|
|
use UndefinedBehaviorInfo::*;
|
2024-07-28 22:13:50 +00:00
|
|
|
|
2023-05-17 10:30:14 +00:00
|
|
|
use crate::fluent_generated::*;
|
|
|
|
match self {
|
2023-05-29 06:40:15 +00:00
|
|
|
Ub(msg) => msg.clone().into(),
|
2023-09-09 08:50:14 +00:00
|
|
|
Custom(x) => (x.msg)(),
|
|
|
|
ValidationError(e) => e.diagnostic_message(),
|
|
|
|
|
2023-05-17 10:30:14 +00:00
|
|
|
Unreachable => const_eval_unreachable,
|
|
|
|
BoundsCheckFailed { .. } => const_eval_bounds_check_failed,
|
|
|
|
DivisionByZero => const_eval_division_by_zero,
|
|
|
|
RemainderByZero => const_eval_remainder_by_zero,
|
|
|
|
DivisionOverflow => const_eval_division_overflow,
|
|
|
|
RemainderOverflow => const_eval_remainder_overflow,
|
|
|
|
PointerArithOverflow => const_eval_pointer_arithmetic_overflow,
|
2024-05-21 10:17:34 +00:00
|
|
|
ArithOverflow { .. } => const_eval_overflow_arith,
|
|
|
|
ShiftOverflow { .. } => const_eval_overflow_shift,
|
2023-05-17 10:30:14 +00:00
|
|
|
InvalidMeta(InvalidMetaKind::SliceTooBig) => const_eval_invalid_meta_slice,
|
|
|
|
InvalidMeta(InvalidMetaKind::TooBig) => const_eval_invalid_meta,
|
|
|
|
UnterminatedCString(_) => const_eval_unterminated_c_string,
|
2023-08-01 15:03:19 +00:00
|
|
|
PointerUseAfterFree(_, _) => const_eval_pointer_use_after_free,
|
2023-05-17 10:30:14 +00:00
|
|
|
PointerOutOfBounds { .. } => const_eval_pointer_out_of_bounds,
|
2024-07-27 16:09:50 +00:00
|
|
|
DanglingIntPointer { addr: 0, .. } => const_eval_dangling_null_pointer,
|
|
|
|
DanglingIntPointer { .. } => const_eval_dangling_int_pointer,
|
2023-05-17 10:30:14 +00:00
|
|
|
AlignmentCheckFailed { .. } => const_eval_alignment_check_failed,
|
|
|
|
WriteToReadOnly(_) => const_eval_write_to_read_only,
|
|
|
|
DerefFunctionPointer(_) => const_eval_deref_function_pointer,
|
|
|
|
DerefVTablePointer(_) => const_eval_deref_vtable_pointer,
|
|
|
|
InvalidBool(_) => const_eval_invalid_bool,
|
|
|
|
InvalidChar(_) => const_eval_invalid_char,
|
|
|
|
InvalidTag(_) => const_eval_invalid_tag,
|
|
|
|
InvalidFunctionPointer(_) => const_eval_invalid_function_pointer,
|
|
|
|
InvalidVTablePointer(_) => const_eval_invalid_vtable_pointer,
|
2024-04-21 09:35:02 +00:00
|
|
|
InvalidVTableTrait { .. } => const_eval_invalid_vtable_trait,
|
2023-05-17 10:30:14 +00:00
|
|
|
InvalidStr(_) => const_eval_invalid_str,
|
|
|
|
InvalidUninitBytes(None) => const_eval_invalid_uninit_bytes_unknown,
|
|
|
|
InvalidUninitBytes(Some(_)) => const_eval_invalid_uninit_bytes,
|
|
|
|
DeadLocal => const_eval_dead_local,
|
|
|
|
ScalarSizeMismatch(_) => const_eval_scalar_size_mismatch,
|
2023-07-24 09:44:58 +00:00
|
|
|
UninhabitedEnumVariantWritten(_) => const_eval_uninhabited_enum_variant_written,
|
|
|
|
UninhabitedEnumVariantRead(_) => const_eval_uninhabited_enum_variant_read,
|
2024-02-10 14:26:55 +00:00
|
|
|
InvalidNichedEnumVariantWritten { .. } => {
|
|
|
|
const_eval_invalid_niched_enum_variant_written
|
|
|
|
}
|
2023-09-09 08:50:14 +00:00
|
|
|
AbiMismatchArgument { .. } => const_eval_incompatible_types,
|
|
|
|
AbiMismatchReturn { .. } => const_eval_incompatible_return_types,
|
2023-05-17 10:30:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-02-22 23:20:45 +00:00
|
|
|
fn add_args<G: EmissionGuarantee>(self, diag: &mut Diag<'_, G>) {
|
2023-05-17 10:30:14 +00:00
|
|
|
use UndefinedBehaviorInfo::*;
|
2024-02-12 04:18:18 +00:00
|
|
|
let dcx = diag.dcx;
|
2023-05-17 10:30:14 +00:00
|
|
|
match self {
|
2023-09-09 08:50:14 +00:00
|
|
|
Ub(_) => {}
|
|
|
|
Custom(custom) => {
|
|
|
|
(custom.add_args)(&mut |name, value| {
|
2024-02-12 04:18:18 +00:00
|
|
|
diag.arg(name, value);
|
2023-09-09 08:50:14 +00:00
|
|
|
});
|
|
|
|
}
|
2024-02-12 04:18:18 +00:00
|
|
|
ValidationError(e) => e.add_args(diag),
|
2023-09-09 08:50:14 +00:00
|
|
|
|
|
|
|
Unreachable
|
2023-05-17 10:30:14 +00:00
|
|
|
| DivisionByZero
|
|
|
|
| RemainderByZero
|
|
|
|
| DivisionOverflow
|
|
|
|
| RemainderOverflow
|
|
|
|
| PointerArithOverflow
|
|
|
|
| InvalidMeta(InvalidMetaKind::SliceTooBig)
|
|
|
|
| InvalidMeta(InvalidMetaKind::TooBig)
|
|
|
|
| InvalidUninitBytes(None)
|
|
|
|
| DeadLocal
|
2023-07-24 09:44:58 +00:00
|
|
|
| UninhabitedEnumVariantWritten(_)
|
|
|
|
| UninhabitedEnumVariantRead(_) => {}
|
2024-04-21 09:35:02 +00:00
|
|
|
|
2024-05-21 10:17:34 +00:00
|
|
|
ArithOverflow { intrinsic } => {
|
|
|
|
diag.arg("intrinsic", intrinsic);
|
|
|
|
}
|
|
|
|
ShiftOverflow { intrinsic, shift_amount } => {
|
|
|
|
diag.arg("intrinsic", intrinsic);
|
|
|
|
diag.arg(
|
|
|
|
"shift_amount",
|
|
|
|
match shift_amount {
|
|
|
|
Either::Left(v) => v.to_string(),
|
|
|
|
Either::Right(v) => v.to_string(),
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
2023-05-17 10:30:14 +00:00
|
|
|
BoundsCheckFailed { len, index } => {
|
2024-02-12 04:18:18 +00:00
|
|
|
diag.arg("len", len);
|
|
|
|
diag.arg("index", index);
|
2023-05-17 10:30:14 +00:00
|
|
|
}
|
|
|
|
UnterminatedCString(ptr) | InvalidFunctionPointer(ptr) | InvalidVTablePointer(ptr) => {
|
2024-02-12 04:18:18 +00:00
|
|
|
diag.arg("pointer", ptr);
|
2023-05-17 10:30:14 +00:00
|
|
|
}
|
2024-09-23 00:00:01 +00:00
|
|
|
InvalidVTableTrait { expected_dyn_type, vtable_dyn_type } => {
|
|
|
|
diag.arg("expected_dyn_type", expected_dyn_type.to_string());
|
|
|
|
diag.arg("vtable_dyn_type", vtable_dyn_type.to_string());
|
2024-04-21 09:35:02 +00:00
|
|
|
}
|
2023-08-01 15:03:19 +00:00
|
|
|
PointerUseAfterFree(alloc_id, msg) => {
|
2024-02-12 04:18:18 +00:00
|
|
|
diag.arg("alloc_id", alloc_id)
|
2023-12-23 22:08:41 +00:00
|
|
|
.arg("bad_pointer_message", bad_pointer_message(msg, dcx));
|
2023-05-17 10:30:14 +00:00
|
|
|
}
|
2024-07-27 16:09:50 +00:00
|
|
|
PointerOutOfBounds { alloc_id, alloc_size, ptr_offset, inbounds_size, msg } => {
|
2024-07-29 14:40:21 +00:00
|
|
|
diag.arg("alloc_size", alloc_size.bytes());
|
|
|
|
diag.arg("bad_pointer_message", bad_pointer_message(msg, dcx));
|
|
|
|
diag.arg("pointer", {
|
|
|
|
let mut out = format!("{:?}", alloc_id);
|
|
|
|
if ptr_offset > 0 {
|
|
|
|
write!(out, "+{:#x}", ptr_offset).unwrap();
|
|
|
|
} else if ptr_offset < 0 {
|
|
|
|
write!(out, "-{:#x}", ptr_offset.unsigned_abs()).unwrap();
|
|
|
|
}
|
|
|
|
out
|
|
|
|
});
|
|
|
|
diag.arg("inbounds_size_is_neg", inbounds_size < 0);
|
|
|
|
diag.arg("inbounds_size_abs", inbounds_size.unsigned_abs());
|
2024-07-27 16:09:50 +00:00
|
|
|
diag.arg("ptr_offset_is_neg", ptr_offset < 0);
|
2024-07-29 14:40:21 +00:00
|
|
|
diag.arg("ptr_offset_abs", ptr_offset.unsigned_abs());
|
2024-07-27 16:09:50 +00:00
|
|
|
diag.arg(
|
|
|
|
"alloc_size_minus_ptr_offset",
|
|
|
|
alloc_size.bytes().saturating_sub(ptr_offset as u64),
|
|
|
|
);
|
2023-05-17 10:30:14 +00:00
|
|
|
}
|
2024-07-27 16:09:50 +00:00
|
|
|
DanglingIntPointer { addr, inbounds_size, msg } => {
|
|
|
|
if addr != 0 {
|
|
|
|
diag.arg(
|
|
|
|
"pointer",
|
|
|
|
Pointer::<Option<CtfeProvenance>>::from_addr_invalid(addr).to_string(),
|
|
|
|
);
|
2023-05-17 10:30:14 +00:00
|
|
|
}
|
|
|
|
|
2024-07-29 14:40:21 +00:00
|
|
|
diag.arg("inbounds_size_is_neg", inbounds_size < 0);
|
|
|
|
diag.arg("inbounds_size_abs", inbounds_size.unsigned_abs());
|
2024-02-12 04:18:18 +00:00
|
|
|
diag.arg("bad_pointer_message", bad_pointer_message(msg, dcx));
|
2023-05-17 10:30:14 +00:00
|
|
|
}
|
2023-09-26 14:25:05 +00:00
|
|
|
AlignmentCheckFailed(Misalignment { required, has }, msg) => {
|
2024-02-12 04:18:18 +00:00
|
|
|
diag.arg("required", required.bytes());
|
|
|
|
diag.arg("has", has.bytes());
|
|
|
|
diag.arg("msg", format!("{msg:?}"));
|
2023-05-17 10:30:14 +00:00
|
|
|
}
|
|
|
|
WriteToReadOnly(alloc) | DerefFunctionPointer(alloc) | DerefVTablePointer(alloc) => {
|
2024-02-12 04:18:18 +00:00
|
|
|
diag.arg("allocation", alloc);
|
2023-05-17 10:30:14 +00:00
|
|
|
}
|
|
|
|
InvalidBool(b) => {
|
2024-02-12 04:18:18 +00:00
|
|
|
diag.arg("value", format!("{b:02x}"));
|
2023-05-17 10:30:14 +00:00
|
|
|
}
|
|
|
|
InvalidChar(c) => {
|
2024-02-12 04:18:18 +00:00
|
|
|
diag.arg("value", format!("{c:08x}"));
|
2023-05-17 10:30:14 +00:00
|
|
|
}
|
|
|
|
InvalidTag(tag) => {
|
2024-02-12 04:18:18 +00:00
|
|
|
diag.arg("tag", format!("{tag:x}"));
|
2023-05-17 10:30:14 +00:00
|
|
|
}
|
|
|
|
InvalidStr(err) => {
|
2024-02-12 04:18:18 +00:00
|
|
|
diag.arg("err", format!("{err}"));
|
2023-05-17 10:30:14 +00:00
|
|
|
}
|
|
|
|
InvalidUninitBytes(Some((alloc, info))) => {
|
2024-02-12 04:18:18 +00:00
|
|
|
diag.arg("alloc", alloc);
|
|
|
|
diag.arg("access", info.access);
|
|
|
|
diag.arg("uninit", info.bad);
|
2023-05-17 10:30:14 +00:00
|
|
|
}
|
|
|
|
ScalarSizeMismatch(info) => {
|
2024-02-12 04:18:18 +00:00
|
|
|
diag.arg("target_size", info.target_size);
|
|
|
|
diag.arg("data_size", info.data_size);
|
2023-05-17 10:30:14 +00:00
|
|
|
}
|
2024-02-10 14:26:55 +00:00
|
|
|
InvalidNichedEnumVariantWritten { enum_ty } => {
|
2024-02-12 04:18:18 +00:00
|
|
|
diag.arg("ty", enum_ty.to_string());
|
2024-02-10 14:26:55 +00:00
|
|
|
}
|
2023-09-09 08:50:14 +00:00
|
|
|
AbiMismatchArgument { caller_ty, callee_ty }
|
|
|
|
| AbiMismatchReturn { caller_ty, callee_ty } => {
|
2024-02-12 04:18:18 +00:00
|
|
|
diag.arg("caller_ty", caller_ty.to_string());
|
|
|
|
diag.arg("callee_ty", callee_ty.to_string());
|
2023-05-17 10:30:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'tcx> ReportErrorExt for ValidationErrorInfo<'tcx> {
|
2024-02-29 00:58:51 +00:00
|
|
|
fn diagnostic_message(&self) -> DiagMessage {
|
2023-05-17 10:30:14 +00:00
|
|
|
use rustc_middle::mir::interpret::ValidationErrorKind::*;
|
2024-07-28 22:13:50 +00:00
|
|
|
|
2023-05-17 10:30:14 +00:00
|
|
|
use crate::fluent_generated::*;
|
|
|
|
match self.kind {
|
2023-08-02 14:14:36 +00:00
|
|
|
PtrToUninhabited { ptr_kind: PointerKind::Box, .. } => {
|
|
|
|
const_eval_validation_box_to_uninhabited
|
|
|
|
}
|
2024-02-16 08:58:53 +00:00
|
|
|
PtrToUninhabited { ptr_kind: PointerKind::Ref(_), .. } => {
|
2023-08-02 14:14:36 +00:00
|
|
|
const_eval_validation_ref_to_uninhabited
|
|
|
|
}
|
|
|
|
|
|
|
|
PointerAsInt { .. } => const_eval_validation_pointer_as_int,
|
|
|
|
PartialPointer => const_eval_validation_partial_pointer,
|
2024-01-06 12:48:48 +00:00
|
|
|
ConstRefToMutable => const_eval_validation_const_ref_to_mutable,
|
2024-01-06 14:06:22 +00:00
|
|
|
ConstRefToExtern => const_eval_validation_const_ref_to_extern,
|
2023-12-16 15:24:25 +00:00
|
|
|
MutableRefToImmutable => const_eval_validation_mutable_ref_to_immutable,
|
2023-08-02 14:14:36 +00:00
|
|
|
NullFnPtr => const_eval_validation_null_fn_ptr,
|
|
|
|
NeverVal => const_eval_validation_never_val,
|
|
|
|
NullablePtrOutOfRange { .. } => const_eval_validation_nullable_ptr_out_of_range,
|
|
|
|
PtrOutOfRange { .. } => const_eval_validation_ptr_out_of_range,
|
|
|
|
OutOfRange { .. } => const_eval_validation_out_of_range,
|
2023-12-16 15:24:25 +00:00
|
|
|
UnsafeCellInImmutable => const_eval_validation_unsafe_cell,
|
2023-08-02 14:14:36 +00:00
|
|
|
UninhabitedVal { .. } => const_eval_validation_uninhabited_val,
|
|
|
|
InvalidEnumTag { .. } => const_eval_validation_invalid_enum_tag,
|
|
|
|
UninhabitedEnumVariant => const_eval_validation_uninhabited_enum_variant,
|
|
|
|
Uninit { .. } => const_eval_validation_uninit,
|
|
|
|
InvalidVTablePtr { .. } => const_eval_validation_invalid_vtable_ptr,
|
2024-04-21 09:35:02 +00:00
|
|
|
InvalidMetaWrongTrait { .. } => const_eval_validation_invalid_vtable_trait,
|
2023-05-17 10:30:14 +00:00
|
|
|
InvalidMetaSliceTooLarge { ptr_kind: PointerKind::Box } => {
|
2023-08-02 14:14:36 +00:00
|
|
|
const_eval_validation_invalid_box_slice_meta
|
2023-05-17 10:30:14 +00:00
|
|
|
}
|
2024-02-16 08:58:53 +00:00
|
|
|
InvalidMetaSliceTooLarge { ptr_kind: PointerKind::Ref(_) } => {
|
2023-08-02 14:14:36 +00:00
|
|
|
const_eval_validation_invalid_ref_slice_meta
|
2023-05-17 10:30:14 +00:00
|
|
|
}
|
|
|
|
|
2023-08-02 14:14:36 +00:00
|
|
|
InvalidMetaTooLarge { ptr_kind: PointerKind::Box } => {
|
|
|
|
const_eval_validation_invalid_box_meta
|
|
|
|
}
|
2024-02-16 08:58:53 +00:00
|
|
|
InvalidMetaTooLarge { ptr_kind: PointerKind::Ref(_) } => {
|
2023-08-02 14:14:36 +00:00
|
|
|
const_eval_validation_invalid_ref_meta
|
|
|
|
}
|
2024-02-16 08:58:53 +00:00
|
|
|
UnalignedPtr { ptr_kind: PointerKind::Ref(_), .. } => {
|
|
|
|
const_eval_validation_unaligned_ref
|
|
|
|
}
|
2023-08-02 14:14:36 +00:00
|
|
|
UnalignedPtr { ptr_kind: PointerKind::Box, .. } => const_eval_validation_unaligned_box,
|
2023-05-17 10:30:14 +00:00
|
|
|
|
2023-08-02 14:14:36 +00:00
|
|
|
NullPtr { ptr_kind: PointerKind::Box } => const_eval_validation_null_box,
|
2024-02-16 08:58:53 +00:00
|
|
|
NullPtr { ptr_kind: PointerKind::Ref(_) } => const_eval_validation_null_ref,
|
2023-05-17 10:30:14 +00:00
|
|
|
DanglingPtrNoProvenance { ptr_kind: PointerKind::Box, .. } => {
|
2023-08-02 14:14:36 +00:00
|
|
|
const_eval_validation_dangling_box_no_provenance
|
2023-05-17 10:30:14 +00:00
|
|
|
}
|
2024-02-16 08:58:53 +00:00
|
|
|
DanglingPtrNoProvenance { ptr_kind: PointerKind::Ref(_), .. } => {
|
2023-08-02 14:14:36 +00:00
|
|
|
const_eval_validation_dangling_ref_no_provenance
|
2023-05-17 10:30:14 +00:00
|
|
|
}
|
|
|
|
DanglingPtrOutOfBounds { ptr_kind: PointerKind::Box } => {
|
2023-08-02 14:14:36 +00:00
|
|
|
const_eval_validation_dangling_box_out_of_bounds
|
2023-05-17 10:30:14 +00:00
|
|
|
}
|
2024-02-16 08:58:53 +00:00
|
|
|
DanglingPtrOutOfBounds { ptr_kind: PointerKind::Ref(_) } => {
|
2023-08-02 14:14:36 +00:00
|
|
|
const_eval_validation_dangling_ref_out_of_bounds
|
2023-05-17 10:30:14 +00:00
|
|
|
}
|
|
|
|
DanglingPtrUseAfterFree { ptr_kind: PointerKind::Box } => {
|
2023-08-02 14:14:36 +00:00
|
|
|
const_eval_validation_dangling_box_use_after_free
|
2023-05-17 10:30:14 +00:00
|
|
|
}
|
2024-02-16 08:58:53 +00:00
|
|
|
DanglingPtrUseAfterFree { ptr_kind: PointerKind::Ref(_) } => {
|
2023-08-02 14:14:36 +00:00
|
|
|
const_eval_validation_dangling_ref_use_after_free
|
2023-05-17 10:30:14 +00:00
|
|
|
}
|
|
|
|
InvalidBool { .. } => const_eval_validation_invalid_bool,
|
|
|
|
InvalidChar { .. } => const_eval_validation_invalid_char,
|
2023-08-02 14:14:36 +00:00
|
|
|
InvalidFnPtr { .. } => const_eval_validation_invalid_fn_ptr,
|
2023-05-17 10:30:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-02-22 23:20:45 +00:00
|
|
|
fn add_args<G: EmissionGuarantee>(self, err: &mut Diag<'_, G>) {
|
2023-05-17 10:30:14 +00:00
|
|
|
use rustc_middle::mir::interpret::ValidationErrorKind::*;
|
|
|
|
|
|
|
|
use crate::fluent_generated as fluent;
|
2024-07-28 22:13:50 +00:00
|
|
|
|
2023-08-02 14:14:36 +00:00
|
|
|
if let PointerAsInt { .. } | PartialPointer = self.kind {
|
|
|
|
err.help(fluent::const_eval_ptr_as_bytes_1);
|
|
|
|
err.help(fluent::const_eval_ptr_as_bytes_2);
|
|
|
|
}
|
|
|
|
|
2023-05-17 10:30:14 +00:00
|
|
|
let message = if let Some(path) = self.path {
|
2024-02-12 04:18:18 +00:00
|
|
|
err.dcx.eagerly_translate_to_string(
|
2023-08-02 14:14:36 +00:00
|
|
|
fluent::const_eval_validation_front_matter_invalid_value_with_path,
|
2024-02-23 03:37:48 +00:00
|
|
|
[("path".into(), DiagArgValue::Str(path.into()))].iter().map(|(a, b)| (a, b)),
|
2023-05-17 10:30:14 +00:00
|
|
|
)
|
|
|
|
} else {
|
2024-02-12 04:18:18 +00:00
|
|
|
err.dcx.eagerly_translate_to_string(
|
2023-08-02 14:14:36 +00:00
|
|
|
fluent::const_eval_validation_front_matter_invalid_value,
|
|
|
|
[].into_iter(),
|
|
|
|
)
|
2023-05-17 10:30:14 +00:00
|
|
|
};
|
|
|
|
|
2023-12-23 22:08:41 +00:00
|
|
|
err.arg("front_matter", message);
|
2023-05-17 10:30:14 +00:00
|
|
|
|
|
|
|
fn add_range_arg<G: EmissionGuarantee>(
|
|
|
|
r: WrappingRange,
|
|
|
|
max_hi: u128,
|
2024-02-22 23:20:45 +00:00
|
|
|
err: &mut Diag<'_, G>,
|
2023-05-17 10:30:14 +00:00
|
|
|
) {
|
|
|
|
let WrappingRange { start: lo, end: hi } = r;
|
|
|
|
assert!(hi <= max_hi);
|
|
|
|
let msg = if lo > hi {
|
|
|
|
fluent::const_eval_range_wrapping
|
|
|
|
} else if lo == hi {
|
|
|
|
fluent::const_eval_range_singular
|
|
|
|
} else if lo == 0 {
|
|
|
|
assert!(hi < max_hi, "should not be printing if the range covers everything");
|
|
|
|
fluent::const_eval_range_upper
|
|
|
|
} else if hi == max_hi {
|
|
|
|
assert!(lo > 0, "should not be printing if the range covers everything");
|
|
|
|
fluent::const_eval_range_lower
|
|
|
|
} else {
|
|
|
|
fluent::const_eval_range
|
|
|
|
};
|
|
|
|
|
|
|
|
let args = [
|
2024-02-23 03:37:48 +00:00
|
|
|
("lo".into(), DiagArgValue::Str(lo.to_string().into())),
|
|
|
|
("hi".into(), DiagArgValue::Str(hi.to_string().into())),
|
2023-05-17 10:30:14 +00:00
|
|
|
];
|
|
|
|
let args = args.iter().map(|(a, b)| (a, b));
|
2024-02-12 04:18:18 +00:00
|
|
|
let message = err.dcx.eagerly_translate_to_string(msg, args);
|
2023-12-23 22:08:41 +00:00
|
|
|
err.arg("in_range", message);
|
2023-05-17 10:30:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
match self.kind {
|
|
|
|
PtrToUninhabited { ty, .. } | UninhabitedVal { ty } => {
|
2023-12-23 22:08:41 +00:00
|
|
|
err.arg("ty", ty);
|
2023-05-17 10:30:14 +00:00
|
|
|
}
|
2023-08-02 14:14:36 +00:00
|
|
|
PointerAsInt { expected } | Uninit { expected } => {
|
|
|
|
let msg = match expected {
|
|
|
|
ExpectedKind::Reference => fluent::const_eval_validation_expected_ref,
|
|
|
|
ExpectedKind::Box => fluent::const_eval_validation_expected_box,
|
|
|
|
ExpectedKind::RawPtr => fluent::const_eval_validation_expected_raw_ptr,
|
|
|
|
ExpectedKind::InitScalar => fluent::const_eval_validation_expected_init_scalar,
|
|
|
|
ExpectedKind::Bool => fluent::const_eval_validation_expected_bool,
|
|
|
|
ExpectedKind::Char => fluent::const_eval_validation_expected_char,
|
|
|
|
ExpectedKind::Float => fluent::const_eval_validation_expected_float,
|
|
|
|
ExpectedKind::Int => fluent::const_eval_validation_expected_int,
|
|
|
|
ExpectedKind::FnPtr => fluent::const_eval_validation_expected_fn_ptr,
|
|
|
|
ExpectedKind::EnumTag => fluent::const_eval_validation_expected_enum_tag,
|
|
|
|
ExpectedKind::Str => fluent::const_eval_validation_expected_str,
|
|
|
|
};
|
2024-02-12 04:18:18 +00:00
|
|
|
let msg = err.dcx.eagerly_translate_to_string(msg, [].into_iter());
|
2023-12-23 22:08:41 +00:00
|
|
|
err.arg("expected", msg);
|
2023-08-02 14:14:36 +00:00
|
|
|
}
|
|
|
|
InvalidEnumTag { value }
|
2023-05-17 10:30:14 +00:00
|
|
|
| InvalidVTablePtr { value }
|
|
|
|
| InvalidBool { value }
|
|
|
|
| InvalidChar { value }
|
|
|
|
| InvalidFnPtr { value } => {
|
2023-12-23 22:08:41 +00:00
|
|
|
err.arg("value", value);
|
2023-05-17 10:30:14 +00:00
|
|
|
}
|
2023-07-22 05:35:57 +00:00
|
|
|
NullablePtrOutOfRange { range, max_value } | PtrOutOfRange { range, max_value } => {
|
2024-02-12 04:18:18 +00:00
|
|
|
add_range_arg(range, max_value, err)
|
2023-07-22 05:35:57 +00:00
|
|
|
}
|
2023-05-17 10:30:14 +00:00
|
|
|
OutOfRange { range, max_value, value } => {
|
2023-12-23 22:08:41 +00:00
|
|
|
err.arg("value", value);
|
2024-02-12 04:18:18 +00:00
|
|
|
add_range_arg(range, max_value, err);
|
2023-05-17 10:30:14 +00:00
|
|
|
}
|
|
|
|
UnalignedPtr { required_bytes, found_bytes, .. } => {
|
2023-12-23 22:08:41 +00:00
|
|
|
err.arg("required_bytes", required_bytes);
|
|
|
|
err.arg("found_bytes", found_bytes);
|
2023-05-17 10:30:14 +00:00
|
|
|
}
|
|
|
|
DanglingPtrNoProvenance { pointer, .. } => {
|
2023-12-23 22:08:41 +00:00
|
|
|
err.arg("pointer", pointer);
|
2023-05-17 10:30:14 +00:00
|
|
|
}
|
2024-09-23 00:00:01 +00:00
|
|
|
InvalidMetaWrongTrait { vtable_dyn_type, expected_dyn_type } => {
|
|
|
|
err.arg("vtable_dyn_type", vtable_dyn_type.to_string());
|
|
|
|
err.arg("expected_dyn_type", expected_dyn_type.to_string());
|
2024-04-21 09:35:02 +00:00
|
|
|
}
|
2023-05-17 10:30:14 +00:00
|
|
|
NullPtr { .. }
|
2024-01-06 12:48:48 +00:00
|
|
|
| ConstRefToMutable
|
2024-01-06 14:06:22 +00:00
|
|
|
| ConstRefToExtern
|
2023-12-16 15:24:25 +00:00
|
|
|
| MutableRefToImmutable
|
2023-05-17 10:30:14 +00:00
|
|
|
| NullFnPtr
|
|
|
|
| NeverVal
|
2023-12-16 15:24:25 +00:00
|
|
|
| UnsafeCellInImmutable
|
2023-05-17 10:30:14 +00:00
|
|
|
| InvalidMetaSliceTooLarge { .. }
|
|
|
|
| InvalidMetaTooLarge { .. }
|
|
|
|
| DanglingPtrUseAfterFree { .. }
|
2023-07-24 09:44:58 +00:00
|
|
|
| DanglingPtrOutOfBounds { .. }
|
2023-08-02 14:14:36 +00:00
|
|
|
| UninhabitedEnumVariant
|
|
|
|
| PartialPointer => {}
|
2023-05-17 10:30:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl ReportErrorExt for UnsupportedOpInfo {
|
2024-02-29 00:58:51 +00:00
|
|
|
fn diagnostic_message(&self) -> DiagMessage {
|
2023-05-17 10:30:14 +00:00
|
|
|
use crate::fluent_generated::*;
|
|
|
|
match self {
|
|
|
|
UnsupportedOpInfo::Unsupported(s) => s.clone().into(),
|
2024-06-22 14:26:30 +00:00
|
|
|
UnsupportedOpInfo::ExternTypeField => const_eval_extern_type_field,
|
2023-08-06 16:40:37 +00:00
|
|
|
UnsupportedOpInfo::UnsizedLocal => const_eval_unsized_local,
|
2023-08-02 14:14:36 +00:00
|
|
|
UnsupportedOpInfo::OverwritePartialPointer(_) => const_eval_partial_pointer_overwrite,
|
|
|
|
UnsupportedOpInfo::ReadPartialPointer(_) => const_eval_partial_pointer_copy,
|
|
|
|
UnsupportedOpInfo::ReadPointerAsInt(_) => const_eval_read_pointer_as_int,
|
2023-05-17 10:30:14 +00:00
|
|
|
UnsupportedOpInfo::ThreadLocalStatic(_) => const_eval_thread_local_static,
|
2024-02-10 14:41:08 +00:00
|
|
|
UnsupportedOpInfo::ExternStatic(_) => const_eval_extern_static,
|
2023-05-17 10:30:14 +00:00
|
|
|
}
|
|
|
|
}
|
2025-03-20 03:21:58 +00:00
|
|
|
|
2024-02-22 23:20:45 +00:00
|
|
|
fn add_args<G: EmissionGuarantee>(self, diag: &mut Diag<'_, G>) {
|
2023-05-17 10:30:14 +00:00
|
|
|
use UnsupportedOpInfo::*;
|
2024-07-28 22:13:50 +00:00
|
|
|
|
2023-05-17 10:30:14 +00:00
|
|
|
use crate::fluent_generated::*;
|
2023-08-02 14:14:36 +00:00
|
|
|
if let ReadPointerAsInt(_) | OverwritePartialPointer(_) | ReadPartialPointer(_) = self {
|
2024-02-12 04:18:18 +00:00
|
|
|
diag.help(const_eval_ptr_as_bytes_1);
|
|
|
|
diag.help(const_eval_ptr_as_bytes_2);
|
2023-05-17 10:30:14 +00:00
|
|
|
}
|
|
|
|
match self {
|
2023-08-02 14:14:36 +00:00
|
|
|
// `ReadPointerAsInt(Some(info))` is never printed anyway, it only serves as an error to
|
|
|
|
// be further processed by validity checking which then turns it into something nice to
|
|
|
|
// print. So it's not worth the effort of having diagnostics that can print the `info`.
|
2024-06-22 14:26:30 +00:00
|
|
|
UnsizedLocal
|
|
|
|
| UnsupportedOpInfo::ExternTypeField
|
|
|
|
| Unsupported(_)
|
|
|
|
| ReadPointerAsInt(_) => {}
|
2023-08-02 14:14:36 +00:00
|
|
|
OverwritePartialPointer(ptr) | ReadPartialPointer(ptr) => {
|
2024-02-12 04:18:18 +00:00
|
|
|
diag.arg("ptr", ptr);
|
2023-05-17 10:30:14 +00:00
|
|
|
}
|
2025-03-20 03:21:58 +00:00
|
|
|
ThreadLocalStatic(did) | ExternStatic(did) => rustc_middle::ty::tls::with(|tcx| {
|
|
|
|
diag.arg("did", tcx.def_path_str(did));
|
|
|
|
}),
|
2023-05-17 10:30:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-10-19 06:49:13 +00:00
|
|
|
impl<'tcx> ReportErrorExt for InterpErrorKind<'tcx> {
|
2024-02-29 00:58:51 +00:00
|
|
|
fn diagnostic_message(&self) -> DiagMessage {
|
2023-05-17 10:30:14 +00:00
|
|
|
match self {
|
2024-10-19 06:49:13 +00:00
|
|
|
InterpErrorKind::UndefinedBehavior(ub) => ub.diagnostic_message(),
|
|
|
|
InterpErrorKind::Unsupported(e) => e.diagnostic_message(),
|
|
|
|
InterpErrorKind::InvalidProgram(e) => e.diagnostic_message(),
|
|
|
|
InterpErrorKind::ResourceExhaustion(e) => e.diagnostic_message(),
|
|
|
|
InterpErrorKind::MachineStop(e) => e.diagnostic_message(),
|
2023-05-17 10:30:14 +00:00
|
|
|
}
|
|
|
|
}
|
2024-02-22 23:20:45 +00:00
|
|
|
fn add_args<G: EmissionGuarantee>(self, diag: &mut Diag<'_, G>) {
|
2023-05-17 10:30:14 +00:00
|
|
|
match self {
|
2024-10-19 06:49:13 +00:00
|
|
|
InterpErrorKind::UndefinedBehavior(ub) => ub.add_args(diag),
|
|
|
|
InterpErrorKind::Unsupported(e) => e.add_args(diag),
|
|
|
|
InterpErrorKind::InvalidProgram(e) => e.add_args(diag),
|
|
|
|
InterpErrorKind::ResourceExhaustion(e) => e.add_args(diag),
|
|
|
|
InterpErrorKind::MachineStop(e) => e.add_args(&mut |name, value| {
|
2024-02-12 04:18:18 +00:00
|
|
|
diag.arg(name, value);
|
2023-05-17 10:30:14 +00:00
|
|
|
}),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'tcx> ReportErrorExt for InvalidProgramInfo<'tcx> {
|
2024-02-29 00:58:51 +00:00
|
|
|
fn diagnostic_message(&self) -> DiagMessage {
|
2023-05-17 10:30:14 +00:00
|
|
|
use crate::fluent_generated::*;
|
|
|
|
match self {
|
|
|
|
InvalidProgramInfo::TooGeneric => const_eval_too_generic,
|
|
|
|
InvalidProgramInfo::AlreadyReported(_) => const_eval_already_reported,
|
|
|
|
InvalidProgramInfo::Layout(e) => e.diagnostic_message(),
|
|
|
|
}
|
|
|
|
}
|
2024-02-22 23:20:45 +00:00
|
|
|
fn add_args<G: EmissionGuarantee>(self, diag: &mut Diag<'_, G>) {
|
2023-05-17 10:30:14 +00:00
|
|
|
match self {
|
2024-01-05 17:31:38 +00:00
|
|
|
InvalidProgramInfo::TooGeneric | InvalidProgramInfo::AlreadyReported(_) => {}
|
2023-05-17 10:30:14 +00:00
|
|
|
InvalidProgramInfo::Layout(e) => {
|
2024-02-12 04:18:18 +00:00
|
|
|
// The level doesn't matter, `dummy_diag` is consumed without it being used.
|
2023-12-18 03:12:39 +00:00
|
|
|
let dummy_level = Level::Bug;
|
2024-03-06 00:02:56 +00:00
|
|
|
let dummy_diag: Diag<'_, ()> = e.into_diagnostic().into_diag(diag.dcx, dummy_level);
|
2024-02-15 19:07:49 +00:00
|
|
|
for (name, val) in dummy_diag.args.iter() {
|
2024-02-12 04:18:18 +00:00
|
|
|
diag.arg(name.clone(), val.clone());
|
2023-05-17 10:30:14 +00:00
|
|
|
}
|
2024-02-12 04:18:18 +00:00
|
|
|
dummy_diag.cancel();
|
2023-05-17 10:30:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl ReportErrorExt for ResourceExhaustionInfo {
|
2024-02-29 00:58:51 +00:00
|
|
|
fn diagnostic_message(&self) -> DiagMessage {
|
2023-05-17 10:30:14 +00:00
|
|
|
use crate::fluent_generated::*;
|
|
|
|
match self {
|
|
|
|
ResourceExhaustionInfo::StackFrameLimitReached => const_eval_stack_frame_limit_reached,
|
|
|
|
ResourceExhaustionInfo::MemoryExhausted => const_eval_memory_exhausted,
|
|
|
|
ResourceExhaustionInfo::AddressSpaceFull => const_eval_address_space_full,
|
2023-05-19 20:03:35 +00:00
|
|
|
ResourceExhaustionInfo::Interrupted => const_eval_interrupted,
|
2023-05-17 10:30:14 +00:00
|
|
|
}
|
|
|
|
}
|
2024-02-22 23:20:45 +00:00
|
|
|
fn add_args<G: EmissionGuarantee>(self, _: &mut Diag<'_, G>) {}
|
2023-05-17 10:30:14 +00:00
|
|
|
}
|
2023-12-16 15:24:25 +00:00
|
|
|
|
2024-03-05 05:53:24 +00:00
|
|
|
impl rustc_errors::IntoDiagArg for InternKind {
|
Teach structured errors to display short `Ty`
Make it so that every structured error annotated with `#[derive(Diagnostic)]` that has a field of type `Ty<'_>`, the printing of that value into a `String` will look at the thread-local storage `TyCtxt` in order to shorten to a length appropriate with the terminal width. When this happen, the resulting error will have a note with the file where the full type name was written to.
```
error[E0618]: expected function, found `((..., ..., ..., ...), ..., ..., ...)``
--> long.rs:7:5
|
6 | fn foo(x: D) { //~ `x` has type `(...
| - `x` has type `((..., ..., ..., ...), ..., ..., ...)`
7 | x(); //~ ERROR expected function, found `(...
| ^--
| |
| call expression requires function
|
= note: the full name for the type has been written to 'long.long-type-14182675702747116984.txt'
= note: consider using `--verbose` to print the full type name to the console
```
2025-02-18 01:15:59 +00:00
|
|
|
fn into_diag_arg(self, _: &mut Option<std::path::PathBuf>) -> DiagArgValue {
|
2024-02-23 03:37:48 +00:00
|
|
|
DiagArgValue::Str(Cow::Borrowed(match self {
|
2023-12-16 15:24:25 +00:00
|
|
|
InternKind::Static(Mutability::Not) => "static",
|
|
|
|
InternKind::Static(Mutability::Mut) => "static_mut",
|
|
|
|
InternKind::Constant => "const",
|
|
|
|
InternKind::Promoted => "promoted",
|
|
|
|
}))
|
|
|
|
}
|
|
|
|
}
|