Skip to content

Commit 1f470ce

Browse files
committed
pre-expansion gate decl_macro
1 parent 49cbfa1 commit 1f470ce

File tree

6 files changed

+24
-7
lines changed

6 files changed

+24
-7
lines changed

src/libstd/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@
220220

221221
#![cfg_attr(test, feature(print_internals, set_stdio, update_panic_count))]
222222
#![cfg_attr(all(target_vendor = "fortanix", target_env = "sgx"),
223-
feature(slice_index_methods, decl_macro, coerce_unsized,
223+
feature(slice_index_methods, coerce_unsized,
224224
sgx_platform, ptr_wrapping_offset_from))]
225225
#![cfg_attr(all(test, target_vendor = "fortanix", target_env = "sgx"),
226226
feature(fixed_size_array, maybe_uninit_extra))]
@@ -251,6 +251,7 @@
251251
#![feature(container_error_extra)]
252252
#![feature(core_intrinsics)]
253253
#![feature(custom_test_frameworks)]
254+
#![feature(decl_macro)]
254255
#![feature(doc_alias)]
255256
#![feature(doc_cfg)]
256257
#![feature(doc_keyword)]

src/libsyntax/feature_gate/check.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -420,11 +420,6 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
420420
"auto traits are experimental and possibly buggy");
421421
}
422422

423-
ast::ItemKind::MacroDef(ast::MacroDef { legacy: false, .. }) => {
424-
let msg = "`macro` is experimental";
425-
gate_feature_post!(&self, decl_macro, i.span, msg);
426-
}
427-
428423
ast::ItemKind::OpaqueTy(..) => {
429424
gate_feature_post!(
430425
&self,
@@ -831,6 +826,7 @@ pub fn check_crate(krate: &ast::Crate,
831826
gate_all!(associated_type_bounds, "associated type bounds are unstable");
832827
gate_all!(crate_visibility_modifier, "`crate` visibility modifier is experimental");
833828
gate_all!(const_generics, "const generics are unstable");
829+
gate_all!(decl_macro, "`macro` is experimental");
834830

835831
visit::walk_crate(&mut visitor, krate);
836832
}

src/libsyntax/parse/parser/item.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1706,6 +1706,11 @@ impl<'a> Parser<'a> {
17061706
};
17071707

17081708
let span = lo.to(self.prev_span);
1709+
1710+
if !def.legacy {
1711+
self.sess.gated_spans.decl_macro.borrow_mut().push(span);
1712+
}
1713+
17091714
Ok(Some(self.mk_item(span, ident, ItemKind::MacroDef(def), vis.clone(), attrs.to_vec())))
17101715
}
17111716

src/libsyntax/sess.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ crate struct GatedSpans {
3838
pub crate_visibility_modifier: Lock<Vec<Span>>,
3939
/// Spans collected for gating `const_generics`, e.g. `const N: usize`.
4040
pub const_generics: Lock<Vec<Span>>,
41+
/// Spans collected for gating `decl_macro`, e.g. `macro m() {}`.
42+
pub decl_macro: Lock<Vec<Span>>,
4143
}
4244

4345
/// Info about a parsing session.

src/test/ui/feature-gates/feature-gate-decl_macro.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,8 @@
22

33
macro m() {} //~ ERROR `macro` is experimental
44

5+
macro_rules! accept_item { ($i:item) => {} }
6+
accept_item! {
7+
macro m() {} //~ ERROR `macro` is experimental
8+
}
59
fn main() {}

src/test/ui/feature-gates/feature-gate-decl_macro.stderr

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,15 @@ LL | macro m() {}
77
= note: for more information, see https://github.com/rust-lang/rust/issues/39412
88
= help: add `#![feature(decl_macro)]` to the crate attributes to enable
99

10-
error: aborting due to previous error
10+
error[E0658]: `macro` is experimental
11+
--> $DIR/feature-gate-decl_macro.rs:7:5
12+
|
13+
LL | macro m() {}
14+
| ^^^^^^^^^^^^
15+
|
16+
= note: for more information, see https://github.com/rust-lang/rust/issues/39412
17+
= help: add `#![feature(decl_macro)]` to the crate attributes to enable
18+
19+
error: aborting due to 2 previous errors
1120

1221
For more information about this error, try `rustc --explain E0658`.

0 commit comments

Comments
 (0)