From dc5cc1b1f28d93651981b94cb8ae7f05239335d0 Mon Sep 17 00:00:00 2001 From: Jeffrey Seyfried Date: Wed, 1 Jun 2016 10:25:19 +0000 Subject: [PATCH 1/2] Run decorators on expanded AST. --- src/libsyntax/ext/expand.rs | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/src/libsyntax/ext/expand.rs b/src/libsyntax/ext/expand.rs index c3202dbdbb49e..13507cb6dfda4 100644 --- a/src/libsyntax/ext/expand.rs +++ b/src/libsyntax/ext/expand.rs @@ -724,11 +724,7 @@ fn expand_annotatable(a: Annotatable, -> SmallVector { 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 = match a { + let new_items: SmallVector = match a { Annotatable::Item(it) => match it.node { ast::ItemKind::Mac(..) => { let new_items: SmallVector> = 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 { + 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 } From 635a82e74413b07904320f023968d33018635136 Mon Sep 17 00:00:00 2001 From: Jeffrey Seyfried Date: Wed, 1 Jun 2016 11:00:27 +0000 Subject: [PATCH 2/2] Add regression test. --- src/test/compile-fail/issue-32950.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 src/test/compile-fail/issue-32950.rs diff --git a/src/test/compile-fail/issue-32950.rs b/src/test/compile-fail/issue-32950.rs new file mode 100644 index 0000000000000..e47ebdd6a6938 --- /dev/null +++ b/src/test/compile-fail/issue-32950.rs @@ -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 or the MIT license +// , 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, concat_idents!(Foo, Bar)); + +#[rustc_error] +fn main() {} //~ ERROR compilation successful