Auto merge of #34010 - jseyfried:decorate_expanded, r=nrc
Run decorators on expanded AST Fixes #32950. r? @nrc
This commit is contained in:
commit
ff1315591f
2 changed files with 32 additions and 13 deletions
|
@ -723,11 +723,7 @@ fn expand_annotatable(a: Annotatable,
|
||||||
-> SmallVector<Annotatable> {
|
-> SmallVector<Annotatable> {
|
||||||
let a = expand_item_multi_modifier(a, fld);
|
let a = expand_item_multi_modifier(a, fld);
|
||||||
|
|
||||||
let mut decorator_items = SmallVector::zero();
|
let new_items: SmallVector<Annotatable> = match a {
|
||||||
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 {
|
|
||||||
Annotatable::Item(it) => match it.node {
|
Annotatable::Item(it) => match it.node {
|
||||||
ast::ItemKind::Mac(..) => {
|
ast::ItemKind::Mac(..) => {
|
||||||
let new_items: SmallVector<P<ast::Item>> = it.and_then(|it| match it.node {
|
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 {
|
if valid_ident {
|
||||||
fld.cx.mod_push(it.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,
|
let result = with_exts_frame!(fld.cx.syntax_env,
|
||||||
macro_use,
|
macro_use,
|
||||||
noop_fold_item(it, fld));
|
noop_fold_item(it, fld));
|
||||||
|
@ -754,13 +750,7 @@ fn expand_annotatable(a: Annotatable,
|
||||||
}
|
}
|
||||||
result.into_iter().map(|i| Annotatable::Item(i)).collect()
|
result.into_iter().map(|i| Annotatable::Item(i)).collect()
|
||||||
},
|
},
|
||||||
_ => {
|
_ => noop_fold_item(it, fld).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()
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
|
|
||||||
Annotatable::TraitItem(it) => match it.node {
|
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.push_all(decorator_items);
|
||||||
new_items
|
new_items
|
||||||
}
|
}
|
||||||
|
|
18
src/test/compile-fail/issue-32950.rs
Normal file
18
src/test/compile-fail/issue-32950.rs
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
|
||||||
|
// file at the top-level directory of this distribution and at
|
||||||
|
// http://rust-lang.org/COPYRIGHT.
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||||
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||||
|
// option. This file may not be copied, modified, or distributed
|
||||||
|
// except according to those terms.
|
||||||
|
|
||||||
|
#![feature(type_macros, concat_idents, rustc_attrs)]
|
||||||
|
#![allow(unused)]
|
||||||
|
|
||||||
|
#[derive(Debug)] struct FooBar;
|
||||||
|
#[derive(Debug)] struct Baz<T>(T, concat_idents!(Foo, Bar));
|
||||||
|
|
||||||
|
#[rustc_error]
|
||||||
|
fn main() {} //~ ERROR compilation successful
|
Loading…
Add table
Add a link
Reference in a new issue