diff options
| author | bors <bors@rust-lang.org> | 2016-06-08 02:05:38 -0700 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2016-06-08 02:05:38 -0700 |
| commit | ff1315591fb8b4c25fd3ca83093982ae4dd973bc (patch) | |
| tree | 20487a69f9d750e70d05c733a4a2cf5fa1fed648 /src/libsyntax | |
| parent | 368f6ae8cb03c0986d30af704b64c58a2b87dfe4 (diff) | |
| parent | 635a82e74413b07904320f023968d33018635136 (diff) | |
| download | rust-ff1315591fb8b4c25fd3ca83093982ae4dd973bc.tar.gz rust-ff1315591fb8b4c25fd3ca83093982ae4dd973bc.zip | |
Auto merge of #34010 - jseyfried:decorate_expanded, r=nrc
Run decorators on expanded AST Fixes #32950. r? @nrc
Diffstat (limited to 'src/libsyntax')
| -rw-r--r-- | src/libsyntax/ext/expand.rs | 27 |
1 files changed, 14 insertions, 13 deletions
diff --git a/src/libsyntax/ext/expand.rs b/src/libsyntax/ext/expand.rs index d3f5a573218..7fee27c5dd4 100644 --- a/src/libsyntax/ext/expand.rs +++ b/src/libsyntax/ext/expand.rs @@ -723,11 +723,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 { @@ -745,7 +741,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)); @@ -754,13 +750,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 { @@ -789,6 +779,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 } |
