2022-10-13 04:13:02 -05:00
|
|
|
use crate::fluent_generated as fluent;
|
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 17:57:07 -06:00
|
|
|
use rustc_errors::{codes::*, AddToDiagnostic, Diagnostic, SubdiagnosticMessage};
|
2022-09-18 10:47:31 -05:00
|
|
|
use rustc_macros::{Diagnostic, Subdiagnostic};
|
2022-09-07 08:36:08 -05:00
|
|
|
use rustc_session::lint::Level;
|
2022-08-19 19:04:21 -05:00
|
|
|
use rustc_span::{Span, Symbol};
|
2022-08-19 14:50:38 -05:00
|
|
|
|
2022-09-18 10:46:56 -05: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 17:57:07 -06:00
|
|
|
#[diag(lint_overruled_attribute, code = E0453)]
|
2022-10-06 19:28:51 -05:00
|
|
|
pub struct OverruledAttribute<'a> {
|
2022-08-19 19:47:05 -05:00
|
|
|
#[primary_span]
|
|
|
|
pub span: Span,
|
|
|
|
#[label]
|
|
|
|
pub overruled: Span,
|
2022-10-06 19:28:51 -05:00
|
|
|
pub lint_level: &'a str,
|
2022-08-19 19:47:05 -05:00
|
|
|
pub lint_source: Symbol,
|
|
|
|
#[subdiagnostic]
|
|
|
|
pub sub: OverruledAttributeSub,
|
|
|
|
}
|
|
|
|
//
|
|
|
|
pub enum OverruledAttributeSub {
|
|
|
|
DefaultSource { id: String },
|
|
|
|
NodeSource { span: Span, reason: Option<Symbol> },
|
|
|
|
CommandLineSource,
|
|
|
|
}
|
|
|
|
|
2022-09-18 10:46:16 -05:00
|
|
|
impl AddToDiagnostic for OverruledAttributeSub {
|
2022-10-03 08:09:05 -05:00
|
|
|
fn add_to_diagnostic_with<F>(self, diag: &mut Diagnostic, _: F)
|
|
|
|
where
|
|
|
|
F: Fn(&mut Diagnostic, SubdiagnosticMessage) -> SubdiagnosticMessage,
|
|
|
|
{
|
2022-08-19 19:47:05 -05:00
|
|
|
match self {
|
|
|
|
OverruledAttributeSub::DefaultSource { id } => {
|
2022-10-22 04:07:54 -05:00
|
|
|
diag.note(fluent::lint_default_source);
|
2023-12-23 16:08:41 -06:00
|
|
|
diag.arg("id", id);
|
2022-08-19 19:47:05 -05:00
|
|
|
}
|
|
|
|
OverruledAttributeSub::NodeSource { span, reason } => {
|
2022-10-22 04:07:54 -05:00
|
|
|
diag.span_label(span, fluent::lint_node_source);
|
2022-08-19 19:47:05 -05:00
|
|
|
if let Some(rationale) = reason {
|
2022-09-21 19:42:52 -05:00
|
|
|
#[allow(rustc::untranslatable_diagnostic)]
|
Use `Cow` in `{D,Subd}iagnosticMessage`.
Each of `{D,Subd}iagnosticMessage::{Str,Eager}` has a comment:
```
// FIXME(davidtwco): can a `Cow<'static, str>` be used here?
```
This commit answers that question in the affirmative. It's not the most
compelling change ever, but it might be worth merging.
This requires changing the `impl<'a> From<&'a str>` impls to `impl
From<&'static str>`, which involves a bunch of knock-on changes that
require/result in call sites being a little more precise about exactly
what kind of string they use to create errors, and not just `&str`. This
will result in fewer unnecessary allocations, though this will not have
any notable perf effects given that these are error paths.
Note that I was lazy within Clippy, using `to_string` in a few places to
preserve the existing string imprecision. I could have used `impl
Into<{D,Subd}iagnosticMessage>` in various places as is done in the
compiler, but that would have required changes to *many* call sites
(mostly changing `&format("...")` to `format!("...")`) which didn't seem
worthwhile.
2023-05-03 19:55:21 -05:00
|
|
|
diag.note(rationale.to_string());
|
2022-08-19 19:47:05 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
OverruledAttributeSub::CommandLineSource => {
|
2022-10-22 04:07:54 -05:00
|
|
|
diag.note(fluent::lint_command_line_source);
|
2022-08-19 19:47:05 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-18 10:46:56 -05: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 17:57:07 -06:00
|
|
|
#[diag(lint_malformed_attribute, code = E0452)]
|
2022-08-19 16:17:14 -05:00
|
|
|
pub struct MalformedAttribute {
|
|
|
|
#[primary_span]
|
|
|
|
pub span: Span,
|
|
|
|
#[subdiagnostic]
|
|
|
|
pub sub: MalformedAttributeSub,
|
|
|
|
}
|
|
|
|
|
2022-09-18 10:47:31 -05:00
|
|
|
#[derive(Subdiagnostic)]
|
2022-08-19 16:17:14 -05:00
|
|
|
pub enum MalformedAttributeSub {
|
2022-10-22 04:07:54 -05:00
|
|
|
#[label(lint_bad_attribute_argument)]
|
2022-08-19 16:17:14 -05:00
|
|
|
BadAttributeArgument(#[primary_span] Span),
|
2022-10-22 04:07:54 -05:00
|
|
|
#[label(lint_reason_must_be_string_literal)]
|
2022-08-19 16:17:14 -05:00
|
|
|
ReasonMustBeStringLiteral(#[primary_span] Span),
|
2022-10-22 04:07:54 -05:00
|
|
|
#[label(lint_reason_must_come_last)]
|
2022-08-19 16:17:14 -05:00
|
|
|
ReasonMustComeLast(#[primary_span] Span),
|
|
|
|
}
|
|
|
|
|
2022-09-18 10:46:56 -05: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 17:57:07 -06:00
|
|
|
#[diag(lint_unknown_tool_in_scoped_lint, code = E0710)]
|
2022-08-20 11:30:49 -05:00
|
|
|
pub struct UnknownToolInScopedLint {
|
2022-08-19 14:50:38 -05:00
|
|
|
#[primary_span]
|
|
|
|
pub span: Option<Span>,
|
2022-08-19 18:52:20 -05:00
|
|
|
pub tool_name: Symbol,
|
2022-08-19 14:50:38 -05:00
|
|
|
pub lint_name: String,
|
|
|
|
#[help]
|
|
|
|
pub is_nightly_build: Option<()>,
|
|
|
|
}
|
2022-08-20 11:11:07 -05:00
|
|
|
|
2022-09-18 10:46:56 -05: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 17:57:07 -06:00
|
|
|
#[diag(lint_builtin_ellipsis_inclusive_range_patterns, code = E0783)]
|
2023-04-09 16:35:02 -05:00
|
|
|
pub struct BuiltinEllipsisInclusiveRangePatterns {
|
2022-08-20 11:11:07 -05:00
|
|
|
#[primary_span]
|
|
|
|
pub span: Span,
|
2022-10-22 08:48:55 -05:00
|
|
|
#[suggestion(style = "short", code = "{replace}", applicability = "machine-applicable")]
|
2022-08-20 11:11:07 -05:00
|
|
|
pub suggestion: Span,
|
|
|
|
pub replace: String,
|
|
|
|
}
|
2022-08-20 14:48:03 -05:00
|
|
|
|
2022-10-14 07:25:12 -05:00
|
|
|
#[derive(Subdiagnostic)]
|
2022-10-22 04:07:54 -05:00
|
|
|
#[note(lint_requested_level)]
|
2023-08-23 18:23:01 -05:00
|
|
|
pub struct RequestedLevel<'a> {
|
2022-08-20 14:48:03 -05:00
|
|
|
pub level: Level,
|
2023-08-23 18:23:01 -05:00
|
|
|
pub lint_name: &'a str,
|
2022-08-20 14:48:03 -05:00
|
|
|
}
|
|
|
|
|
2022-09-18 10:46:56 -05: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 17:57:07 -06:00
|
|
|
#[diag(lint_unsupported_group, code = E0602)]
|
2022-08-20 14:48:03 -05:00
|
|
|
pub struct UnsupportedGroup {
|
|
|
|
pub lint_group: String,
|
|
|
|
}
|
|
|
|
|
2022-09-18 10:46:56 -05: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 17:57:07 -06:00
|
|
|
#[diag(lint_check_name_unknown_tool, code = E0602)]
|
2023-08-23 18:23:01 -05:00
|
|
|
pub struct CheckNameUnknownTool<'a> {
|
2022-08-20 14:48:03 -05:00
|
|
|
pub tool_name: Symbol,
|
|
|
|
#[subdiagnostic]
|
2023-08-23 18:23:01 -05:00
|
|
|
pub sub: RequestedLevel<'a>,
|
2022-08-20 14:48:03 -05:00
|
|
|
}
|