@@ -16,7 +16,7 @@ use ast;
16
16
use ext:: mtwt;
17
17
use ext:: build:: AstBuilder ;
18
18
use attr;
19
- use attr:: { AttrMetaMethods , WithAttrs } ;
19
+ use attr:: { AttrMetaMethods , WithAttrs , ThinAttributesExt } ;
20
20
use codemap;
21
21
use codemap:: { Span , Spanned , ExpnInfo , NameAndSpan , MacroBang , MacroAttribute } ;
22
22
use ext:: base:: * ;
@@ -86,14 +86,7 @@ pub fn expand_expr(e: P<ast::Expr>, fld: &mut MacroExpander) -> P<ast::Expr> {
86
86
// expr_mac should really be expr_ext or something; it's the
87
87
// entry-point for all syntax extensions.
88
88
ast:: ExprKind :: Mac ( mac) => {
89
- if let Some ( ref attrs) = attrs {
90
- check_attributes ( attrs, fld) ;
91
- }
92
-
93
- // Assert that we drop any macro attributes on the floor here
94
- drop ( attrs) ;
95
-
96
- expand_mac_invoc ( mac, span, fld)
89
+ expand_mac_invoc ( mac, attrs. into_attr_vec ( ) , span, fld)
97
90
}
98
91
99
92
ast:: ExprKind :: InPlace ( placer, value_expr) => {
@@ -204,7 +197,12 @@ pub fn expand_expr(e: P<ast::Expr>, fld: &mut MacroExpander) -> P<ast::Expr> {
204
197
}
205
198
206
199
/// Expand a (not-ident-style) macro invocation. Returns the result of expansion.
207
- fn expand_mac_invoc < T : MacroGenerable > ( mac : ast:: Mac , span : Span , fld : & mut MacroExpander ) -> T {
200
+ fn expand_mac_invoc < T > ( mac : ast:: Mac , attrs : Vec < ast:: Attribute > , span : Span ,
201
+ fld : & mut MacroExpander ) -> T
202
+ where T : MacroGenerable ,
203
+ {
204
+ check_attributes ( & attrs, fld) ;
205
+
208
206
// it would almost certainly be cleaner to pass the whole
209
207
// macro invocation in, rather than pulling it apart and
210
208
// marking the tts and the ctxt separately. This also goes
@@ -527,15 +525,8 @@ fn expand_stmt(stmt: Stmt, fld: &mut MacroExpander) -> SmallVector<Stmt> {
527
525
_ => return expand_non_macro_stmt ( stmt, fld)
528
526
} ;
529
527
530
- if let Some ( ref attrs) = attrs {
531
- check_attributes ( attrs, fld) ;
532
- }
533
-
534
- // Assert that we drop any macro attributes on the floor here
535
- drop ( attrs) ;
536
-
537
528
let mut fully_expanded: SmallVector < ast:: Stmt > =
538
- expand_mac_invoc ( mac. unwrap ( ) , stmt. span , fld) ;
529
+ expand_mac_invoc ( mac. unwrap ( ) , attrs . into_attr_vec ( ) , stmt. span , fld) ;
539
530
540
531
// If this is a macro invocation with a semicolon, then apply that
541
532
// semicolon to the final statement produced by expansion.
@@ -752,7 +743,7 @@ fn expand_pat(p: P<ast::Pat>, fld: &mut MacroExpander) -> P<ast::Pat> {
752
743
}
753
744
p. and_then ( |ast:: Pat { node, span, ..} | {
754
745
match node {
755
- PatKind :: Mac ( mac) => expand_mac_invoc ( mac, span, fld) ,
746
+ PatKind :: Mac ( mac) => expand_mac_invoc ( mac, Vec :: new ( ) , span, fld) ,
756
747
_ => unreachable ! ( )
757
748
}
758
749
} )
@@ -1007,8 +998,7 @@ fn expand_impl_item(ii: ast::ImplItem, fld: &mut MacroExpander)
1007
998
span : fld. new_span ( ii. span )
1008
999
} ) ,
1009
1000
ast:: ImplItemKind :: Macro ( mac) => {
1010
- check_attributes ( & ii. attrs , fld) ;
1011
- expand_mac_invoc ( mac, ii. span , fld)
1001
+ expand_mac_invoc ( mac, ii. attrs , ii. span , fld)
1012
1002
}
1013
1003
_ => fold:: noop_fold_impl_item ( ii, fld)
1014
1004
}
@@ -1052,7 +1042,7 @@ pub fn expand_type(t: P<ast::Ty>, fld: &mut MacroExpander) -> P<ast::Ty> {
1052
1042
let t = match t. node . clone ( ) {
1053
1043
ast:: TyKind :: Mac ( mac) => {
1054
1044
if fld. cx . ecfg . features . unwrap ( ) . type_macros {
1055
- expand_mac_invoc ( mac, t. span , fld)
1045
+ expand_mac_invoc ( mac, Vec :: new ( ) , t. span , fld)
1056
1046
} else {
1057
1047
feature_gate:: emit_feature_err (
1058
1048
& fld. cx . parse_sess . span_diagnostic ,
0 commit comments