summary refs log tree commit diff
path: root/src/libsyntax
diff options
context:
space:
mode:
authorJeffrey Seyfried <jeffrey.seyfried@gmail.com>2016-05-20 23:55:39 +0000
committerJeffrey Seyfried <jeffrey.seyfried@gmail.com>2016-05-21 23:01:02 +0000
commit215c1460f68a5c47f40ea173484cd791166ebc94 (patch)
tree4367d10885f825754c252f8d74cc3aee2a0cd796 /src/libsyntax
parentf4075e9467ef704d7f8cd120669faec455eb84f9 (diff)
downloadrust-215c1460f68a5c47f40ea173484cd791166ebc94.tar.gz
rust-215c1460f68a5c47f40ea173484cd791166ebc94.zip
Check attributes in `expand_mac_invoc`
Diffstat (limited to 'src/libsyntax')
-rw-r--r--src/libsyntax/ext/expand.rs34
1 files changed, 12 insertions, 22 deletions
diff --git a/src/libsyntax/ext/expand.rs b/src/libsyntax/ext/expand.rs
index 8a5689daca5..aa5d93d8269 100644
--- a/src/libsyntax/ext/expand.rs
+++ b/src/libsyntax/ext/expand.rs
@@ -16,7 +16,7 @@ use ast;
 use ext::mtwt;
 use ext::build::AstBuilder;
 use attr;
-use attr::{AttrMetaMethods, WithAttrs};
+use attr::{AttrMetaMethods, WithAttrs, ThinAttributesExt};
 use codemap;
 use codemap::{Span, Spanned, ExpnInfo, NameAndSpan, MacroBang, MacroAttribute};
 use ext::base::*;
@@ -86,14 +86,7 @@ pub fn expand_expr(e: P<ast::Expr>, fld: &mut MacroExpander) -> P<ast::Expr> {
         // expr_mac should really be expr_ext or something; it's the
         // entry-point for all syntax extensions.
         ast::ExprKind::Mac(mac) => {
-            if let Some(ref attrs) = attrs {
-                check_attributes(attrs, fld);
-            }
-
-            // Assert that we drop any macro attributes on the floor here
-            drop(attrs);
-
-            expand_mac_invoc(mac, span, fld)
+            expand_mac_invoc(mac, attrs.into_attr_vec(), span, fld)
         }
 
         ast::ExprKind::InPlace(placer, value_expr) => {
@@ -204,7 +197,12 @@ pub fn expand_expr(e: P<ast::Expr>, fld: &mut MacroExpander) -> P<ast::Expr> {
 }
 
 /// Expand a (not-ident-style) macro invocation. Returns the result of expansion.
-fn expand_mac_invoc<T: MacroGenerable>(mac: ast::Mac, span: Span, fld: &mut MacroExpander) -> T {
+fn expand_mac_invoc<T>(mac: ast::Mac, attrs: Vec<ast::Attribute>, span: Span,
+                       fld: &mut MacroExpander) -> T
+    where T: MacroGenerable,
+{
+    check_attributes(&attrs, fld);
+
     // it would almost certainly be cleaner to pass the whole
     // macro invocation in, rather than pulling it apart and
     // marking the tts and the ctxt separately. This also goes
@@ -527,15 +525,8 @@ fn expand_stmt(stmt: Stmt, fld: &mut MacroExpander) -> SmallVector<Stmt> {
         _ => return expand_non_macro_stmt(stmt, fld)
     };
 
-    if let Some(ref attrs) = attrs {
-        check_attributes(attrs, fld);
-    }
-
-    // Assert that we drop any macro attributes on the floor here
-    drop(attrs);
-
     let mut fully_expanded: SmallVector<ast::Stmt> =
-        expand_mac_invoc(mac.unwrap(), stmt.span, fld);
+        expand_mac_invoc(mac.unwrap(), attrs.into_attr_vec(), stmt.span, fld);
 
     // If this is a macro invocation with a semicolon, then apply that
     // 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> {
     }
     p.and_then(|ast::Pat {node, span, ..}| {
         match node {
-            PatKind::Mac(mac) => expand_mac_invoc(mac, span, fld),
+            PatKind::Mac(mac) => expand_mac_invoc(mac, Vec::new(), span, fld),
             _ => unreachable!()
         }
     })
@@ -1007,8 +998,7 @@ fn expand_impl_item(ii: ast::ImplItem, fld: &mut MacroExpander)
             span: fld.new_span(ii.span)
         }),
         ast::ImplItemKind::Macro(mac) => {
-            check_attributes(&ii.attrs, fld);
-            expand_mac_invoc(mac, ii.span, fld)
+            expand_mac_invoc(mac, ii.attrs, ii.span, fld)
         }
         _ => fold::noop_fold_impl_item(ii, fld)
     }
@@ -1052,7 +1042,7 @@ pub fn expand_type(t: P<ast::Ty>, fld: &mut MacroExpander) -> P<ast::Ty> {
     let t = match t.node.clone() {
         ast::TyKind::Mac(mac) => {
             if fld.cx.ecfg.features.unwrap().type_macros {
-                expand_mac_invoc(mac, t.span, fld)
+                expand_mac_invoc(mac, Vec::new(), t.span, fld)
             } else {
                 feature_gate::emit_feature_err(
                     &fld.cx.parse_sess.span_diagnostic,