Avoid including attributes in bang macro invocations.

This commit is contained in:
Jeffrey Seyfried 2016-12-01 11:54:01 +00:00
parent 421c5d11c1
commit 6f040b48ef
2 changed files with 19 additions and 25 deletions

View File

@ -217,8 +217,7 @@ pub trait IdentMacroExpander {
cx: &'cx mut ExtCtxt,
sp: Span,
ident: ast::Ident,
token_tree: Vec<tokenstream::TokenTree>,
attrs: Vec<ast::Attribute>)
token_tree: Vec<tokenstream::TokenTree>)
-> Box<MacResult+'cx>;
}
@ -234,8 +233,7 @@ impl<F> IdentMacroExpander for F
cx: &'cx mut ExtCtxt,
sp: Span,
ident: ast::Ident,
token_tree: Vec<tokenstream::TokenTree>,
_attrs: Vec<ast::Attribute>)
token_tree: Vec<tokenstream::TokenTree>)
-> Box<MacResult+'cx>
{
(*self)(cx, sp, ident, token_tree)

View File

@ -158,7 +158,6 @@ pub struct Invocation {
pub enum InvocationKind {
Bang {
attrs: Vec<ast::Attribute>,
mac: ast::Mac,
ident: Option<Ident>,
span: Span,
@ -386,8 +385,8 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
/// Expand a macro invocation. Returns the result of expansion.
fn expand_bang_invoc(&mut self, invoc: Invocation, ext: Rc<SyntaxExtension>) -> Expansion {
let (mark, kind) = (invoc.expansion_data.mark, invoc.expansion_kind);
let (attrs, mac, ident, span) = match invoc.kind {
InvocationKind::Bang { attrs, mac, ident, span } => (attrs, mac, ident, span),
let (mac, ident, span) = match invoc.kind {
InvocationKind::Bang { mac, ident, span } => (mac, ident, span),
_ => unreachable!(),
};
let Mac_ { path, tts, .. } = mac.node;
@ -432,7 +431,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
}
});
kind.make_from(expander.expand(self.cx, span, ident, marked_tts, attrs))
kind.make_from(expander.expand(self.cx, span, ident, marked_tts))
}
MultiDecorator(..) | MultiModifier(..) | SyntaxExtension::AttrProcMacro(..) => {
@ -590,11 +589,8 @@ impl<'a, 'b> InvocationCollector<'a, 'b> {
placeholder(expansion_kind, ast::NodeId::from_u32(mark.as_u32()))
}
fn collect_bang(
&mut self, mac: ast::Mac, attrs: Vec<ast::Attribute>, span: Span, kind: ExpansionKind,
) -> Expansion {
self.check_attributes(&attrs);
self.collect(kind, InvocationKind::Bang { attrs: attrs, mac: mac, ident: None, span: span })
fn collect_bang(&mut self, mac: ast::Mac, span: Span, kind: ExpansionKind) -> Expansion {
self.collect(kind, InvocationKind::Bang { mac: mac, ident: None, span: span })
}
fn collect_attr(&mut self, attr: ast::Attribute, item: Annotatable, kind: ExpansionKind)
@ -663,7 +659,8 @@ impl<'a, 'b> Folder for InvocationCollector<'a, 'b> {
expr.node = self.cfg.configure_expr_kind(expr.node);
if let ast::ExprKind::Mac(mac) = expr.node {
self.collect_bang(mac, expr.attrs.into(), expr.span, ExpansionKind::Expr).make_expr()
self.check_attributes(&expr.attrs);
self.collect_bang(mac, expr.span, ExpansionKind::Expr).make_expr()
} else {
P(noop_fold_expr(expr, self))
}
@ -674,8 +671,8 @@ impl<'a, 'b> Folder for InvocationCollector<'a, 'b> {
expr.node = self.cfg.configure_expr_kind(expr.node);
if let ast::ExprKind::Mac(mac) = expr.node {
self.collect_bang(mac, expr.attrs.into(), expr.span, ExpansionKind::OptExpr)
.make_opt_expr()
self.check_attributes(&expr.attrs);
self.collect_bang(mac, expr.span, ExpansionKind::OptExpr).make_opt_expr()
} else {
Some(P(noop_fold_expr(expr, self)))
}
@ -688,8 +685,7 @@ impl<'a, 'b> Folder for InvocationCollector<'a, 'b> {
}
pat.and_then(|pat| match pat.node {
PatKind::Mac(mac) =>
self.collect_bang(mac, Vec::new(), pat.span, ExpansionKind::Pat).make_pat(),
PatKind::Mac(mac) => self.collect_bang(mac, pat.span, ExpansionKind::Pat).make_pat(),
_ => unreachable!(),
})
}
@ -710,8 +706,8 @@ impl<'a, 'b> Folder for InvocationCollector<'a, 'b> {
}).collect()
};
let mut placeholder =
self.collect_bang(mac, attrs.into(), stmt.span, ExpansionKind::Stmts).make_stmts();
self.check_attributes(&attrs);
let mut placeholder = self.collect_bang(mac, stmt.span, ExpansionKind::Stmts).make_stmts();
// If this is a macro invocation with a semicolon, then apply that
// semicolon to the final statement produced by expansion.
@ -758,7 +754,6 @@ impl<'a, 'b> Folder for InvocationCollector<'a, 'b> {
ItemKind::Mac(mac) => {
self.collect(ExpansionKind::Items, InvocationKind::Bang {
mac: mac,
attrs: item.attrs,
ident: Some(item.ident),
span: item.span,
}).make_items()
@ -830,7 +825,8 @@ impl<'a, 'b> Folder for InvocationCollector<'a, 'b> {
match item.node {
ast::TraitItemKind::Macro(mac) => {
let ast::TraitItem { attrs, span, .. } = item;
self.collect_bang(mac, attrs, span, ExpansionKind::TraitItems).make_trait_items()
self.check_attributes(&attrs);
self.collect_bang(mac, span, ExpansionKind::TraitItems).make_trait_items()
}
_ => fold::noop_fold_trait_item(item, self),
}
@ -848,7 +844,8 @@ impl<'a, 'b> Folder for InvocationCollector<'a, 'b> {
match item.node {
ast::ImplItemKind::Macro(mac) => {
let ast::ImplItem { attrs, span, .. } = item;
self.collect_bang(mac, attrs, span, ExpansionKind::ImplItems).make_impl_items()
self.check_attributes(&attrs);
self.collect_bang(mac, span, ExpansionKind::ImplItems).make_impl_items()
}
_ => fold::noop_fold_impl_item(item, self),
}
@ -861,8 +858,7 @@ impl<'a, 'b> Folder for InvocationCollector<'a, 'b> {
};
match ty.node {
ast::TyKind::Mac(mac) =>
self.collect_bang(mac, Vec::new(), ty.span, ExpansionKind::Ty).make_ty(),
ast::TyKind::Mac(mac) => self.collect_bang(mac, ty.span, ExpansionKind::Ty).make_ty(),
_ => unreachable!(),
}
}