Skip to content

Commit 7f3a6fd

Browse files
committed
Replace #[lint/warning/error] with #[diag]
1 parent bd0d3f7 commit 7f3a6fd

File tree

16 files changed

+443
-387
lines changed

16 files changed

+443
-387
lines changed

compiler/rustc_borrowck/src/session_diagnostics.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use rustc_middle::ty::Ty;
33
use rustc_span::Span;
44

55
#[derive(SessionDiagnostic)]
6-
#[error(borrowck::move_unsized, code = "E0161")]
6+
#[diag(borrowck::move_unsized, code = "E0161")]
77
pub(crate) struct MoveUnsized<'tcx> {
88
pub ty: Ty<'tcx>,
99
#[primary_span]
@@ -12,7 +12,7 @@ pub(crate) struct MoveUnsized<'tcx> {
1212
}
1313

1414
#[derive(SessionDiagnostic)]
15-
#[error(borrowck::higher_ranked_lifetime_error)]
15+
#[diag(borrowck::higher_ranked_lifetime_error)]
1616
pub(crate) struct HigherRankedLifetimeError {
1717
#[subdiagnostic]
1818
pub cause: Option<HigherRankedErrorCause>,
@@ -29,14 +29,14 @@ pub(crate) enum HigherRankedErrorCause {
2929
}
3030

3131
#[derive(SessionDiagnostic)]
32-
#[error(borrowck::higher_ranked_subtype_error)]
32+
#[diag(borrowck::higher_ranked_subtype_error)]
3333
pub(crate) struct HigherRankedSubtypeError {
3434
#[primary_span]
3535
pub span: Span,
3636
}
3737

3838
#[derive(SessionDiagnostic)]
39-
#[error(borrowck::generic_does_not_live_long_enough)]
39+
#[diag(borrowck::generic_does_not_live_long_enough)]
4040
pub(crate) struct GenericDoesNotLiveLongEnough {
4141
pub kind: String,
4242
#[primary_span]

compiler/rustc_builtin_macros/src/cfg.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,15 @@ pub fn expand_cfg(
3636
}
3737

3838
#[derive(SessionDiagnostic)]
39-
#[error(builtin_macros::requires_cfg_pattern)]
39+
#[diag(builtin_macros::requires_cfg_pattern)]
4040
struct RequiresCfgPattern {
4141
#[primary_span]
4242
#[label]
4343
span: Span,
4444
}
4545

4646
#[derive(SessionDiagnostic)]
47-
#[error(builtin_macros::expected_one_cfg_pattern)]
47+
#[diag(builtin_macros::expected_one_cfg_pattern)]
4848
struct OneCfgPattern {
4949
#[primary_span]
5050
span: Span,

compiler/rustc_const_eval/src/errors.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use rustc_macros::SessionDiagnostic;
33
use rustc_span::Span;
44

55
#[derive(SessionDiagnostic)]
6-
#[error(const_eval::unstable_in_stable)]
6+
#[diag(const_eval::unstable_in_stable)]
77
pub(crate) struct UnstableInStable {
88
pub gate: String,
99
#[primary_span]
@@ -22,14 +22,14 @@ pub(crate) struct UnstableInStable {
2222
}
2323

2424
#[derive(SessionDiagnostic)]
25-
#[error(const_eval::thread_local_access, code = "E0625")]
25+
#[diag(const_eval::thread_local_access, code = "E0625")]
2626
pub(crate) struct NonConstOpErr {
2727
#[primary_span]
2828
pub span: Span,
2929
}
3030

3131
#[derive(SessionDiagnostic)]
32-
#[error(const_eval::static_access, code = "E0013")]
32+
#[diag(const_eval::static_access, code = "E0013")]
3333
#[help]
3434
pub(crate) struct StaticAccessErr {
3535
#[primary_span]
@@ -41,7 +41,7 @@ pub(crate) struct StaticAccessErr {
4141
}
4242

4343
#[derive(SessionDiagnostic)]
44-
#[error(const_eval::raw_ptr_to_int)]
44+
#[diag(const_eval::raw_ptr_to_int)]
4545
#[note]
4646
#[note(const_eval::note2)]
4747
pub(crate) struct RawPtrToIntErr {
@@ -50,38 +50,38 @@ pub(crate) struct RawPtrToIntErr {
5050
}
5151

5252
#[derive(SessionDiagnostic)]
53-
#[error(const_eval::raw_ptr_comparison)]
53+
#[diag(const_eval::raw_ptr_comparison)]
5454
#[note]
5555
pub(crate) struct RawPtrComparisonErr {
5656
#[primary_span]
5757
pub span: Span,
5858
}
5959

6060
#[derive(SessionDiagnostic)]
61-
#[error(const_eval::panic_non_str)]
61+
#[diag(const_eval::panic_non_str)]
6262
pub(crate) struct PanicNonStrErr {
6363
#[primary_span]
6464
pub span: Span,
6565
}
6666

6767
#[derive(SessionDiagnostic)]
68-
#[error(const_eval::mut_deref, code = "E0658")]
68+
#[diag(const_eval::mut_deref, code = "E0658")]
6969
pub(crate) struct MutDerefErr {
7070
#[primary_span]
7171
pub span: Span,
7272
pub kind: ConstContext,
7373
}
7474

7575
#[derive(SessionDiagnostic)]
76-
#[error(const_eval::transient_mut_borrow, code = "E0658")]
76+
#[diag(const_eval::transient_mut_borrow, code = "E0658")]
7777
pub(crate) struct TransientMutBorrowErr {
7878
#[primary_span]
7979
pub span: Span,
8080
pub kind: ConstContext,
8181
}
8282

8383
#[derive(SessionDiagnostic)]
84-
#[error(const_eval::transient_mut_borrow_raw, code = "E0658")]
84+
#[diag(const_eval::transient_mut_borrow_raw, code = "E0658")]
8585
pub(crate) struct TransientMutBorrowErrRaw {
8686
#[primary_span]
8787
pub span: Span,

compiler/rustc_expand/src/errors.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -3,44 +3,44 @@ use rustc_span::symbol::MacroRulesNormalizedIdent;
33
use rustc_span::Span;
44

55
#[derive(SessionDiagnostic)]
6-
#[error(expand::expr_repeat_no_syntax_vars)]
6+
#[diag(expand::expr_repeat_no_syntax_vars)]
77
pub(crate) struct NoSyntaxVarsExprRepeat {
88
#[primary_span]
99
pub span: Span,
1010
}
1111

1212
#[derive(SessionDiagnostic)]
13-
#[error(expand::must_repeat_once)]
13+
#[diag(expand::must_repeat_once)]
1414
pub(crate) struct MustRepeatOnce {
1515
#[primary_span]
1616
pub span: Span,
1717
}
1818

1919
#[derive(SessionDiagnostic)]
20-
#[error(expand::count_repetition_misplaced)]
20+
#[diag(expand::count_repetition_misplaced)]
2121
pub(crate) struct CountRepetitionMisplaced {
2222
#[primary_span]
2323
pub span: Span,
2424
}
2525

2626
#[derive(SessionDiagnostic)]
27-
#[error(expand::meta_var_expr_unrecognized_var)]
27+
#[diag(expand::meta_var_expr_unrecognized_var)]
2828
pub(crate) struct MetaVarExprUnrecognizedVar {
2929
#[primary_span]
3030
pub span: Span,
3131
pub key: MacroRulesNormalizedIdent,
3232
}
3333

3434
#[derive(SessionDiagnostic)]
35-
#[error(expand::var_still_repeating)]
35+
#[diag(expand::var_still_repeating)]
3636
pub(crate) struct VarStillRepeating {
3737
#[primary_span]
3838
pub span: Span,
3939
pub ident: MacroRulesNormalizedIdent,
4040
}
4141

4242
#[derive(SessionDiagnostic)]
43-
#[error(expand::meta_var_dif_seq_matchers)]
43+
#[diag(expand::meta_var_dif_seq_matchers)]
4444
pub(crate) struct MetaVarsDifSeqMatchers {
4545
#[primary_span]
4646
pub span: Span,

compiler/rustc_interface/src/passes.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ impl LintStoreExpand for LintStoreExpandImpl<'_> {
265265
}
266266

267267
#[derive(SessionDiagnostic)]
268-
#[error(interface::ferris_identifier)]
268+
#[diag(interface::ferris_identifier)]
269269
struct FerrisIdentifier {
270270
#[primary_span]
271271
spans: Vec<Span>,
@@ -274,7 +274,7 @@ struct FerrisIdentifier {
274274
}
275275

276276
#[derive(SessionDiagnostic)]
277-
#[error(interface::emoji_identifier)]
277+
#[diag(interface::emoji_identifier)]
278278
struct EmojiIdentifier {
279279
#[primary_span]
280280
spans: Vec<Span>,

compiler/rustc_lint/src/types.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1546,7 +1546,7 @@ impl InvalidAtomicOrdering {
15461546

15471547
if matches!(fail_ordering, sym::Release | sym::AcqRel) {
15481548
#[derive(LintDiagnostic)]
1549-
#[lint(lint::atomic_ordering_invalid)]
1549+
#[diag(lint::atomic_ordering_invalid)]
15501550
#[help]
15511551
struct InvalidAtomicOrderingDiag {
15521552
method: Symbol,

compiler/rustc_macros/src/diagnostics/diagnostic_builder.rs

+4-15
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ impl DiagnosticDeriveBuilder {
141141
let name = name.as_str();
142142
let meta = attr.parse_meta()?;
143143

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

146146
let nested = match meta {
147147
// Most attributes are lists, like `#[diag(..)]` for most cases or
@@ -163,20 +163,9 @@ impl DiagnosticDeriveBuilder {
163163
// Check the kind before doing any further processing so that there aren't misleading
164164
// "no kind specified" errors if there are failures later.
165165
match name {
166-
"error" | "warning" => {
167-
if self.kind == DiagnosticDeriveKind::LintDiagnostic {
168-
span_err(span, "only `#[lint(..)]` is supported")
169-
.help("use the `#[lint(...)]` attribute to create a lint")
170-
.emit();
171-
}
172-
}
173-
"lint" => {
174-
if self.kind == DiagnosticDeriveKind::SessionDiagnostic {
175-
span_err(span, "only `#[error(..)]` and `#[warning(..)]` are supported")
176-
.help("use the `#[error(...)]` attribute to create a error")
177-
.emit();
178-
}
179-
}
166+
"error" | "warning" | "lint" => throw_invalid_attr!(attr, &meta, |diag| {
167+
diag.help("`error`, `warning` and `lint` have been replaced by `diag`")
168+
}),
180169
"diag" | "help" | "note" | "warn_" => (),
181170
_ => throw_invalid_attr!(attr, &meta, |diag| {
182171
diag.help("only `diag`, `help`, `note` and `warn_` are valid attributes")

compiler/rustc_macros/src/diagnostics/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use synstructure::Structure;
2323
/// # extern crate rust_middle;
2424
/// # use rustc_middle::ty::Ty;
2525
/// #[derive(SessionDiagnostic)]
26-
/// #[error(borrowck::move_out_of_borrow, code = "E0505")]
26+
/// #[diag(borrowck::move_out_of_borrow, code = "E0505")]
2727
/// pub struct MoveOutOfBorrowError<'tcx> {
2828
/// pub name: Ident,
2929
/// pub ty: Ty<'tcx>,
@@ -67,7 +67,7 @@ pub fn session_diagnostic_derive(s: Structure<'_>) -> TokenStream {
6767
///
6868
/// ```ignore (rust)
6969
/// #[derive(LintDiagnostic)]
70-
/// #[lint(lint::atomic_ordering_invalid_fail_success)]
70+
/// #[diag(lint::atomic_ordering_invalid_fail_success)]
7171
/// pub struct AtomicOrderingInvalidLint {
7272
/// method: Symbol,
7373
/// success_ordering: Symbol,

compiler/rustc_macros/src/lib.rs

-6
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,6 @@ decl_derive!([Lift, attributes(lift)] => lift::lift_derive);
129129
decl_derive!(
130130
[SessionDiagnostic, attributes(
131131
// struct attributes
132-
warning,
133-
error,
134-
lint,
135132
diag,
136133
help,
137134
note,
@@ -149,9 +146,6 @@ decl_derive!(
149146
decl_derive!(
150147
[LintDiagnostic, attributes(
151148
// struct attributes
152-
warning,
153-
error,
154-
lint,
155149
diag,
156150
help,
157151
note,

compiler/rustc_parse/src/parser/diagnostics.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ impl MultiSugg {
244244
}
245245

246246
#[derive(SessionDiagnostic)]
247-
#[error(parser::maybe_report_ambiguous_plus)]
247+
#[diag(parser::maybe_report_ambiguous_plus)]
248248
struct AmbiguousPlus {
249249
pub sum_ty: String,
250250
#[primary_span]
@@ -253,7 +253,7 @@ struct AmbiguousPlus {
253253
}
254254

255255
#[derive(SessionDiagnostic)]
256-
#[error(parser::maybe_recover_from_bad_type_plus, code = "E0178")]
256+
#[diag(parser::maybe_recover_from_bad_type_plus, code = "E0178")]
257257
struct BadTypePlus {
258258
pub ty: String,
259259
#[primary_span]
@@ -287,7 +287,7 @@ pub enum BadTypePlusSub {
287287
}
288288

289289
#[derive(SessionDiagnostic)]
290-
#[error(parser::maybe_recover_from_bad_qpath_stage_2)]
290+
#[diag(parser::maybe_recover_from_bad_qpath_stage_2)]
291291
struct BadQPathStage2 {
292292
#[primary_span]
293293
#[suggestion(applicability = "maybe-incorrect")]
@@ -296,7 +296,7 @@ struct BadQPathStage2 {
296296
}
297297

298298
#[derive(SessionDiagnostic)]
299-
#[error(parser::incorrect_semicolon)]
299+
#[diag(parser::incorrect_semicolon)]
300300
struct IncorrectSemicolon<'a> {
301301
#[primary_span]
302302
#[suggestion_short(applicability = "machine-applicable")]
@@ -307,15 +307,15 @@ struct IncorrectSemicolon<'a> {
307307
}
308308

309309
#[derive(SessionDiagnostic)]
310-
#[error(parser::incorrect_use_of_await)]
310+
#[diag(parser::incorrect_use_of_await)]
311311
struct IncorrectUseOfAwait {
312312
#[primary_span]
313313
#[suggestion(parser::parentheses_suggestion, applicability = "machine-applicable")]
314314
span: Span,
315315
}
316316

317317
#[derive(SessionDiagnostic)]
318-
#[error(parser::incorrect_use_of_await)]
318+
#[diag(parser::incorrect_use_of_await)]
319319
struct IncorrectAwait {
320320
#[primary_span]
321321
span: Span,
@@ -326,7 +326,7 @@ struct IncorrectAwait {
326326
}
327327

328328
#[derive(SessionDiagnostic)]
329-
#[error(parser::in_in_typo)]
329+
#[diag(parser::in_in_typo)]
330330
struct InInTypo {
331331
#[primary_span]
332332
span: Span,
@@ -335,7 +335,7 @@ struct InInTypo {
335335
}
336336

337337
#[derive(SessionDiagnostic)]
338-
#[error(parser::invalid_variable_declaration)]
338+
#[diag(parser::invalid_variable_declaration)]
339339
pub struct InvalidVariableDeclaration {
340340
#[primary_span]
341341
pub span: Span,

0 commit comments

Comments
 (0)