Skip to content

Commit ff13155

Browse files
committedJun 8, 2016
Auto merge of #34010 - jseyfried:decorate_expanded, r=nrc
Run decorators on expanded AST Fixes #32950. r? @nrc
2 parents 368f6ae + 635a82e commit ff13155

File tree

2 files changed

+32
-13
lines changed

2 files changed

+32
-13
lines changed
 

Diff for: ‎src/libsyntax/ext/expand.rs

+14-13
Original file line numberDiff line numberDiff line change
@@ -723,11 +723,7 @@ fn expand_annotatable(a: Annotatable,
723723
-> SmallVector<Annotatable> {
724724
let a = expand_item_multi_modifier(a, fld);
725725

726-
let mut decorator_items = SmallVector::zero();
727-
let mut new_attrs = Vec::new();
728-
expand_decorators(a.clone(), fld, &mut decorator_items, &mut new_attrs);
729-
730-
let mut new_items: SmallVector<Annotatable> = match a {
726+
let new_items: SmallVector<Annotatable> = match a {
731727
Annotatable::Item(it) => match it.node {
732728
ast::ItemKind::Mac(..) => {
733729
let new_items: SmallVector<P<ast::Item>> = it.and_then(|it| match it.node {
@@ -745,7 +741,7 @@ fn expand_annotatable(a: Annotatable,
745741
if valid_ident {
746742
fld.cx.mod_push(it.ident);
747743
}
748-
let macro_use = contains_macro_use(fld, &new_attrs[..]);
744+
let macro_use = contains_macro_use(fld, &it.attrs);
749745
let result = with_exts_frame!(fld.cx.syntax_env,
750746
macro_use,
751747
noop_fold_item(it, fld));
@@ -754,13 +750,7 @@ fn expand_annotatable(a: Annotatable,
754750
}
755751
result.into_iter().map(|i| Annotatable::Item(i)).collect()
756752
},
757-
_ => {
758-
let it = P(ast::Item {
759-
attrs: new_attrs,
760-
..(*it).clone()
761-
});
762-
noop_fold_item(it, fld).into_iter().map(|i| Annotatable::Item(i)).collect()
763-
}
753+
_ => noop_fold_item(it, fld).into_iter().map(|i| Annotatable::Item(i)).collect(),
764754
},
765755

766756
Annotatable::TraitItem(it) => match it.node {
@@ -789,6 +779,17 @@ fn expand_annotatable(a: Annotatable,
789779
}
790780
};
791781

782+
new_items.into_iter().flat_map(|a| decorate(a, fld)).collect()
783+
}
784+
785+
fn decorate(a: Annotatable, fld: &mut MacroExpander) -> SmallVector<Annotatable> {
786+
let mut decorator_items = SmallVector::zero();
787+
let mut new_attrs = Vec::new();
788+
expand_decorators(a.clone(), fld, &mut decorator_items, &mut new_attrs);
789+
let decorator_items =
790+
decorator_items.into_iter().flat_map(|a| expand_annotatable(a, fld)).collect();
791+
792+
let mut new_items = SmallVector::one(a.fold_attrs(new_attrs));
792793
new_items.push_all(decorator_items);
793794
new_items
794795
}

Diff for: ‎src/test/compile-fail/issue-32950.rs

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
#![feature(type_macros, concat_idents, rustc_attrs)]
12+
#![allow(unused)]
13+
14+
#[derive(Debug)] struct FooBar;
15+
#[derive(Debug)] struct Baz<T>(T, concat_idents!(Foo, Bar));
16+
17+
#[rustc_error]
18+
fn main() {} //~ ERROR compilation successful

0 commit comments

Comments
 (0)