about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMazdak Farrokhzad <twingoow@gmail.com>2019-09-21 19:18:41 +0200
committerMazdak Farrokhzad <twingoow@gmail.com>2019-10-24 00:32:03 +0200
commit1f470ceac2202ecffe8a15acc1139edb9ad4a03b (patch)
treea10d1f399cfab5d1274f84e5a4585dba3955ade2
parent49cbfa1a6f6469ddbc0e88161e52104cc87aea9b (diff)
downloadrust-1f470ceac2202ecffe8a15acc1139edb9ad4a03b.tar.gz
rust-1f470ceac2202ecffe8a15acc1139edb9ad4a03b.zip
pre-expansion gate decl_macro
-rw-r--r--src/libstd/lib.rs3
-rw-r--r--src/libsyntax/feature_gate/check.rs6
-rw-r--r--src/libsyntax/parse/parser/item.rs5
-rw-r--r--src/libsyntax/sess.rs2
-rw-r--r--src/test/ui/feature-gates/feature-gate-decl_macro.rs4
-rw-r--r--src/test/ui/feature-gates/feature-gate-decl_macro.stderr11
6 files changed, 24 insertions, 7 deletions
diff --git a/src/libstd/lib.rs b/src/libstd/lib.rs
index 93d3e4ea3df..8fbb449d88c 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 282b5ae2193..9882db4e3f3 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 c5498236da1..95bddb5afdd 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 3d2051b4c78..30aeff752ec 100644
--- a/src/libsyntax/sess.rs
+++ b/src/libsyntax/sess.rs
@@ -38,6 +38,8 @@ crate struct GatedSpans {
     pub crate_visibility_modifier: Lock<Vec<Span>>,
     /// Spans collected for gating `const_generics`, e.g. `const N: usize`.
     pub const_generics: Lock<Vec<Span>>,
+    /// Spans collected for gating `decl_macro`, e.g. `macro m() {}`.
+    pub decl_macro: Lock<Vec<Span>>,
 }
 
 /// 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 d002c5dbbd2..b208a047481 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 905a1b15310..c6690ebd4d9 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`.