2023-12-16 15:24:25 +00:00
|
|
|
use std::borrow::Cow;
|
|
|
|
|
2023-05-17 10:30:14 +00:00
|
|
|
use rustc_errors::{
|
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
|
|
|
codes::*, DiagCtxt, DiagnosticArgValue, DiagnosticBuilder, DiagnosticMessage,
|
|
|
|
EmissionGuarantee, IntoDiagnostic, Level,
|
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::{
|
2023-09-05 13:12:18 +00:00
|
|
|
CheckInAllocMsg, ExpectedKind, InterpError, InvalidMetaKind, InvalidProgramInfo, Misalignment,
|
|
|
|
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};
|
2022-06-29 04:26:05 +00:00
|
|
|
use rustc_span::Span;
|
2023-05-17 10:30:14 +00:00
|
|
|
use rustc_target::abi::call::AdjustForForeignAbiError;
|
|
|
|
use rustc_target::abi::{Size, WrappingRange};
|
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,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Diagnostic)]
|
|
|
|
#[diag(const_eval_mutable_ptr_in_final)]
|
|
|
|
pub(crate) struct MutablePtrInFinal {
|
|
|
|
#[primary_span]
|
|
|
|
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)]
|
2022-10-22 09:07:54 +00:00
|
|
|
#[diag(const_eval_unstable_in_stable)]
|
2022-06-29 04:26:05 +00:00
|
|
|
pub(crate) struct UnstableInStable {
|
|
|
|
pub gate: String,
|
|
|
|
#[primary_span]
|
|
|
|
pub span: Span,
|
|
|
|
#[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)]
|
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_mut_deref, code = E0658)]
|
2022-06-29 06:22:15 +00:00
|
|
|
pub(crate) struct MutDerefErr {
|
|
|
|
#[primary_span]
|
|
|
|
pub span: Span,
|
|
|
|
pub kind: ConstContext,
|
|
|
|
}
|
|
|
|
|
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_transient_mut_borrow, code = E0658)]
|
2022-06-29 06:22:15 +00:00
|
|
|
pub(crate) struct TransientMutBorrowErr {
|
|
|
|
#[primary_span]
|
|
|
|
pub span: Span,
|
|
|
|
pub kind: ConstContext,
|
|
|
|
}
|
|
|
|
|
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_transient_mut_raw, code = E0658)]
|
2023-12-17 10:24:34 +00:00
|
|
|
pub(crate) struct TransientMutRawErr {
|
2022-06-29 06:22:15 +00:00
|
|
|
#[primary_span]
|
|
|
|
pub span: Span,
|
|
|
|
pub kind: ConstContext,
|
|
|
|
}
|
2022-08-18 04:54:11 +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
|
|
|
|
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_mutable_refs, code = E0764)]
|
2022-08-19 18:36:09 +00:00
|
|
|
pub(crate) struct UnallowedMutableRefs {
|
|
|
|
#[primary_span]
|
|
|
|
pub span: Span,
|
|
|
|
pub kind: ConstContext,
|
2022-10-13 09:13:02 +00:00
|
|
|
#[note(const_eval_teach_note)]
|
2022-08-19 18:36:09 +00:00
|
|
|
pub teach: Option<()>,
|
|
|
|
}
|
|
|
|
|
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_mutable_raw, code = E0764)]
|
2023-12-17 10:24:34 +00:00
|
|
|
pub(crate) struct UnallowedMutableRaw {
|
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)]
|
2022-08-19 18:36:09 +00:00
|
|
|
pub teach: Option<()>,
|
|
|
|
}
|
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,
|
|
|
|
}
|
|
|
|
|
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,
|
|
|
|
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)]
|
2022-08-19 18:36:09 +00:00
|
|
|
pub teach: Option<()>,
|
|
|
|
}
|
|
|
|
|
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)]
|
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_interior_mutable_data_refer, code = E0492)]
|
2022-08-19 18:36:09 +00:00
|
|
|
pub(crate) struct InteriorMutableDataRefer {
|
|
|
|
#[primary_span]
|
2022-08-20 19:27:41 +00:00
|
|
|
#[label]
|
2022-08-19 18:36:09 +00:00
|
|
|
pub span: Span,
|
|
|
|
#[help]
|
|
|
|
pub opt_help: Option<()>,
|
|
|
|
pub kind: ConstContext,
|
2022-10-13 09:13:02 +00:00
|
|
|
#[note(const_eval_teach_note)]
|
2022-08-19 18:36:09 +00:00
|
|
|
pub teach: Option<()>,
|
|
|
|
}
|
|
|
|
|
2022-09-18 15:46:56 +00:00
|
|
|
#[derive(Diagnostic)]
|
2022-10-22 09:07:54 +00:00
|
|
|
#[diag(const_eval_interior_mutability_borrow)]
|
2022-08-19 18:36:09 +00:00
|
|
|
pub(crate) struct InteriorMutabilityBorrow {
|
|
|
|
#[primary_span]
|
|
|
|
pub span: Span,
|
|
|
|
}
|
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,
|
|
|
|
}
|
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,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Subdiagnostic, PartialEq, Eq, Clone)]
|
|
|
|
#[note(const_eval_frame_note)]
|
|
|
|
pub struct FrameNote {
|
|
|
|
#[primary_span]
|
|
|
|
pub span: Span,
|
|
|
|
pub times: i32,
|
|
|
|
pub where_: &'static str,
|
|
|
|
pub instance: String,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[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)]
|
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_match_eq_non_const, 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,
|
|
|
|
}
|
|
|
|
|
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_for_loop_into_iter_non_const, 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,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[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_question_branch_non_const, 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,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[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_question_from_residual_non_const, 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,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[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_try_block_from_output_non_const, 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,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[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_await_non_const, 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,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[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_closure_non_const, 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>,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[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)]
|
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_operator_non_const, 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>,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[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_deref_coercion_non_const, 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>,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[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)]
|
|
|
|
pub dropped_at: Option<Span>,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[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>,
|
|
|
|
}
|
|
|
|
|
2023-11-26 15:57:13 +00:00
|
|
|
#[derive(LintDiagnostic)]
|
|
|
|
#[diag(const_eval_write_through_immutable_pointer)]
|
|
|
|
pub struct WriteThroughImmutablePointer {
|
|
|
|
#[subdiagnostic]
|
|
|
|
pub frames: Vec<FrameNote>,
|
|
|
|
}
|
|
|
|
|
2023-05-17 10:30:14 +00:00
|
|
|
#[derive(Diagnostic)]
|
|
|
|
#[diag(const_eval_nullary_intrinsic_fail)]
|
|
|
|
pub struct NullaryIntrinsicError {
|
|
|
|
#[primary_span]
|
|
|
|
pub span: Span,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[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_undefined_behavior, code = E0080)]
|
2023-05-17 10:30:14 +00:00
|
|
|
pub struct UndefinedBehavior {
|
|
|
|
#[primary_span]
|
|
|
|
pub span: Span,
|
|
|
|
#[note(const_eval_undefined_behavior_note)]
|
|
|
|
pub ub_note: Option<()>,
|
|
|
|
#[subdiagnostic]
|
|
|
|
pub frames: Vec<FrameNote>,
|
|
|
|
#[subdiagnostic]
|
|
|
|
pub raw_bytes: RawBytesNote,
|
|
|
|
}
|
|
|
|
|
|
|
|
pub trait ReportErrorExt {
|
|
|
|
/// Returns the diagnostic message for this error.
|
|
|
|
fn diagnostic_message(&self) -> DiagnosticMessage;
|
2024-02-12 04:18:18 +00:00
|
|
|
fn add_args<G: EmissionGuarantee>(self, diag: &mut DiagnosticBuilder<'_, 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-12 04:18:18 +00:00
|
|
|
let mut diag = dcx.struct_allow(DiagnosticMessage::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
|
|
|
}
|
|
|
|
|
2023-12-17 23:15:45 +00:00
|
|
|
fn bad_pointer_message(msg: CheckInAllocMsg, dcx: &DiagCtxt) -> 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> {
|
|
|
|
fn diagnostic_message(&self) -> DiagnosticMessage {
|
|
|
|
use crate::fluent_generated::*;
|
|
|
|
use UndefinedBehaviorInfo::*;
|
|
|
|
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,
|
|
|
|
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 { ptr_size: Size::ZERO, .. } => const_eval_zst_pointer_out_of_bounds,
|
|
|
|
PointerOutOfBounds { .. } => const_eval_pointer_out_of_bounds,
|
|
|
|
DanglingIntPointer(0, _) => const_eval_dangling_null_pointer,
|
|
|
|
DanglingIntPointer(_, _) => const_eval_dangling_int_pointer,
|
|
|
|
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,
|
|
|
|
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-12 04:18:18 +00:00
|
|
|
fn add_args<G: EmissionGuarantee>(self, diag: &mut DiagnosticBuilder<'_, 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(_) => {}
|
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
|
|
|
}
|
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
|
|
|
}
|
|
|
|
PointerOutOfBounds { alloc_id, alloc_size, ptr_offset, ptr_size, msg } => {
|
2024-02-12 04:18:18 +00:00
|
|
|
diag.arg("alloc_id", alloc_id)
|
2023-12-23 22:08:41 +00:00
|
|
|
.arg("alloc_size", alloc_size.bytes())
|
|
|
|
.arg("ptr_offset", ptr_offset)
|
|
|
|
.arg("ptr_size", ptr_size.bytes())
|
|
|
|
.arg("bad_pointer_message", bad_pointer_message(msg, dcx));
|
2023-05-17 10:30:14 +00:00
|
|
|
}
|
|
|
|
DanglingIntPointer(ptr, msg) => {
|
|
|
|
if ptr != 0 {
|
2024-02-12 04:18:18 +00:00
|
|
|
diag.arg("pointer", format!("{ptr:#x}[noalloc]"));
|
2023-05-17 10:30:14 +00:00
|
|
|
}
|
|
|
|
|
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> {
|
|
|
|
fn diagnostic_message(&self) -> DiagnosticMessage {
|
|
|
|
use crate::fluent_generated::*;
|
|
|
|
use rustc_middle::mir::interpret::ValidationErrorKind::*;
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
PtrToStatic { ptr_kind: PointerKind::Box } => const_eval_validation_box_to_static,
|
2024-02-16 08:58:53 +00:00
|
|
|
PtrToStatic { ptr_kind: PointerKind::Ref(_) } => const_eval_validation_ref_to_static,
|
2023-08-02 14:14:36 +00:00
|
|
|
|
|
|
|
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,
|
2024-02-16 08:58:53 +00:00
|
|
|
MutableRefInConstOrStatic => const_eval_validation_mutable_ref_in_const_or_static,
|
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,
|
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-12 04:18:18 +00:00
|
|
|
fn add_args<G: EmissionGuarantee>(self, err: &mut DiagnosticBuilder<'_, G>) {
|
2023-05-17 10:30:14 +00:00
|
|
|
use crate::fluent_generated as fluent;
|
|
|
|
use rustc_middle::mir::interpret::ValidationErrorKind::*;
|
|
|
|
|
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,
|
2023-05-17 10:30:14 +00:00
|
|
|
[("path".into(), DiagnosticArgValue::Str(path.into()))].iter().map(|(a, b)| (a, b)),
|
|
|
|
)
|
|
|
|
} 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,
|
|
|
|
err: &mut DiagnosticBuilder<'_, G>,
|
|
|
|
) {
|
|
|
|
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 = [
|
|
|
|
("lo".into(), DiagnosticArgValue::Str(lo.to_string().into())),
|
|
|
|
("hi".into(), DiagnosticArgValue::Str(hi.to_string().into())),
|
|
|
|
];
|
|
|
|
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
|
|
|
}
|
|
|
|
NullPtr { .. }
|
|
|
|
| PtrToStatic { .. }
|
2024-02-16 08:58:53 +00:00
|
|
|
| MutableRefInConstOrStatic
|
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 {
|
|
|
|
fn diagnostic_message(&self) -> DiagnosticMessage {
|
|
|
|
use crate::fluent_generated::*;
|
|
|
|
match self {
|
|
|
|
UnsupportedOpInfo::Unsupported(s) => s.clone().into(),
|
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
|
|
|
}
|
|
|
|
}
|
2024-02-12 04:18:18 +00:00
|
|
|
fn add_args<G: EmissionGuarantee>(self, diag: &mut DiagnosticBuilder<'_, G>) {
|
2023-05-17 10:30:14 +00:00
|
|
|
use crate::fluent_generated::*;
|
|
|
|
|
|
|
|
use UnsupportedOpInfo::*;
|
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`.
|
2023-08-06 16:40:37 +00:00
|
|
|
UnsizedLocal | 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
|
|
|
}
|
2024-02-10 14:41:08 +00:00
|
|
|
ThreadLocalStatic(did) | ExternStatic(did) => {
|
2024-02-12 04:18:18 +00:00
|
|
|
diag.arg("did", format!("{did:?}"));
|
2023-05-17 10:30:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'tcx> ReportErrorExt for InterpError<'tcx> {
|
|
|
|
fn diagnostic_message(&self) -> DiagnosticMessage {
|
|
|
|
match self {
|
|
|
|
InterpError::UndefinedBehavior(ub) => ub.diagnostic_message(),
|
|
|
|
InterpError::Unsupported(e) => e.diagnostic_message(),
|
|
|
|
InterpError::InvalidProgram(e) => e.diagnostic_message(),
|
|
|
|
InterpError::ResourceExhaustion(e) => e.diagnostic_message(),
|
|
|
|
InterpError::MachineStop(e) => e.diagnostic_message(),
|
|
|
|
}
|
|
|
|
}
|
2024-02-12 04:18:18 +00:00
|
|
|
fn add_args<G: EmissionGuarantee>(self, diag: &mut DiagnosticBuilder<'_, G>) {
|
2023-05-17 10:30:14 +00:00
|
|
|
match self {
|
2024-02-12 04:18:18 +00:00
|
|
|
InterpError::UndefinedBehavior(ub) => ub.add_args(diag),
|
|
|
|
InterpError::Unsupported(e) => e.add_args(diag),
|
|
|
|
InterpError::InvalidProgram(e) => e.add_args(diag),
|
|
|
|
InterpError::ResourceExhaustion(e) => e.add_args(diag),
|
2023-05-17 10:30:14 +00:00
|
|
|
InterpError::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> {
|
|
|
|
fn diagnostic_message(&self) -> DiagnosticMessage {
|
|
|
|
use crate::fluent_generated::*;
|
|
|
|
match self {
|
|
|
|
InvalidProgramInfo::TooGeneric => const_eval_too_generic,
|
|
|
|
InvalidProgramInfo::AlreadyReported(_) => const_eval_already_reported,
|
|
|
|
InvalidProgramInfo::Layout(e) => e.diagnostic_message(),
|
|
|
|
InvalidProgramInfo::FnAbiAdjustForForeignAbi(_) => {
|
|
|
|
rustc_middle::error::middle_adjust_for_foreign_abi_error
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2024-02-12 04:18:18 +00:00
|
|
|
fn add_args<G: EmissionGuarantee>(self, diag: &mut DiagnosticBuilder<'_, 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-02-12 04:18:18 +00:00
|
|
|
let dummy_diag: DiagnosticBuilder<'_, ()> =
|
|
|
|
e.into_diagnostic().into_diagnostic(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
|
|
|
}
|
|
|
|
InvalidProgramInfo::FnAbiAdjustForForeignAbi(
|
|
|
|
AdjustForForeignAbiError::Unsupported { arch, abi },
|
|
|
|
) => {
|
2024-02-12 04:18:18 +00:00
|
|
|
diag.arg("arch", arch);
|
|
|
|
diag.arg("abi", abi.name());
|
2023-05-17 10:30:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl ReportErrorExt for ResourceExhaustionInfo {
|
|
|
|
fn diagnostic_message(&self) -> DiagnosticMessage {
|
|
|
|
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,
|
|
|
|
}
|
|
|
|
}
|
2024-02-12 04:18:18 +00:00
|
|
|
fn add_args<G: EmissionGuarantee>(self, _: &mut DiagnosticBuilder<'_, G>) {}
|
2023-05-17 10:30:14 +00:00
|
|
|
}
|
2023-12-16 15:24:25 +00:00
|
|
|
|
|
|
|
impl rustc_errors::IntoDiagnosticArg for InternKind {
|
2024-01-30 04:27:16 +00:00
|
|
|
fn into_diagnostic_arg(self) -> DiagnosticArgValue {
|
2023-12-16 15:24:25 +00:00
|
|
|
DiagnosticArgValue::Str(Cow::Borrowed(match self {
|
|
|
|
InternKind::Static(Mutability::Not) => "static",
|
|
|
|
InternKind::Static(Mutability::Mut) => "static_mut",
|
|
|
|
InternKind::Constant => "const",
|
|
|
|
InternKind::Promoted => "promoted",
|
|
|
|
}))
|
|
|
|
}
|
|
|
|
}
|