Skip to content

Commit

Permalink
Replace #[lint/warning/error] with #[diag]
Browse files Browse the repository at this point in the history
  • Loading branch information
Xiretza committed Aug 21, 2022
1 parent bd0d3f7 commit 7f3a6fd
Show file tree
Hide file tree
Showing 16 changed files with 443 additions and 387 deletions.
8 changes: 4 additions & 4 deletions compiler/rustc_borrowck/src/session_diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use rustc_middle::ty::Ty;
use rustc_span::Span;

#[derive(SessionDiagnostic)]
#[error(borrowck::move_unsized, code = "E0161")]
#[diag(borrowck::move_unsized, code = "E0161")]
pub(crate) struct MoveUnsized<'tcx> {
pub ty: Ty<'tcx>,
#[primary_span]
Expand All @@ -12,7 +12,7 @@ pub(crate) struct MoveUnsized<'tcx> {
}

#[derive(SessionDiagnostic)]
#[error(borrowck::higher_ranked_lifetime_error)]
#[diag(borrowck::higher_ranked_lifetime_error)]
pub(crate) struct HigherRankedLifetimeError {
#[subdiagnostic]
pub cause: Option<HigherRankedErrorCause>,
Expand All @@ -29,14 +29,14 @@ pub(crate) enum HigherRankedErrorCause {
}

#[derive(SessionDiagnostic)]
#[error(borrowck::higher_ranked_subtype_error)]
#[diag(borrowck::higher_ranked_subtype_error)]
pub(crate) struct HigherRankedSubtypeError {
#[primary_span]
pub span: Span,
}

#[derive(SessionDiagnostic)]
#[error(borrowck::generic_does_not_live_long_enough)]
#[diag(borrowck::generic_does_not_live_long_enough)]
pub(crate) struct GenericDoesNotLiveLongEnough {
pub kind: String,
#[primary_span]
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_builtin_macros/src/cfg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,15 @@ pub fn expand_cfg(
}

#[derive(SessionDiagnostic)]
#[error(builtin_macros::requires_cfg_pattern)]
#[diag(builtin_macros::requires_cfg_pattern)]
struct RequiresCfgPattern {
#[primary_span]
#[label]
span: Span,
}

#[derive(SessionDiagnostic)]
#[error(builtin_macros::expected_one_cfg_pattern)]
#[diag(builtin_macros::expected_one_cfg_pattern)]
struct OneCfgPattern {
#[primary_span]
span: Span,
Expand Down
18 changes: 9 additions & 9 deletions compiler/rustc_const_eval/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use rustc_macros::SessionDiagnostic;
use rustc_span::Span;

#[derive(SessionDiagnostic)]
#[error(const_eval::unstable_in_stable)]
#[diag(const_eval::unstable_in_stable)]
pub(crate) struct UnstableInStable {
pub gate: String,
#[primary_span]
Expand All @@ -22,14 +22,14 @@ pub(crate) struct UnstableInStable {
}

#[derive(SessionDiagnostic)]
#[error(const_eval::thread_local_access, code = "E0625")]
#[diag(const_eval::thread_local_access, code = "E0625")]
pub(crate) struct NonConstOpErr {
#[primary_span]
pub span: Span,
}

#[derive(SessionDiagnostic)]
#[error(const_eval::static_access, code = "E0013")]
#[diag(const_eval::static_access, code = "E0013")]
#[help]
pub(crate) struct StaticAccessErr {
#[primary_span]
Expand All @@ -41,7 +41,7 @@ pub(crate) struct StaticAccessErr {
}

#[derive(SessionDiagnostic)]
#[error(const_eval::raw_ptr_to_int)]
#[diag(const_eval::raw_ptr_to_int)]
#[note]
#[note(const_eval::note2)]
pub(crate) struct RawPtrToIntErr {
Expand All @@ -50,38 +50,38 @@ pub(crate) struct RawPtrToIntErr {
}

#[derive(SessionDiagnostic)]
#[error(const_eval::raw_ptr_comparison)]
#[diag(const_eval::raw_ptr_comparison)]
#[note]
pub(crate) struct RawPtrComparisonErr {
#[primary_span]
pub span: Span,
}

#[derive(SessionDiagnostic)]
#[error(const_eval::panic_non_str)]
#[diag(const_eval::panic_non_str)]
pub(crate) struct PanicNonStrErr {
#[primary_span]
pub span: Span,
}

#[derive(SessionDiagnostic)]
#[error(const_eval::mut_deref, code = "E0658")]
#[diag(const_eval::mut_deref, code = "E0658")]
pub(crate) struct MutDerefErr {
#[primary_span]
pub span: Span,
pub kind: ConstContext,
}

#[derive(SessionDiagnostic)]
#[error(const_eval::transient_mut_borrow, code = "E0658")]
#[diag(const_eval::transient_mut_borrow, code = "E0658")]
pub(crate) struct TransientMutBorrowErr {
#[primary_span]
pub span: Span,
pub kind: ConstContext,
}

#[derive(SessionDiagnostic)]
#[error(const_eval::transient_mut_borrow_raw, code = "E0658")]
#[diag(const_eval::transient_mut_borrow_raw, code = "E0658")]
pub(crate) struct TransientMutBorrowErrRaw {
#[primary_span]
pub span: Span,
Expand Down
12 changes: 6 additions & 6 deletions compiler/rustc_expand/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,44 +3,44 @@ use rustc_span::symbol::MacroRulesNormalizedIdent;
use rustc_span::Span;

#[derive(SessionDiagnostic)]
#[error(expand::expr_repeat_no_syntax_vars)]
#[diag(expand::expr_repeat_no_syntax_vars)]
pub(crate) struct NoSyntaxVarsExprRepeat {
#[primary_span]
pub span: Span,
}

#[derive(SessionDiagnostic)]
#[error(expand::must_repeat_once)]
#[diag(expand::must_repeat_once)]
pub(crate) struct MustRepeatOnce {
#[primary_span]
pub span: Span,
}

#[derive(SessionDiagnostic)]
#[error(expand::count_repetition_misplaced)]
#[diag(expand::count_repetition_misplaced)]
pub(crate) struct CountRepetitionMisplaced {
#[primary_span]
pub span: Span,
}

#[derive(SessionDiagnostic)]
#[error(expand::meta_var_expr_unrecognized_var)]
#[diag(expand::meta_var_expr_unrecognized_var)]
pub(crate) struct MetaVarExprUnrecognizedVar {
#[primary_span]
pub span: Span,
pub key: MacroRulesNormalizedIdent,
}

#[derive(SessionDiagnostic)]
#[error(expand::var_still_repeating)]
#[diag(expand::var_still_repeating)]
pub(crate) struct VarStillRepeating {
#[primary_span]
pub span: Span,
pub ident: MacroRulesNormalizedIdent,
}

#[derive(SessionDiagnostic)]
#[error(expand::meta_var_dif_seq_matchers)]
#[diag(expand::meta_var_dif_seq_matchers)]
pub(crate) struct MetaVarsDifSeqMatchers {
#[primary_span]
pub span: Span,
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_interface/src/passes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ impl LintStoreExpand for LintStoreExpandImpl<'_> {
}

#[derive(SessionDiagnostic)]
#[error(interface::ferris_identifier)]
#[diag(interface::ferris_identifier)]
struct FerrisIdentifier {
#[primary_span]
spans: Vec<Span>,
Expand All @@ -274,7 +274,7 @@ struct FerrisIdentifier {
}

#[derive(SessionDiagnostic)]
#[error(interface::emoji_identifier)]
#[diag(interface::emoji_identifier)]
struct EmojiIdentifier {
#[primary_span]
spans: Vec<Span>,
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_lint/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1546,7 +1546,7 @@ impl InvalidAtomicOrdering {

if matches!(fail_ordering, sym::Release | sym::AcqRel) {
#[derive(LintDiagnostic)]
#[lint(lint::atomic_ordering_invalid)]
#[diag(lint::atomic_ordering_invalid)]
#[help]
struct InvalidAtomicOrderingDiag {
method: Symbol,
Expand Down
19 changes: 4 additions & 15 deletions compiler/rustc_macros/src/diagnostics/diagnostic_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ impl DiagnosticDeriveBuilder {
let name = name.as_str();
let meta = attr.parse_meta()?;

let is_diag = matches!(name, "error" | "warning" | "lint" | "diag");
let is_diag = name == "diag";

let nested = match meta {
// Most attributes are lists, like `#[diag(..)]` for most cases or
Expand All @@ -163,20 +163,9 @@ impl DiagnosticDeriveBuilder {
// Check the kind before doing any further processing so that there aren't misleading
// "no kind specified" errors if there are failures later.
match name {
"error" | "warning" => {
if self.kind == DiagnosticDeriveKind::LintDiagnostic {
span_err(span, "only `#[lint(..)]` is supported")
.help("use the `#[lint(...)]` attribute to create a lint")
.emit();
}
}
"lint" => {
if self.kind == DiagnosticDeriveKind::SessionDiagnostic {
span_err(span, "only `#[error(..)]` and `#[warning(..)]` are supported")
.help("use the `#[error(...)]` attribute to create a error")
.emit();
}
}
"error" | "warning" | "lint" => throw_invalid_attr!(attr, &meta, |diag| {
diag.help("`error`, `warning` and `lint` have been replaced by `diag`")
}),
"diag" | "help" | "note" | "warn_" => (),
_ => throw_invalid_attr!(attr, &meta, |diag| {
diag.help("only `diag`, `help`, `note` and `warn_` are valid attributes")
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_macros/src/diagnostics/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use synstructure::Structure;
/// # extern crate rust_middle;
/// # use rustc_middle::ty::Ty;
/// #[derive(SessionDiagnostic)]
/// #[error(borrowck::move_out_of_borrow, code = "E0505")]
/// #[diag(borrowck::move_out_of_borrow, code = "E0505")]
/// pub struct MoveOutOfBorrowError<'tcx> {
/// pub name: Ident,
/// pub ty: Ty<'tcx>,
Expand Down Expand Up @@ -67,7 +67,7 @@ pub fn session_diagnostic_derive(s: Structure<'_>) -> TokenStream {
///
/// ```ignore (rust)
/// #[derive(LintDiagnostic)]
/// #[lint(lint::atomic_ordering_invalid_fail_success)]
/// #[diag(lint::atomic_ordering_invalid_fail_success)]
/// pub struct AtomicOrderingInvalidLint {
/// method: Symbol,
/// success_ordering: Symbol,
Expand Down
6 changes: 0 additions & 6 deletions compiler/rustc_macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,6 @@ decl_derive!([Lift, attributes(lift)] => lift::lift_derive);
decl_derive!(
[SessionDiagnostic, attributes(
// struct attributes
warning,
error,
lint,
diag,
help,
note,
Expand All @@ -149,9 +146,6 @@ decl_derive!(
decl_derive!(
[LintDiagnostic, attributes(
// struct attributes
warning,
error,
lint,
diag,
help,
note,
Expand Down
16 changes: 8 additions & 8 deletions compiler/rustc_parse/src/parser/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ impl MultiSugg {
}

#[derive(SessionDiagnostic)]
#[error(parser::maybe_report_ambiguous_plus)]
#[diag(parser::maybe_report_ambiguous_plus)]
struct AmbiguousPlus {
pub sum_ty: String,
#[primary_span]
Expand All @@ -253,7 +253,7 @@ struct AmbiguousPlus {
}

#[derive(SessionDiagnostic)]
#[error(parser::maybe_recover_from_bad_type_plus, code = "E0178")]
#[diag(parser::maybe_recover_from_bad_type_plus, code = "E0178")]
struct BadTypePlus {
pub ty: String,
#[primary_span]
Expand Down Expand Up @@ -287,7 +287,7 @@ pub enum BadTypePlusSub {
}

#[derive(SessionDiagnostic)]
#[error(parser::maybe_recover_from_bad_qpath_stage_2)]
#[diag(parser::maybe_recover_from_bad_qpath_stage_2)]
struct BadQPathStage2 {
#[primary_span]
#[suggestion(applicability = "maybe-incorrect")]
Expand All @@ -296,7 +296,7 @@ struct BadQPathStage2 {
}

#[derive(SessionDiagnostic)]
#[error(parser::incorrect_semicolon)]
#[diag(parser::incorrect_semicolon)]
struct IncorrectSemicolon<'a> {
#[primary_span]
#[suggestion_short(applicability = "machine-applicable")]
Expand All @@ -307,15 +307,15 @@ struct IncorrectSemicolon<'a> {
}

#[derive(SessionDiagnostic)]
#[error(parser::incorrect_use_of_await)]
#[diag(parser::incorrect_use_of_await)]
struct IncorrectUseOfAwait {
#[primary_span]
#[suggestion(parser::parentheses_suggestion, applicability = "machine-applicable")]
span: Span,
}

#[derive(SessionDiagnostic)]
#[error(parser::incorrect_use_of_await)]
#[diag(parser::incorrect_use_of_await)]
struct IncorrectAwait {
#[primary_span]
span: Span,
Expand All @@ -326,7 +326,7 @@ struct IncorrectAwait {
}

#[derive(SessionDiagnostic)]
#[error(parser::in_in_typo)]
#[diag(parser::in_in_typo)]
struct InInTypo {
#[primary_span]
span: Span,
Expand All @@ -335,7 +335,7 @@ struct InInTypo {
}

#[derive(SessionDiagnostic)]
#[error(parser::invalid_variable_declaration)]
#[diag(parser::invalid_variable_declaration)]
pub struct InvalidVariableDeclaration {
#[primary_span]
pub span: Span,
Expand Down
Loading

0 comments on commit 7f3a6fd

Please sign in to comment.