Skip to content

Commit

Permalink
Remove scope placeholders from the crate root.
Browse files Browse the repository at this point in the history
  • Loading branch information
jseyfried committed Sep 13, 2016
1 parent c86c8d4 commit f3c2dca
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/libsyntax/ext/expand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,15 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
fn expand_crate(&mut self, mut krate: ast::Crate) -> ast::Crate {
let err_count = self.cx.parse_sess.span_diagnostic.err_count();

let items = Expansion::Items(SmallVector::many(krate.module.items));
krate.module.items = self.expand(items).make_items().into();
let mut krate_item = placeholder(ExpansionKind::Items, ast::DUMMY_NODE_ID)
.make_items().pop().unwrap().unwrap();
krate_item.node = ast::ItemKind::Mod(krate.module);
let krate_item = Expansion::Items(SmallVector::one(P(krate_item)));

krate.module = match self.expand(krate_item).make_items().pop().unwrap().unwrap().node {
ast::ItemKind::Mod(module) => module,
_ => unreachable!(),
};
krate.exported_macros = mem::replace(&mut self.cx.exported_macros, Vec::new());

for def in &mut krate.exported_macros {
Expand Down Expand Up @@ -596,6 +603,10 @@ impl<'a, 'b> Folder for InvocationCollector<'a, 'b> {
})
}
ast::ItemKind::Mod(ast::Mod { inner, .. }) => {
if item.ident == keywords::Invalid.ident() {
return noop_fold_item(item, self);
}

let mut module = (*self.cx.current_expansion.module).clone();
module.mod_path.push(item.ident);

Expand Down

0 comments on commit f3c2dca

Please sign in to comment.