about summary refs log tree commit diff
path: root/src/libsyntax
diff options
context:
space:
mode:
authorJeffrey Seyfried <jeffrey.seyfried@gmail.com>2016-06-01 10:25:19 +0000
committerJeffrey Seyfried <jeffrey.seyfried@gmail.com>2016-06-01 11:12:38 +0000
commitdc5cc1b1f28d93651981b94cb8ae7f05239335d0 (patch)
tree69e89215d60909e7836c9fdbb2d3d2dd9e48da8e /src/libsyntax
parentb522b25a41967f7aa6694767dc85745692844259 (diff)
downloadrust-dc5cc1b1f28d93651981b94cb8ae7f05239335d0.tar.gz
rust-dc5cc1b1f28d93651981b94cb8ae7f05239335d0.zip
Run decorators on expanded AST.
Diffstat (limited to 'src/libsyntax')
-rw-r--r--src/libsyntax/ext/expand.rs27
1 files changed, 14 insertions, 13 deletions
diff --git a/src/libsyntax/ext/expand.rs b/src/libsyntax/ext/expand.rs
index c3202dbdbb4..13507cb6dfd 100644
--- a/src/libsyntax/ext/expand.rs
+++ b/src/libsyntax/ext/expand.rs
@@ -724,11 +724,7 @@ fn expand_annotatable(a: Annotatable,
                       -> SmallVector<Annotatable> {
     let a = expand_item_multi_modifier(a, fld);
 
-    let mut decorator_items = SmallVector::zero();
-    let mut new_attrs = Vec::new();
-    expand_decorators(a.clone(), fld, &mut decorator_items, &mut new_attrs);
-
-    let mut new_items: SmallVector<Annotatable> = match a {
+    let new_items: SmallVector<Annotatable> = match a {
         Annotatable::Item(it) => match it.node {
             ast::ItemKind::Mac(..) => {
                 let new_items: SmallVector<P<ast::Item>> = it.and_then(|it| match it.node {
@@ -746,7 +742,7 @@ fn expand_annotatable(a: Annotatable,
                 if valid_ident {
                     fld.cx.mod_push(it.ident);
                 }
-                let macro_use = contains_macro_use(fld, &new_attrs[..]);
+                let macro_use = contains_macro_use(fld, &it.attrs);
                 let result = with_exts_frame!(fld.cx.syntax_env,
                                               macro_use,
                                               noop_fold_item(it, fld));
@@ -755,13 +751,7 @@ fn expand_annotatable(a: Annotatable,
                 }
                 result.into_iter().map(|i| Annotatable::Item(i)).collect()
             },
-            _ => {
-                let it = P(ast::Item {
-                    attrs: new_attrs,
-                    ..(*it).clone()
-                });
-                noop_fold_item(it, fld).into_iter().map(|i| Annotatable::Item(i)).collect()
-            }
+            _ => noop_fold_item(it, fld).into_iter().map(|i| Annotatable::Item(i)).collect(),
         },
 
         Annotatable::TraitItem(it) => match it.node {
@@ -790,6 +780,17 @@ fn expand_annotatable(a: Annotatable,
         }
     };
 
+    new_items.into_iter().flat_map(|a| decorate(a, fld)).collect()
+}
+
+fn decorate(a: Annotatable, fld: &mut MacroExpander) -> SmallVector<Annotatable> {
+    let mut decorator_items = SmallVector::zero();
+    let mut new_attrs = Vec::new();
+    expand_decorators(a.clone(), fld, &mut decorator_items, &mut new_attrs);
+    let decorator_items =
+        decorator_items.into_iter().flat_map(|a| expand_annotatable(a, fld)).collect();
+
+    let mut new_items = SmallVector::one(a.fold_attrs(new_attrs));
     new_items.push_all(decorator_items);
     new_items
 }