Skip to content

Commit dbf0326

Browse files
committed
Add comment and clean up expand_annotatable
1 parent 13e3925 commit dbf0326

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

src/libsyntax/ext/base.rs

+2
Original file line numberDiff line numberDiff line change
@@ -942,6 +942,8 @@ impl SyntaxEnv {
942942
}
943943

944944
pub fn is_crate_root(&mut self) -> bool {
945+
// The first frame is pushed in `SyntaxEnv::new()` and the second frame is
946+
// pushed when folding the crate root pseudo-module (c.f. noop_fold_crate).
945947
self.chain.len() == 2
946948
}
947949
}

src/libsyntax/ext/expand.rs

+6-8
Original file line numberDiff line numberDiff line change
@@ -726,13 +726,11 @@ fn expand_annotatable(a: Annotatable,
726726
let new_items: SmallVector<Annotatable> = match a {
727727
Annotatable::Item(it) => match it.node {
728728
ast::ItemKind::Mac(..) => {
729-
let new_items: SmallVector<P<ast::Item>> = it.and_then(|it| match it.node {
729+
it.and_then(|it| match it.node {
730730
ItemKind::Mac(mac) =>
731731
expand_mac_invoc(mac, Some(it.ident), it.attrs, it.span, fld),
732732
_ => unreachable!(),
733-
});
734-
735-
new_items.into_iter().map(|i| Annotatable::Item(i)).collect()
733+
})
736734
}
737735
ast::ItemKind::Mod(_) | ast::ItemKind::ForeignMod(_) => {
738736
let valid_ident =
@@ -748,7 +746,7 @@ fn expand_annotatable(a: Annotatable,
748746
if valid_ident {
749747
fld.cx.mod_pop();
750748
}
751-
result.into_iter().map(|i| Annotatable::Item(i)).collect()
749+
result
752750
},
753751
ast::ItemKind::ExternCrate(_) => {
754752
// We need to error on `#[macro_use] extern crate` when it isn't at the
@@ -757,10 +755,10 @@ fn expand_annotatable(a: Annotatable,
757755
for def in fld.cx.loader.load_crate(&it, allows_macros) {
758756
fld.cx.insert_macro(def);
759757
}
760-
SmallVector::one(Annotatable::Item(it))
758+
SmallVector::one(it)
761759
},
762-
_ => noop_fold_item(it, fld).into_iter().map(|i| Annotatable::Item(i)).collect(),
763-
},
760+
_ => noop_fold_item(it, fld),
761+
}.into_iter().map(|i| Annotatable::Item(i)).collect(),
764762

765763
Annotatable::TraitItem(it) => match it.node {
766764
ast::TraitItemKind::Method(_, Some(_)) => {

0 commit comments

Comments
 (0)