Skip to content

Commit 6f040b4

Browse files
committed
Avoid including attributes in bang macro invocations.
1 parent 421c5d1 commit 6f040b4

File tree

2 files changed

+19
-25
lines changed

2 files changed

+19
-25
lines changed

src/libsyntax/ext/base.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -217,8 +217,7 @@ pub trait IdentMacroExpander {
217217
cx: &'cx mut ExtCtxt,
218218
sp: Span,
219219
ident: ast::Ident,
220-
token_tree: Vec<tokenstream::TokenTree>,
221-
attrs: Vec<ast::Attribute>)
220+
token_tree: Vec<tokenstream::TokenTree>)
222221
-> Box<MacResult+'cx>;
223222
}
224223

@@ -234,8 +233,7 @@ impl<F> IdentMacroExpander for F
234233
cx: &'cx mut ExtCtxt,
235234
sp: Span,
236235
ident: ast::Ident,
237-
token_tree: Vec<tokenstream::TokenTree>,
238-
_attrs: Vec<ast::Attribute>)
236+
token_tree: Vec<tokenstream::TokenTree>)
239237
-> Box<MacResult+'cx>
240238
{
241239
(*self)(cx, sp, ident, token_tree)

src/libsyntax/ext/expand.rs

+17-21
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,6 @@ pub struct Invocation {
158158

159159
pub enum InvocationKind {
160160
Bang {
161-
attrs: Vec<ast::Attribute>,
162161
mac: ast::Mac,
163162
ident: Option<Ident>,
164163
span: Span,
@@ -386,8 +385,8 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
386385
/// Expand a macro invocation. Returns the result of expansion.
387386
fn expand_bang_invoc(&mut self, invoc: Invocation, ext: Rc<SyntaxExtension>) -> Expansion {
388387
let (mark, kind) = (invoc.expansion_data.mark, invoc.expansion_kind);
389-
let (attrs, mac, ident, span) = match invoc.kind {
390-
InvocationKind::Bang { attrs, mac, ident, span } => (attrs, mac, ident, span),
388+
let (mac, ident, span) = match invoc.kind {
389+
InvocationKind::Bang { mac, ident, span } => (mac, ident, span),
391390
_ => unreachable!(),
392391
};
393392
let Mac_ { path, tts, .. } = mac.node;
@@ -432,7 +431,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
432431
}
433432
});
434433

435-
kind.make_from(expander.expand(self.cx, span, ident, marked_tts, attrs))
434+
kind.make_from(expander.expand(self.cx, span, ident, marked_tts))
436435
}
437436

438437
MultiDecorator(..) | MultiModifier(..) | SyntaxExtension::AttrProcMacro(..) => {
@@ -590,11 +589,8 @@ impl<'a, 'b> InvocationCollector<'a, 'b> {
590589
placeholder(expansion_kind, ast::NodeId::from_u32(mark.as_u32()))
591590
}
592591

593-
fn collect_bang(
594-
&mut self, mac: ast::Mac, attrs: Vec<ast::Attribute>, span: Span, kind: ExpansionKind,
595-
) -> Expansion {
596-
self.check_attributes(&attrs);
597-
self.collect(kind, InvocationKind::Bang { attrs: attrs, mac: mac, ident: None, span: span })
592+
fn collect_bang(&mut self, mac: ast::Mac, span: Span, kind: ExpansionKind) -> Expansion {
593+
self.collect(kind, InvocationKind::Bang { mac: mac, ident: None, span: span })
598594
}
599595

600596
fn collect_attr(&mut self, attr: ast::Attribute, item: Annotatable, kind: ExpansionKind)
@@ -663,7 +659,8 @@ impl<'a, 'b> Folder for InvocationCollector<'a, 'b> {
663659
expr.node = self.cfg.configure_expr_kind(expr.node);
664660

665661
if let ast::ExprKind::Mac(mac) = expr.node {
666-
self.collect_bang(mac, expr.attrs.into(), expr.span, ExpansionKind::Expr).make_expr()
662+
self.check_attributes(&expr.attrs);
663+
self.collect_bang(mac, expr.span, ExpansionKind::Expr).make_expr()
667664
} else {
668665
P(noop_fold_expr(expr, self))
669666
}
@@ -674,8 +671,8 @@ impl<'a, 'b> Folder for InvocationCollector<'a, 'b> {
674671
expr.node = self.cfg.configure_expr_kind(expr.node);
675672

676673
if let ast::ExprKind::Mac(mac) = expr.node {
677-
self.collect_bang(mac, expr.attrs.into(), expr.span, ExpansionKind::OptExpr)
678-
.make_opt_expr()
674+
self.check_attributes(&expr.attrs);
675+
self.collect_bang(mac, expr.span, ExpansionKind::OptExpr).make_opt_expr()
679676
} else {
680677
Some(P(noop_fold_expr(expr, self)))
681678
}
@@ -688,8 +685,7 @@ impl<'a, 'b> Folder for InvocationCollector<'a, 'b> {
688685
}
689686

690687
pat.and_then(|pat| match pat.node {
691-
PatKind::Mac(mac) =>
692-
self.collect_bang(mac, Vec::new(), pat.span, ExpansionKind::Pat).make_pat(),
688+
PatKind::Mac(mac) => self.collect_bang(mac, pat.span, ExpansionKind::Pat).make_pat(),
693689
_ => unreachable!(),
694690
})
695691
}
@@ -710,8 +706,8 @@ impl<'a, 'b> Folder for InvocationCollector<'a, 'b> {
710706
}).collect()
711707
};
712708

713-
let mut placeholder =
714-
self.collect_bang(mac, attrs.into(), stmt.span, ExpansionKind::Stmts).make_stmts();
709+
self.check_attributes(&attrs);
710+
let mut placeholder = self.collect_bang(mac, stmt.span, ExpansionKind::Stmts).make_stmts();
715711

716712
// If this is a macro invocation with a semicolon, then apply that
717713
// semicolon to the final statement produced by expansion.
@@ -758,7 +754,6 @@ impl<'a, 'b> Folder for InvocationCollector<'a, 'b> {
758754
ItemKind::Mac(mac) => {
759755
self.collect(ExpansionKind::Items, InvocationKind::Bang {
760756
mac: mac,
761-
attrs: item.attrs,
762757
ident: Some(item.ident),
763758
span: item.span,
764759
}).make_items()
@@ -830,7 +825,8 @@ impl<'a, 'b> Folder for InvocationCollector<'a, 'b> {
830825
match item.node {
831826
ast::TraitItemKind::Macro(mac) => {
832827
let ast::TraitItem { attrs, span, .. } = item;
833-
self.collect_bang(mac, attrs, span, ExpansionKind::TraitItems).make_trait_items()
828+
self.check_attributes(&attrs);
829+
self.collect_bang(mac, span, ExpansionKind::TraitItems).make_trait_items()
834830
}
835831
_ => fold::noop_fold_trait_item(item, self),
836832
}
@@ -848,7 +844,8 @@ impl<'a, 'b> Folder for InvocationCollector<'a, 'b> {
848844
match item.node {
849845
ast::ImplItemKind::Macro(mac) => {
850846
let ast::ImplItem { attrs, span, .. } = item;
851-
self.collect_bang(mac, attrs, span, ExpansionKind::ImplItems).make_impl_items()
847+
self.check_attributes(&attrs);
848+
self.collect_bang(mac, span, ExpansionKind::ImplItems).make_impl_items()
852849
}
853850
_ => fold::noop_fold_impl_item(item, self),
854851
}
@@ -861,8 +858,7 @@ impl<'a, 'b> Folder for InvocationCollector<'a, 'b> {
861858
};
862859

863860
match ty.node {
864-
ast::TyKind::Mac(mac) =>
865-
self.collect_bang(mac, Vec::new(), ty.span, ExpansionKind::Ty).make_ty(),
861+
ast::TyKind::Mac(mac) => self.collect_bang(mac, ty.span, ExpansionKind::Ty).make_ty(),
866862
_ => unreachable!(),
867863
}
868864
}

0 commit comments

Comments
 (0)