pre-expansion gate decl_macro

This commit is contained in:
Mazdak Farrokhzad 2019-09-21 19:18:41 +02:00
parent 49cbfa1a6f
commit 1f470ceac2
6 changed files with 24 additions and 7 deletions

View file

@ -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)]

View file

@ -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);
}

View file

@ -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())))
}

View file

@ -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.

View file

@ -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() {}

View file

@ -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`.