diff --git a/src/libstd/lib.rs b/src/libstd/lib.rs index 93d3e4ea3df2..8fbb449d88c0 100644 --- a/src/libstd/lib.rs +++ b/src/libstd/lib.rs @@ -220,7 +220,7 @@ #![cfg_attr(test, feature(print_internals, set_stdio, update_panic_count))] #![cfg_attr(all(target_vendor = "fortanix", target_env = "sgx"), - feature(slice_index_methods, decl_macro, coerce_unsized, + feature(slice_index_methods, coerce_unsized, sgx_platform, ptr_wrapping_offset_from))] #![cfg_attr(all(test, target_vendor = "fortanix", target_env = "sgx"), feature(fixed_size_array, maybe_uninit_extra))] @@ -251,6 +251,7 @@ #![feature(container_error_extra)] #![feature(core_intrinsics)] #![feature(custom_test_frameworks)] +#![feature(decl_macro)] #![feature(doc_alias)] #![feature(doc_cfg)] #![feature(doc_keyword)] diff --git a/src/libsyntax/feature_gate/check.rs b/src/libsyntax/feature_gate/check.rs index 282b5ae21936..9882db4e3f30 100644 --- a/src/libsyntax/feature_gate/check.rs +++ b/src/libsyntax/feature_gate/check.rs @@ -420,11 +420,6 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> { "auto traits are experimental and possibly buggy"); } - ast::ItemKind::MacroDef(ast::MacroDef { legacy: false, .. }) => { - let msg = "`macro` is experimental"; - gate_feature_post!(&self, decl_macro, i.span, msg); - } - ast::ItemKind::OpaqueTy(..) => { gate_feature_post!( &self, @@ -831,6 +826,7 @@ pub fn check_crate(krate: &ast::Crate, gate_all!(associated_type_bounds, "associated type bounds are unstable"); gate_all!(crate_visibility_modifier, "`crate` visibility modifier is experimental"); gate_all!(const_generics, "const generics are unstable"); + gate_all!(decl_macro, "`macro` is experimental"); visit::walk_crate(&mut visitor, krate); } diff --git a/src/libsyntax/parse/parser/item.rs b/src/libsyntax/parse/parser/item.rs index c5498236da13..95bddb5afdd0 100644 --- a/src/libsyntax/parse/parser/item.rs +++ b/src/libsyntax/parse/parser/item.rs @@ -1706,6 +1706,11 @@ impl<'a> Parser<'a> { }; let span = lo.to(self.prev_span); + + if !def.legacy { + self.sess.gated_spans.decl_macro.borrow_mut().push(span); + } + Ok(Some(self.mk_item(span, ident, ItemKind::MacroDef(def), vis.clone(), attrs.to_vec()))) } diff --git a/src/libsyntax/sess.rs b/src/libsyntax/sess.rs index 3d2051b4c78e..30aeff752ec4 100644 --- a/src/libsyntax/sess.rs +++ b/src/libsyntax/sess.rs @@ -38,6 +38,8 @@ crate struct GatedSpans { pub crate_visibility_modifier: Lock>, /// Spans collected for gating `const_generics`, e.g. `const N: usize`. pub const_generics: Lock>, + /// Spans collected for gating `decl_macro`, e.g. `macro m() {}`. + pub decl_macro: Lock>, } /// Info about a parsing session. diff --git a/src/test/ui/feature-gates/feature-gate-decl_macro.rs b/src/test/ui/feature-gates/feature-gate-decl_macro.rs index d002c5dbbd2d..b208a047481a 100644 --- a/src/test/ui/feature-gates/feature-gate-decl_macro.rs +++ b/src/test/ui/feature-gates/feature-gate-decl_macro.rs @@ -2,4 +2,8 @@ macro m() {} //~ ERROR `macro` is experimental +macro_rules! accept_item { ($i:item) => {} } +accept_item! { + macro m() {} //~ ERROR `macro` is experimental +} fn main() {} diff --git a/src/test/ui/feature-gates/feature-gate-decl_macro.stderr b/src/test/ui/feature-gates/feature-gate-decl_macro.stderr index 905a1b153104..c6690ebd4d91 100644 --- a/src/test/ui/feature-gates/feature-gate-decl_macro.stderr +++ b/src/test/ui/feature-gates/feature-gate-decl_macro.stderr @@ -7,6 +7,15 @@ LL | macro m() {} = note: for more information, see https://github.com/rust-lang/rust/issues/39412 = help: add `#![feature(decl_macro)]` to the crate attributes to enable -error: aborting due to previous error +error[E0658]: `macro` is experimental + --> $DIR/feature-gate-decl_macro.rs:7:5 + | +LL | macro m() {} + | ^^^^^^^^^^^^ + | + = note: for more information, see https://github.com/rust-lang/rust/issues/39412 + = help: add `#![feature(decl_macro)]` to the crate attributes to enable + +error: aborting due to 2 previous errors For more information about this error, try `rustc --explain E0658`.