]> git.lizzy.rs Git - rust.git/commitdiff
Add comment and clean up `expand_annotatable`
authorJeffrey Seyfried <jeffrey.seyfried@gmail.com>
Thu, 9 Jun 2016 00:47:52 +0000 (00:47 +0000)
committerJeffrey Seyfried <jeffrey.seyfried@gmail.com>
Thu, 9 Jun 2016 00:49:42 +0000 (00:49 +0000)
src/libsyntax/ext/base.rs
src/libsyntax/ext/expand.rs

index 4b7086695eb7d13c7bc3b988ab45d78e15379a9e..95624a433730a96d3b931f62edd92334b0b014e2 100644 (file)
@@ -942,6 +942,8 @@ pub fn info(&mut self) -> &mut BlockInfo {
     }
 
     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
     }
 }
index c581a149f43fa3aa85a750bf18bb4d53fca475cf..15d192b59b81ea5cb8abce588abaeb4c93818f3d 100644 (file)
@@ -726,13 +726,11 @@ fn expand_annotatable(a: Annotatable,
     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 {
+                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(_)) => {