Skip to content

Commit 475b9d9

Browse files
committed
Prevent const stability attrs from being applied to macros via the normal attribute logic instead of special cased checks
1 parent 628c37a commit 475b9d9

5 files changed

Lines changed: 12 additions & 34 deletions

File tree

compiler/rustc_attr_parsing/src/attributes/stability.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,6 @@ impl<S: Stage> AttributeParser<S> for ConstStabilityParser {
257257
Allow(Target::Trait),
258258
Allow(Target::Static),
259259
Allow(Target::Crate),
260-
Allow(Target::MacroDef), // FIXME(oli-obk): remove this and eliminate the manual check for it
261260
]);
262261

263262
fn finalize(mut self, cx: &FinalizeContext<'_, '_, S>) -> Option<AttributeKind> {

compiler/rustc_expand/src/base.rs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -962,15 +962,6 @@ impl SyntaxExtension {
962962

963963
let stability = find_attr!(attrs, AttributeKind::Stability { stability, .. } => *stability);
964964

965-
// FIXME(jdonszelmann): make it impossible to miss the or_else in the typesystem
966-
if let Some(sp) =
967-
find_attr!(attrs, AttributeKind::RustcConstStability { span, .. } => *span)
968-
{
969-
sess.dcx().emit_err(errors::MacroConstStability {
970-
span: sp,
971-
head_span: sess.source_map().guess_head_span(span),
972-
});
973-
}
974965
if let Some(sp) = find_attr!(attrs, AttributeKind::RustcBodyStability{ span, .. } => *span)
975966
{
976967
sess.dcx().emit_err(errors::MacroBodyStability {

compiler/rustc_expand/src/errors.rs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -80,16 +80,6 @@ pub(crate) struct ResolveRelativePath {
8080
pub path: String,
8181
}
8282

83-
#[derive(Diagnostic)]
84-
#[diag("macros cannot have const stability attributes")]
85-
pub(crate) struct MacroConstStability {
86-
#[primary_span]
87-
#[label("invalid const stability attribute")]
88-
pub span: Span,
89-
#[label("const stability attribute affects this macro")]
90-
pub head_span: Span,
91-
}
92-
9383
#[derive(Diagnostic)]
9484
#[diag("macros cannot have body stability attributes")]
9585
pub(crate) struct MacroBodyStability {

tests/ui/attributes/const-stability-on-macro.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
#![stable(feature = "rust1", since = "1.0.0")]
33

44
#[rustc_const_stable(feature = "foo", since = "3.3.3")]
5-
//~^ ERROR macros cannot have const stability attributes
5+
//~^ ERROR attribute cannot be used on macro defs
66
macro_rules! foo {
77
() => {};
88
}
99

10-
#[rustc_const_unstable(feature = "bar", issue="none")]
11-
//~^ ERROR macros cannot have const stability attributes
10+
#[rustc_const_unstable(feature = "bar", issue = "none")]
11+
//~^ ERROR attribute cannot be used on macro defs
1212
macro_rules! bar {
1313
() => {};
1414
}
Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,18 @@
1-
error: macros cannot have const stability attributes
1+
error: `#[rustc_const_stable]` attribute cannot be used on macro defs
22
--> $DIR/const-stability-on-macro.rs:4:1
33
|
44
LL | #[rustc_const_stable(feature = "foo", since = "3.3.3")]
5-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ invalid const stability attribute
6-
LL |
7-
LL | macro_rules! foo {
8-
| ---------------- const stability attribute affects this macro
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6+
|
7+
= help: `#[rustc_const_stable]` can be applied to associated consts, constants, crates, functions, impl blocks, statics, traits, and use statements
98

10-
error: macros cannot have const stability attributes
9+
error: `#[rustc_const_unstable]` attribute cannot be used on macro defs
1110
--> $DIR/const-stability-on-macro.rs:10:1
1211
|
13-
LL | #[rustc_const_unstable(feature = "bar", issue="none")]
14-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ invalid const stability attribute
15-
LL |
16-
LL | macro_rules! bar {
17-
| ---------------- const stability attribute affects this macro
12+
LL | #[rustc_const_unstable(feature = "bar", issue = "none")]
13+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
14+
|
15+
= help: `#[rustc_const_unstable]` can be applied to associated consts, constants, crates, functions, impl blocks, statics, traits, and use statements
1816

1917
error: aborting due to 2 previous errors
2018

0 commit comments

Comments
 (0)