Skip to content

Commit

Permalink
Add comment and clean up expand_annotatable
Browse files Browse the repository at this point in the history
  • Loading branch information
jseyfried committed Jun 9, 2016
1 parent 13e3925 commit dbf0326
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
2 changes: 2 additions & 0 deletions src/libsyntax/ext/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
14 changes: 6 additions & 8 deletions src/libsyntax/ext/expand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand All @@ -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
Expand All @@ -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(_)) => {
Expand Down

0 comments on commit dbf0326

Please sign in to comment.