2022-08-21 08:46:05 +02:00
|
|
|
use std::num::IntErrorKind;
|
|
|
|
|
|
2022-08-21 22:11:41 +02:00
|
|
|
use rustc_ast as ast;
|
2024-06-18 10:35:56 +00:00
|
|
|
use rustc_errors::codes::*;
|
2025-03-04 14:17:06 +01:00
|
|
|
use rustc_errors::{
|
|
|
|
|
Applicability, Diag, DiagArgValue, DiagCtxtHandle, Diagnostic, EmissionGuarantee, Level,
|
|
|
|
|
};
|
|
|
|
|
use rustc_feature::AttributeTemplate;
|
|
|
|
|
use rustc_hir::AttrPath;
|
2025-02-12 13:59:08 +01:00
|
|
|
use rustc_macros::{Diagnostic, LintDiagnostic, Subdiagnostic};
|
2022-09-05 17:26:57 -04:00
|
|
|
use rustc_span::{Span, Symbol};
|
2022-08-21 08:46:05 +02:00
|
|
|
|
2024-12-07 15:27:17 +01:00
|
|
|
use crate::fluent_generated as fluent;
|
2022-08-21 08:46:05 +02:00
|
|
|
|
2025-02-09 22:49:33 +01:00
|
|
|
pub(crate) enum UnsupportedLiteralReason {
|
|
|
|
|
Generic,
|
|
|
|
|
CfgString,
|
|
|
|
|
CfgBoolean,
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-18 11:46:56 -04:00
|
|
|
#[derive(Diagnostic)]
|
2024-12-13 14:47:11 +01:00
|
|
|
#[diag(attr_parsing_expected_one_cfg_pattern, code = E0536)]
|
2022-08-21 21:43:03 +02:00
|
|
|
pub(crate) struct ExpectedOneCfgPattern {
|
2022-08-21 08:46:05 +02:00
|
|
|
#[primary_span]
|
|
|
|
|
pub span: Span,
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-18 11:46:56 -04:00
|
|
|
#[derive(Diagnostic)]
|
2024-12-13 14:47:11 +01:00
|
|
|
#[diag(attr_parsing_invalid_predicate, code = E0537)]
|
2022-08-21 21:43:03 +02:00
|
|
|
pub(crate) struct InvalidPredicate {
|
2022-08-21 08:46:05 +02:00
|
|
|
#[primary_span]
|
|
|
|
|
pub span: Span,
|
|
|
|
|
|
2022-08-21 21:43:03 +02:00
|
|
|
pub predicate: String,
|
2022-08-21 08:46:05 +02:00
|
|
|
}
|
|
|
|
|
|
2022-11-27 11:15:06 +00:00
|
|
|
/// Error code: E0541
|
2022-08-21 21:43:03 +02:00
|
|
|
pub(crate) struct UnknownMetaItem<'a> {
|
2022-08-21 12:36:16 +02:00
|
|
|
pub span: Span,
|
2022-08-21 21:43:03 +02:00
|
|
|
pub item: String,
|
|
|
|
|
pub expected: &'a [&'a str],
|
2022-08-21 12:36:16 +02:00
|
|
|
}
|
|
|
|
|
|
2022-08-21 21:43:03 +02:00
|
|
|
// Manual implementation to be able to format `expected` items correctly.
|
2024-03-06 11:02:56 +11:00
|
|
|
impl<'a, G: EmissionGuarantee> Diagnostic<'a, G> for UnknownMetaItem<'_> {
|
2024-06-18 10:35:56 +00:00
|
|
|
fn into_diag(self, dcx: DiagCtxtHandle<'a>, level: Level) -> Diag<'a, G> {
|
2022-12-19 10:31:55 +01:00
|
|
|
let expected = self.expected.iter().map(|name| format!("`{name}`")).collect::<Vec<_>>();
|
2024-12-13 14:47:11 +01:00
|
|
|
Diag::new(dcx, level, fluent::attr_parsing_unknown_meta_item)
|
2024-01-09 09:08:49 +11:00
|
|
|
.with_span(self.span)
|
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-14 10:57:07 +11:00
|
|
|
.with_code(E0541)
|
2024-01-09 09:08:49 +11:00
|
|
|
.with_arg("item", self.item)
|
|
|
|
|
.with_arg("expected", expected.join(", "))
|
2024-12-13 14:47:11 +01:00
|
|
|
.with_span_label(self.span, fluent::attr_parsing_label)
|
2022-08-21 21:43:03 +02:00
|
|
|
}
|
2022-08-21 12:36:16 +02:00
|
|
|
}
|
|
|
|
|
|
2022-09-18 11:46:56 -04:00
|
|
|
#[derive(Diagnostic)]
|
2024-12-13 14:47:11 +01:00
|
|
|
#[diag(attr_parsing_missing_since, code = E0542)]
|
2022-08-21 21:43:03 +02:00
|
|
|
pub(crate) struct MissingSince {
|
2022-08-21 12:36:16 +02:00
|
|
|
#[primary_span]
|
|
|
|
|
pub span: Span,
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-18 11:46:56 -04:00
|
|
|
#[derive(Diagnostic)]
|
2024-12-13 14:47:11 +01:00
|
|
|
#[diag(attr_parsing_missing_note, code = E0543)]
|
2022-08-21 21:43:03 +02:00
|
|
|
pub(crate) struct MissingNote {
|
2022-08-21 12:36:16 +02:00
|
|
|
#[primary_span]
|
|
|
|
|
pub span: Span,
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-18 11:46:56 -04:00
|
|
|
#[derive(Diagnostic)]
|
2024-12-13 14:47:11 +01:00
|
|
|
#[diag(attr_parsing_multiple_stability_levels, code = E0544)]
|
2022-08-21 21:43:03 +02:00
|
|
|
pub(crate) struct MultipleStabilityLevels {
|
2022-08-21 12:36:16 +02:00
|
|
|
#[primary_span]
|
|
|
|
|
pub span: Span,
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-18 11:46:56 -04:00
|
|
|
#[derive(Diagnostic)]
|
2024-12-13 14:47:11 +01:00
|
|
|
#[diag(attr_parsing_invalid_issue_string, code = E0545)]
|
2022-08-21 08:46:05 +02:00
|
|
|
pub(crate) struct InvalidIssueString {
|
|
|
|
|
#[primary_span]
|
|
|
|
|
pub span: Span,
|
|
|
|
|
|
|
|
|
|
#[subdiagnostic]
|
|
|
|
|
pub cause: Option<InvalidIssueStringCause>,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// The error kinds of `IntErrorKind` are duplicated here in order to allow the messages to be
|
|
|
|
|
// translatable.
|
2022-09-18 11:47:31 -04:00
|
|
|
#[derive(Subdiagnostic)]
|
2022-08-21 08:46:05 +02:00
|
|
|
pub(crate) enum InvalidIssueStringCause {
|
2024-12-13 14:47:11 +01:00
|
|
|
#[label(attr_parsing_must_not_be_zero)]
|
2022-08-21 08:46:05 +02:00
|
|
|
MustNotBeZero {
|
|
|
|
|
#[primary_span]
|
|
|
|
|
span: Span,
|
|
|
|
|
},
|
|
|
|
|
|
2024-12-13 14:47:11 +01:00
|
|
|
#[label(attr_parsing_empty)]
|
2022-08-21 08:46:05 +02:00
|
|
|
Empty {
|
|
|
|
|
#[primary_span]
|
|
|
|
|
span: Span,
|
|
|
|
|
},
|
|
|
|
|
|
2024-12-13 14:47:11 +01:00
|
|
|
#[label(attr_parsing_invalid_digit)]
|
2022-08-21 08:46:05 +02:00
|
|
|
InvalidDigit {
|
|
|
|
|
#[primary_span]
|
|
|
|
|
span: Span,
|
|
|
|
|
},
|
|
|
|
|
|
2024-12-13 14:47:11 +01:00
|
|
|
#[label(attr_parsing_pos_overflow)]
|
2022-08-21 08:46:05 +02:00
|
|
|
PosOverflow {
|
|
|
|
|
#[primary_span]
|
|
|
|
|
span: Span,
|
|
|
|
|
},
|
|
|
|
|
|
2024-12-13 14:47:11 +01:00
|
|
|
#[label(attr_parsing_neg_overflow)]
|
2022-08-21 08:46:05 +02:00
|
|
|
NegOverflow {
|
|
|
|
|
#[primary_span]
|
|
|
|
|
span: Span,
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl InvalidIssueStringCause {
|
2024-07-06 21:31:11 +10:00
|
|
|
pub(crate) fn from_int_error_kind(span: Span, kind: &IntErrorKind) -> Option<Self> {
|
2022-08-21 08:46:05 +02:00
|
|
|
match kind {
|
|
|
|
|
IntErrorKind::Empty => Some(Self::Empty { span }),
|
|
|
|
|
IntErrorKind::InvalidDigit => Some(Self::InvalidDigit { span }),
|
|
|
|
|
IntErrorKind::PosOverflow => Some(Self::PosOverflow { span }),
|
|
|
|
|
IntErrorKind::NegOverflow => Some(Self::NegOverflow { span }),
|
|
|
|
|
IntErrorKind::Zero => Some(Self::MustNotBeZero { span }),
|
|
|
|
|
_ => None,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-18 11:46:56 -04:00
|
|
|
#[derive(Diagnostic)]
|
2024-12-13 14:47:11 +01:00
|
|
|
#[diag(attr_parsing_missing_feature, code = E0546)]
|
2022-08-21 21:43:03 +02:00
|
|
|
pub(crate) struct MissingFeature {
|
|
|
|
|
#[primary_span]
|
2022-08-21 08:46:05 +02:00
|
|
|
pub span: Span,
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-18 11:46:56 -04:00
|
|
|
#[derive(Diagnostic)]
|
2024-12-13 14:47:11 +01:00
|
|
|
#[diag(attr_parsing_non_ident_feature, code = E0546)]
|
2022-08-21 21:43:03 +02:00
|
|
|
pub(crate) struct NonIdentFeature {
|
|
|
|
|
#[primary_span]
|
|
|
|
|
pub span: Span,
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-18 11:46:56 -04:00
|
|
|
#[derive(Diagnostic)]
|
2024-12-13 14:47:11 +01:00
|
|
|
#[diag(attr_parsing_missing_issue, code = E0547)]
|
2022-08-21 21:43:03 +02:00
|
|
|
pub(crate) struct MissingIssue {
|
|
|
|
|
#[primary_span]
|
|
|
|
|
pub span: Span,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// FIXME: Why is this the same error code as `InvalidReprHintNoParen` and `InvalidReprHintNoValue`?
|
|
|
|
|
// It is more similar to `IncorrectReprFormatGeneric`.
|
2022-09-18 11:46:56 -04:00
|
|
|
#[derive(Diagnostic)]
|
2024-12-13 14:47:11 +01:00
|
|
|
#[diag(attr_parsing_incorrect_repr_format_packed_one_or_zero_arg, code = E0552)]
|
2022-08-21 21:43:03 +02:00
|
|
|
pub(crate) struct IncorrectReprFormatPackedOneOrZeroArg {
|
|
|
|
|
#[primary_span]
|
|
|
|
|
pub span: Span,
|
|
|
|
|
}
|
2024-03-02 22:42:13 +08:00
|
|
|
#[derive(Diagnostic)]
|
2024-12-13 14:47:11 +01:00
|
|
|
#[diag(attr_parsing_incorrect_repr_format_packed_expect_integer, code = E0552)]
|
2024-03-02 22:42:13 +08:00
|
|
|
pub(crate) struct IncorrectReprFormatPackedExpectInteger {
|
|
|
|
|
#[primary_span]
|
|
|
|
|
pub span: Span,
|
|
|
|
|
}
|
2022-08-21 21:43:03 +02:00
|
|
|
|
2022-09-18 11:46:56 -04:00
|
|
|
#[derive(Diagnostic)]
|
2024-12-13 14:47:11 +01:00
|
|
|
#[diag(attr_parsing_invalid_repr_hint_no_paren, code = E0552)]
|
2022-08-21 21:43:03 +02:00
|
|
|
pub(crate) struct InvalidReprHintNoParen {
|
|
|
|
|
#[primary_span]
|
|
|
|
|
pub span: Span,
|
|
|
|
|
|
2025-05-07 12:50:56 +10:00
|
|
|
pub name: Symbol,
|
2022-08-21 08:46:05 +02:00
|
|
|
}
|
|
|
|
|
|
2022-09-18 11:46:56 -04:00
|
|
|
#[derive(Diagnostic)]
|
2024-12-13 14:47:11 +01:00
|
|
|
#[diag(attr_parsing_invalid_repr_hint_no_value, code = E0552)]
|
2022-08-21 21:43:03 +02:00
|
|
|
pub(crate) struct InvalidReprHintNoValue {
|
|
|
|
|
#[primary_span]
|
|
|
|
|
pub span: Span,
|
|
|
|
|
|
2025-05-07 12:50:56 +10:00
|
|
|
pub name: Symbol,
|
2022-08-21 21:43:03 +02:00
|
|
|
}
|
|
|
|
|
|
2022-11-27 11:15:06 +00:00
|
|
|
/// Error code: E0565
|
2025-03-08 18:58:05 +01:00
|
|
|
// FIXME(jdonszelmann): slowly phased out
|
2022-09-05 17:26:57 -04:00
|
|
|
pub(crate) struct UnsupportedLiteral {
|
2022-08-21 08:46:05 +02:00
|
|
|
pub span: Span,
|
|
|
|
|
pub reason: UnsupportedLiteralReason,
|
|
|
|
|
pub is_bytestr: bool,
|
2022-09-05 17:26:57 -04:00
|
|
|
pub start_point_span: Span,
|
2022-08-21 08:46:05 +02:00
|
|
|
}
|
|
|
|
|
|
2024-03-06 11:02:56 +11:00
|
|
|
impl<'a, G: EmissionGuarantee> Diagnostic<'a, G> for UnsupportedLiteral {
|
2024-06-18 10:35:56 +00:00
|
|
|
fn into_diag(self, dcx: DiagCtxtHandle<'a>, level: Level) -> Diag<'a, G> {
|
2024-02-23 10:20:45 +11:00
|
|
|
let mut diag = Diag::new(
|
|
|
|
|
dcx,
|
|
|
|
|
level,
|
|
|
|
|
match self.reason {
|
2024-12-13 14:47:11 +01:00
|
|
|
UnsupportedLiteralReason::Generic => {
|
|
|
|
|
fluent::attr_parsing_unsupported_literal_generic
|
2025-02-08 22:12:13 +00:00
|
|
|
}
|
2024-12-13 14:47:11 +01:00
|
|
|
UnsupportedLiteralReason::CfgString => {
|
|
|
|
|
fluent::attr_parsing_unsupported_literal_cfg_string
|
|
|
|
|
}
|
|
|
|
|
UnsupportedLiteralReason::CfgBoolean => {
|
|
|
|
|
fluent::attr_parsing_unsupported_literal_cfg_boolean
|
|
|
|
|
}
|
2022-08-21 08:46:05 +02:00
|
|
|
},
|
|
|
|
|
);
|
2023-12-24 09:08:41 +11:00
|
|
|
diag.span(self.span);
|
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-14 10:57:07 +11:00
|
|
|
diag.code(E0565);
|
2022-08-21 08:46:05 +02:00
|
|
|
if self.is_bytestr {
|
2022-08-27 02:23:21 +09:00
|
|
|
diag.span_suggestion(
|
2022-09-05 17:26:57 -04:00
|
|
|
self.start_point_span,
|
2024-12-13 14:47:11 +01:00
|
|
|
fluent::attr_parsing_unsupported_literal_suggestion,
|
2022-08-27 02:23:21 +09:00
|
|
|
"",
|
|
|
|
|
Applicability::MaybeIncorrect,
|
|
|
|
|
);
|
2022-08-21 08:46:05 +02:00
|
|
|
}
|
|
|
|
|
diag
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-08-21 21:52:15 +02:00
|
|
|
|
2022-09-18 11:46:56 -04:00
|
|
|
#[derive(Diagnostic)]
|
2024-12-13 14:47:11 +01:00
|
|
|
#[diag(attr_parsing_invalid_repr_align_need_arg, code = E0589)]
|
2022-08-21 21:43:03 +02:00
|
|
|
pub(crate) struct InvalidReprAlignNeedArg {
|
|
|
|
|
#[primary_span]
|
|
|
|
|
#[suggestion(code = "align(...)", applicability = "has-placeholders")]
|
|
|
|
|
pub span: Span,
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-18 11:46:56 -04:00
|
|
|
#[derive(Diagnostic)]
|
2024-12-13 14:47:11 +01:00
|
|
|
#[diag(attr_parsing_invalid_repr_generic, code = E0589)]
|
2022-08-21 21:43:03 +02:00
|
|
|
pub(crate) struct InvalidReprGeneric<'a> {
|
|
|
|
|
#[primary_span]
|
|
|
|
|
pub span: Span,
|
|
|
|
|
|
|
|
|
|
pub repr_arg: String,
|
|
|
|
|
pub error_part: &'a str,
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-18 11:46:56 -04:00
|
|
|
#[derive(Diagnostic)]
|
2024-12-13 14:47:11 +01:00
|
|
|
#[diag(attr_parsing_incorrect_repr_format_align_one_arg, code = E0693)]
|
2022-08-21 21:43:03 +02:00
|
|
|
pub(crate) struct IncorrectReprFormatAlignOneArg {
|
|
|
|
|
#[primary_span]
|
2024-03-02 22:42:13 +08:00
|
|
|
pub span: Span,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[derive(Diagnostic)]
|
2024-12-13 14:47:11 +01:00
|
|
|
#[diag(attr_parsing_incorrect_repr_format_expect_literal_integer, code = E0693)]
|
2024-03-02 22:42:13 +08:00
|
|
|
pub(crate) struct IncorrectReprFormatExpectInteger {
|
|
|
|
|
#[primary_span]
|
2022-08-21 21:43:03 +02:00
|
|
|
pub span: Span,
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-18 11:46:56 -04:00
|
|
|
#[derive(Diagnostic)]
|
2024-12-13 14:47:11 +01:00
|
|
|
#[diag(attr_parsing_incorrect_repr_format_generic, code = E0693)]
|
2025-05-07 12:50:56 +10:00
|
|
|
pub(crate) struct IncorrectReprFormatGeneric {
|
2022-08-21 21:43:03 +02:00
|
|
|
#[primary_span]
|
|
|
|
|
pub span: Span,
|
|
|
|
|
|
2025-05-07 12:50:56 +10:00
|
|
|
pub repr_arg: Symbol,
|
2022-08-21 21:43:03 +02:00
|
|
|
|
|
|
|
|
#[subdiagnostic]
|
2025-05-07 12:50:56 +10:00
|
|
|
pub cause: Option<IncorrectReprFormatGenericCause>,
|
2022-08-21 21:43:03 +02:00
|
|
|
}
|
|
|
|
|
|
2022-09-18 11:47:31 -04:00
|
|
|
#[derive(Subdiagnostic)]
|
2025-05-07 12:50:56 +10:00
|
|
|
pub(crate) enum IncorrectReprFormatGenericCause {
|
2024-12-13 14:47:11 +01:00
|
|
|
#[suggestion(
|
|
|
|
|
attr_parsing_suggestion,
|
2025-05-07 12:50:56 +10:00
|
|
|
code = "{name}({value})",
|
2024-12-13 14:47:11 +01:00
|
|
|
applicability = "machine-applicable"
|
|
|
|
|
)]
|
2022-08-21 21:43:03 +02:00
|
|
|
Int {
|
|
|
|
|
#[primary_span]
|
|
|
|
|
span: Span,
|
|
|
|
|
|
|
|
|
|
#[skip_arg]
|
2025-05-07 12:50:56 +10:00
|
|
|
name: Symbol,
|
2022-08-21 21:43:03 +02:00
|
|
|
|
|
|
|
|
#[skip_arg]
|
2025-05-07 12:50:56 +10:00
|
|
|
value: u128,
|
2022-08-21 21:43:03 +02:00
|
|
|
},
|
|
|
|
|
|
2024-12-13 14:47:11 +01:00
|
|
|
#[suggestion(
|
|
|
|
|
attr_parsing_suggestion,
|
2025-05-07 12:50:56 +10:00
|
|
|
code = "{name}({value})",
|
2024-12-13 14:47:11 +01:00
|
|
|
applicability = "machine-applicable"
|
|
|
|
|
)]
|
2022-08-21 21:43:03 +02:00
|
|
|
Symbol {
|
|
|
|
|
#[primary_span]
|
|
|
|
|
span: Span,
|
|
|
|
|
|
|
|
|
|
#[skip_arg]
|
2025-05-07 12:50:56 +10:00
|
|
|
name: Symbol,
|
2022-08-21 21:43:03 +02:00
|
|
|
|
|
|
|
|
#[skip_arg]
|
2025-05-07 12:50:56 +10:00
|
|
|
value: Symbol,
|
2022-08-21 21:43:03 +02:00
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
|
2025-05-07 12:50:56 +10:00
|
|
|
impl IncorrectReprFormatGenericCause {
|
|
|
|
|
pub(crate) fn from_lit_kind(span: Span, kind: &ast::LitKind, name: Symbol) -> Option<Self> {
|
|
|
|
|
match *kind {
|
|
|
|
|
ast::LitKind::Int(value, ast::LitIntType::Unsuffixed) => {
|
|
|
|
|
Some(Self::Int { span, name, value: value.get() })
|
2022-08-21 22:11:41 +02:00
|
|
|
}
|
2025-05-07 12:50:56 +10:00
|
|
|
ast::LitKind::Str(value, _) => Some(Self::Symbol { span, name, value }),
|
2022-08-21 22:11:41 +02:00
|
|
|
_ => None,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-18 11:46:56 -04:00
|
|
|
#[derive(Diagnostic)]
|
2024-12-13 14:47:11 +01:00
|
|
|
#[diag(attr_parsing_rustc_promotable_pairing, code = E0717)]
|
2022-08-21 21:43:03 +02:00
|
|
|
pub(crate) struct RustcPromotablePairing {
|
|
|
|
|
#[primary_span]
|
|
|
|
|
pub span: Span,
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-18 11:46:56 -04:00
|
|
|
#[derive(Diagnostic)]
|
2024-12-13 14:47:11 +01:00
|
|
|
#[diag(attr_parsing_rustc_allowed_unstable_pairing, code = E0789)]
|
2022-08-21 21:43:03 +02:00
|
|
|
pub(crate) struct RustcAllowedUnstablePairing {
|
|
|
|
|
#[primary_span]
|
|
|
|
|
pub span: Span,
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-18 11:46:56 -04:00
|
|
|
#[derive(Diagnostic)]
|
2024-12-13 14:47:11 +01:00
|
|
|
#[diag(attr_parsing_cfg_predicate_identifier)]
|
2022-08-21 21:43:03 +02:00
|
|
|
pub(crate) struct CfgPredicateIdentifier {
|
|
|
|
|
#[primary_span]
|
|
|
|
|
pub span: Span,
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-18 11:46:56 -04:00
|
|
|
#[derive(Diagnostic)]
|
2024-12-13 14:47:11 +01:00
|
|
|
#[diag(attr_parsing_deprecated_item_suggestion)]
|
2022-08-21 21:43:03 +02:00
|
|
|
pub(crate) struct DeprecatedItemSuggestion {
|
|
|
|
|
#[primary_span]
|
|
|
|
|
pub span: Span,
|
|
|
|
|
|
|
|
|
|
#[help]
|
2024-08-21 00:57:58 -04:00
|
|
|
pub is_nightly: bool,
|
2022-08-21 22:11:41 +02:00
|
|
|
|
|
|
|
|
#[note]
|
|
|
|
|
pub details: (),
|
2022-08-21 21:43:03 +02:00
|
|
|
}
|
|
|
|
|
|
2022-09-18 11:46:56 -04:00
|
|
|
#[derive(Diagnostic)]
|
2024-12-13 14:47:11 +01:00
|
|
|
#[diag(attr_parsing_expected_single_version_literal)]
|
2022-08-21 21:43:03 +02:00
|
|
|
pub(crate) struct ExpectedSingleVersionLiteral {
|
|
|
|
|
#[primary_span]
|
|
|
|
|
pub span: Span,
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-18 11:46:56 -04:00
|
|
|
#[derive(Diagnostic)]
|
2024-12-13 14:47:11 +01:00
|
|
|
#[diag(attr_parsing_expected_version_literal)]
|
2022-08-21 21:43:03 +02:00
|
|
|
pub(crate) struct ExpectedVersionLiteral {
|
|
|
|
|
#[primary_span]
|
|
|
|
|
pub span: Span,
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-18 11:46:56 -04:00
|
|
|
#[derive(Diagnostic)]
|
2024-12-13 14:47:11 +01:00
|
|
|
#[diag(attr_parsing_expects_feature_list)]
|
2022-08-21 21:43:03 +02:00
|
|
|
pub(crate) struct ExpectsFeatureList {
|
|
|
|
|
#[primary_span]
|
|
|
|
|
pub span: Span,
|
|
|
|
|
|
|
|
|
|
pub name: String,
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-18 11:46:56 -04:00
|
|
|
#[derive(Diagnostic)]
|
2024-12-13 14:47:11 +01:00
|
|
|
#[diag(attr_parsing_expects_features)]
|
2022-08-21 21:43:03 +02:00
|
|
|
pub(crate) struct ExpectsFeatures {
|
|
|
|
|
#[primary_span]
|
|
|
|
|
pub span: Span,
|
|
|
|
|
|
|
|
|
|
pub name: String,
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-16 12:30:32 -07:00
|
|
|
#[derive(Diagnostic)]
|
2024-12-13 14:47:11 +01:00
|
|
|
#[diag(attr_parsing_invalid_since)]
|
2023-10-16 12:30:32 -07:00
|
|
|
pub(crate) struct InvalidSince {
|
|
|
|
|
#[primary_span]
|
|
|
|
|
pub span: Span,
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-18 11:46:56 -04:00
|
|
|
#[derive(Diagnostic)]
|
2024-12-13 14:47:11 +01:00
|
|
|
#[diag(attr_parsing_soft_no_args)]
|
2022-08-21 21:43:03 +02:00
|
|
|
pub(crate) struct SoftNoArgs {
|
|
|
|
|
#[primary_span]
|
|
|
|
|
pub span: Span,
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-18 11:46:56 -04:00
|
|
|
#[derive(Diagnostic)]
|
2024-12-13 14:47:11 +01:00
|
|
|
#[diag(attr_parsing_unknown_version_literal)]
|
2022-08-21 21:43:03 +02:00
|
|
|
pub(crate) struct UnknownVersionLiteral {
|
|
|
|
|
#[primary_span]
|
|
|
|
|
pub span: Span,
|
|
|
|
|
}
|
2025-02-09 22:49:33 +01:00
|
|
|
|
|
|
|
|
// FIXME(jdonszelmann) duplicated from `rustc_passes`, remove once `check_attr` is integrated.
|
|
|
|
|
#[derive(Diagnostic)]
|
|
|
|
|
#[diag(attr_parsing_unused_multiple)]
|
|
|
|
|
pub(crate) struct UnusedMultiple {
|
|
|
|
|
#[primary_span]
|
|
|
|
|
#[suggestion(code = "", applicability = "machine-applicable")]
|
|
|
|
|
pub this: Span,
|
|
|
|
|
#[note]
|
|
|
|
|
pub other: Span,
|
|
|
|
|
pub name: Symbol,
|
|
|
|
|
}
|
|
|
|
|
|
2025-02-12 13:59:08 +01:00
|
|
|
#[derive(LintDiagnostic)]
|
2025-03-03 17:45:14 +01:00
|
|
|
#[diag(attr_parsing_unused_duplicate)]
|
2025-02-12 13:59:08 +01:00
|
|
|
pub(crate) struct UnusedDuplicate {
|
|
|
|
|
#[suggestion(code = "", applicability = "machine-applicable")]
|
|
|
|
|
pub this: Span,
|
|
|
|
|
#[note]
|
|
|
|
|
pub other: Span,
|
|
|
|
|
#[warning]
|
|
|
|
|
pub warning: bool,
|
|
|
|
|
}
|
|
|
|
|
|
2025-03-04 14:17:06 +01:00
|
|
|
// FIXME(jdonszelmann): duplicated in rustc_lints, should be moved here completely.
|
|
|
|
|
#[derive(LintDiagnostic)]
|
|
|
|
|
#[diag(attr_parsing_ill_formed_attribute_input)]
|
|
|
|
|
pub(crate) struct IllFormedAttributeInput {
|
|
|
|
|
pub num_suggestions: usize,
|
|
|
|
|
pub suggestions: DiagArgValue,
|
|
|
|
|
}
|
|
|
|
|
|
2025-06-22 12:09:14 +02:00
|
|
|
#[derive(Diagnostic)]
|
|
|
|
|
#[diag(attr_parsing_ill_formed_attribute_input)]
|
|
|
|
|
pub(crate) struct MustUseIllFormedAttributeInput {
|
|
|
|
|
#[primary_span]
|
|
|
|
|
pub span: Span,
|
|
|
|
|
pub num_suggestions: usize,
|
|
|
|
|
pub suggestions: DiagArgValue,
|
|
|
|
|
}
|
|
|
|
|
|
2025-06-24 22:33:44 +02:00
|
|
|
#[derive(Diagnostic)]
|
|
|
|
|
#[diag(attr_parsing_null_on_export, code = E0648)]
|
|
|
|
|
pub(crate) struct NullOnExport {
|
|
|
|
|
#[primary_span]
|
|
|
|
|
pub span: Span,
|
|
|
|
|
}
|
|
|
|
|
|
2025-06-29 15:37:54 +02:00
|
|
|
#[derive(Diagnostic)]
|
|
|
|
|
#[diag(attr_parsing_null_on_link_section, code = E0648)]
|
|
|
|
|
pub(crate) struct NullOnLinkSection {
|
|
|
|
|
#[primary_span]
|
|
|
|
|
pub span: Span,
|
|
|
|
|
}
|
|
|
|
|
|
2025-02-09 22:49:33 +01:00
|
|
|
#[derive(Diagnostic)]
|
|
|
|
|
#[diag(attr_parsing_stability_outside_std, code = E0734)]
|
|
|
|
|
pub(crate) struct StabilityOutsideStd {
|
|
|
|
|
#[primary_span]
|
|
|
|
|
pub span: Span,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[derive(Diagnostic)]
|
|
|
|
|
#[diag(attr_parsing_empty_confusables)]
|
|
|
|
|
pub(crate) struct EmptyConfusables {
|
|
|
|
|
#[primary_span]
|
|
|
|
|
pub span: Span,
|
|
|
|
|
}
|
|
|
|
|
|
2025-06-09 20:08:52 +02:00
|
|
|
#[derive(Diagnostic)]
|
|
|
|
|
#[diag(attr_parsing_invalid_alignment_value, code = E0589)]
|
|
|
|
|
pub(crate) struct InvalidAlignmentValue {
|
|
|
|
|
#[primary_span]
|
|
|
|
|
pub span: Span,
|
|
|
|
|
pub error_part: &'static str,
|
|
|
|
|
}
|
|
|
|
|
|
2025-02-09 22:49:33 +01:00
|
|
|
#[derive(Diagnostic)]
|
|
|
|
|
#[diag(attr_parsing_repr_ident, code = E0565)]
|
|
|
|
|
pub(crate) struct ReprIdent {
|
|
|
|
|
#[primary_span]
|
|
|
|
|
pub span: Span,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[derive(Diagnostic)]
|
|
|
|
|
#[diag(attr_parsing_unrecognized_repr_hint, code = E0552)]
|
|
|
|
|
#[help]
|
|
|
|
|
pub(crate) struct UnrecognizedReprHint {
|
|
|
|
|
#[primary_span]
|
|
|
|
|
pub span: Span,
|
|
|
|
|
}
|
2025-03-04 14:17:06 +01:00
|
|
|
|
2025-06-13 02:28:33 +02:00
|
|
|
#[derive(Diagnostic)]
|
|
|
|
|
#[diag(attr_parsing_naked_functions_incompatible_attribute, code = E0736)]
|
|
|
|
|
pub(crate) struct NakedFunctionIncompatibleAttribute {
|
|
|
|
|
#[primary_span]
|
|
|
|
|
#[label]
|
|
|
|
|
pub span: Span,
|
|
|
|
|
#[label(attr_parsing_naked_attribute)]
|
|
|
|
|
pub naked_span: Span,
|
|
|
|
|
pub attr: String,
|
|
|
|
|
}
|
|
|
|
|
|
2025-03-04 14:17:06 +01:00
|
|
|
pub(crate) enum AttributeParseErrorReason {
|
2025-06-12 13:52:23 +02:00
|
|
|
ExpectedNoArgs,
|
2025-03-08 18:58:05 +01:00
|
|
|
ExpectedStringLiteral { byte_string: Option<Span> },
|
2025-06-25 09:44:52 +02:00
|
|
|
ExpectedIntegerLiteral,
|
2025-06-18 22:27:35 +03:00
|
|
|
ExpectedAtLeastOneArgument,
|
2025-03-04 14:17:06 +01:00
|
|
|
ExpectedSingleArgument,
|
2025-03-05 14:35:54 +01:00
|
|
|
ExpectedList,
|
2025-03-08 18:58:05 +01:00
|
|
|
UnexpectedLiteral,
|
2025-03-05 14:35:54 +01:00
|
|
|
ExpectedNameValue(Option<Symbol>),
|
|
|
|
|
DuplicateKey(Symbol),
|
|
|
|
|
ExpectedSpecificArgument { possibilities: Vec<&'static str>, strings: bool },
|
2025-03-04 14:17:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub(crate) struct AttributeParseError {
|
|
|
|
|
pub(crate) span: Span,
|
|
|
|
|
pub(crate) attr_span: Span,
|
|
|
|
|
pub(crate) template: AttributeTemplate,
|
|
|
|
|
pub(crate) attribute: AttrPath,
|
|
|
|
|
pub(crate) reason: AttributeParseErrorReason,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl<'a, G: EmissionGuarantee> Diagnostic<'a, G> for AttributeParseError {
|
|
|
|
|
fn into_diag(self, dcx: DiagCtxtHandle<'a>, level: Level) -> Diag<'a, G> {
|
|
|
|
|
let name = self.attribute.to_string();
|
|
|
|
|
|
|
|
|
|
let mut diag = Diag::new(dcx, level, format!("malformed `{name}` attribute input"));
|
|
|
|
|
diag.span(self.attr_span);
|
|
|
|
|
diag.code(E0539);
|
|
|
|
|
match self.reason {
|
2025-03-08 18:58:05 +01:00
|
|
|
AttributeParseErrorReason::ExpectedStringLiteral { byte_string } => {
|
|
|
|
|
if let Some(start_point_span) = byte_string {
|
|
|
|
|
diag.span_suggestion(
|
|
|
|
|
start_point_span,
|
|
|
|
|
fluent::attr_parsing_unsupported_literal_suggestion,
|
|
|
|
|
"",
|
|
|
|
|
Applicability::MaybeIncorrect,
|
|
|
|
|
);
|
|
|
|
|
diag.note("expected a normal string literal, not a byte string literal");
|
|
|
|
|
|
|
|
|
|
return diag;
|
|
|
|
|
} else {
|
|
|
|
|
diag.span_label(self.span, "expected a string literal here");
|
|
|
|
|
}
|
2025-03-04 14:17:06 +01:00
|
|
|
}
|
2025-06-25 09:44:52 +02:00
|
|
|
AttributeParseErrorReason::ExpectedIntegerLiteral => {
|
|
|
|
|
diag.span_label(self.span, "expected an integer literal here");
|
|
|
|
|
}
|
2025-03-04 14:17:06 +01:00
|
|
|
AttributeParseErrorReason::ExpectedSingleArgument => {
|
2025-03-08 18:58:05 +01:00
|
|
|
diag.span_label(self.span, "expected a single argument here");
|
|
|
|
|
diag.code(E0805);
|
2025-03-04 14:17:06 +01:00
|
|
|
}
|
2025-06-18 22:27:35 +03:00
|
|
|
AttributeParseErrorReason::ExpectedAtLeastOneArgument => {
|
|
|
|
|
diag.span_label(self.span, "expected at least 1 argument here");
|
|
|
|
|
}
|
2025-03-05 14:35:54 +01:00
|
|
|
AttributeParseErrorReason::ExpectedList => {
|
2025-03-08 18:58:05 +01:00
|
|
|
diag.span_label(self.span, "expected this to be a list");
|
2025-03-05 14:35:54 +01:00
|
|
|
}
|
|
|
|
|
AttributeParseErrorReason::DuplicateKey(key) => {
|
2025-03-08 18:58:05 +01:00
|
|
|
diag.span_label(self.span, format!("found `{key}` used as a key more than once"));
|
2025-03-05 14:35:54 +01:00
|
|
|
diag.code(E0538);
|
|
|
|
|
}
|
2025-03-08 18:58:05 +01:00
|
|
|
AttributeParseErrorReason::UnexpectedLiteral => {
|
|
|
|
|
diag.span_label(self.span, format!("didn't expect a literal here"));
|
|
|
|
|
diag.code(E0565);
|
|
|
|
|
}
|
2025-06-12 13:52:23 +02:00
|
|
|
AttributeParseErrorReason::ExpectedNoArgs => {
|
|
|
|
|
diag.span_label(self.span, format!("didn't expect any arguments here"));
|
|
|
|
|
diag.code(E0565);
|
|
|
|
|
}
|
2025-03-05 14:35:54 +01:00
|
|
|
AttributeParseErrorReason::ExpectedNameValue(None) => {
|
2025-06-29 12:40:30 +02:00
|
|
|
// The suggestion we add below this match already contains enough information
|
2025-03-05 14:35:54 +01:00
|
|
|
}
|
|
|
|
|
AttributeParseErrorReason::ExpectedNameValue(Some(name)) => {
|
2025-03-08 18:58:05 +01:00
|
|
|
diag.span_label(
|
2025-03-05 14:35:54 +01:00
|
|
|
self.span,
|
|
|
|
|
format!("expected this to be of the form `{name} = \"...\"`"),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
AttributeParseErrorReason::ExpectedSpecificArgument { possibilities, strings } => {
|
|
|
|
|
let quote = if strings { '"' } else { '`' };
|
2025-03-04 14:17:06 +01:00
|
|
|
match possibilities.as_slice() {
|
|
|
|
|
&[] => {}
|
|
|
|
|
&[x] => {
|
2025-03-08 18:58:05 +01:00
|
|
|
diag.span_label(
|
2025-03-04 14:17:06 +01:00
|
|
|
self.span,
|
2025-03-05 14:35:54 +01:00
|
|
|
format!("the only valid argument here is {quote}{x}{quote}"),
|
2025-03-04 14:17:06 +01:00
|
|
|
);
|
|
|
|
|
}
|
2025-03-05 14:35:54 +01:00
|
|
|
[first, second] => {
|
2025-03-08 18:58:05 +01:00
|
|
|
diag.span_label(self.span, format!("valid arguments are {quote}{first}{quote} or {quote}{second}{quote}"));
|
2025-03-05 14:35:54 +01:00
|
|
|
}
|
2025-03-04 14:17:06 +01:00
|
|
|
[first @ .., second_to_last, last] => {
|
|
|
|
|
let mut res = String::new();
|
|
|
|
|
for i in first {
|
2025-03-05 14:35:54 +01:00
|
|
|
res.push_str(&format!("{quote}{i}{quote}, "));
|
2025-03-04 14:17:06 +01:00
|
|
|
}
|
2025-03-05 14:35:54 +01:00
|
|
|
res.push_str(&format!(
|
|
|
|
|
"{quote}{second_to_last}{quote} or {quote}{last}{quote}"
|
|
|
|
|
));
|
2025-03-04 14:17:06 +01:00
|
|
|
|
2025-03-08 18:58:05 +01:00
|
|
|
diag.span_label(self.span, format!("valid arguments are {res}"));
|
2025-03-04 14:17:06 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let suggestions = self.template.suggestions(false, &name);
|
|
|
|
|
diag.span_suggestions(
|
|
|
|
|
self.attr_span,
|
|
|
|
|
if suggestions.len() == 1 {
|
|
|
|
|
"must be of the form"
|
|
|
|
|
} else {
|
2025-03-05 14:35:54 +01:00
|
|
|
"try changing it to one of the following valid forms of the attribute"
|
2025-03-04 14:17:06 +01:00
|
|
|
},
|
|
|
|
|
suggestions,
|
|
|
|
|
Applicability::HasPlaceholders,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
diag
|
|
|
|
|
}
|
|
|
|
|
}
|