Skip to content

Commit

Permalink
pre-expansion gate decl_macro
Browse files Browse the repository at this point in the history
  • Loading branch information
Centril committed Oct 23, 2019
1 parent 49cbfa1 commit 1f470ce
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 7 deletions.
3 changes: 2 additions & 1 deletion src/libstd/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))]
Expand Down Expand Up @@ -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)]
Expand Down
6 changes: 1 addition & 5 deletions src/libsyntax/feature_gate/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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);
}
Expand Down
5 changes: 5 additions & 0 deletions src/libsyntax/parse/parser/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())))
}

Expand Down
2 changes: 2 additions & 0 deletions src/libsyntax/sess.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 4 additions & 0 deletions src/test/ui/feature-gates/feature-gate-decl_macro.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {}
11 changes: 10 additions & 1 deletion src/test/ui/feature-gates/feature-gate-decl_macro.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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`.

0 comments on commit 1f470ce

Please sign in to comment.