diff --git a/src/libsyntax/ext/base.rs b/src/libsyntax/ext/base.rs index 4b7086695eb..95624a43373 100644 --- a/src/libsyntax/ext/base.rs +++ b/src/libsyntax/ext/base.rs @@ -942,6 +942,8 @@ impl SyntaxEnv { } pub fn is_crate_root(&mut self) -> bool { + // The first frame is pushed in `SyntaxEnv::new()` and the second frame is + // pushed when folding the crate root pseudo-module (c.f. noop_fold_crate). self.chain.len() == 2 } } diff --git a/src/libsyntax/ext/expand.rs b/src/libsyntax/ext/expand.rs index c581a149f43..15d192b59b8 100644 --- a/src/libsyntax/ext/expand.rs +++ b/src/libsyntax/ext/expand.rs @@ -726,13 +726,11 @@ fn expand_annotatable(a: Annotatable, 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 { + it.and_then(|it| match it.node { ItemKind::Mac(mac) => expand_mac_invoc(mac, Some(it.ident), it.attrs, it.span, fld), _ => unreachable!(), - }); - - new_items.into_iter().map(|i| Annotatable::Item(i)).collect() + }) } ast::ItemKind::Mod(_) | ast::ItemKind::ForeignMod(_) => { let valid_ident = @@ -748,7 +746,7 @@ fn expand_annotatable(a: Annotatable, if valid_ident { fld.cx.mod_pop(); } - result.into_iter().map(|i| Annotatable::Item(i)).collect() + result }, ast::ItemKind::ExternCrate(_) => { // We need to error on `#[macro_use] extern crate` when it isn't at the @@ -757,10 +755,10 @@ fn expand_annotatable(a: Annotatable, for def in fld.cx.loader.load_crate(&it, allows_macros) { fld.cx.insert_macro(def); } - SmallVector::one(Annotatable::Item(it)) + SmallVector::one(it) }, - _ => 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 { ast::TraitItemKind::Method(_, Some(_)) => {