Skip to content

Commit 503a10b

Browse files
committed
Clean up module processing.
1 parent 2a83574 commit 503a10b

File tree

1 file changed

+20
-34
lines changed

1 file changed

+20
-34
lines changed

src/libsyntax/ext/expand.rs

Lines changed: 20 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -465,18 +465,28 @@ fn expand_item(item: P<ast::Item>, fld: &mut MacroExpander) -> SmallVector<P<ast
465465
_ => unreachable!(),
466466
})
467467
}
468-
ast::ItemKind::Mod(_) | ast::ItemKind::ForeignMod(_) => {
469-
let valid_ident =
470-
item.ident.name != keywords::Invalid.name();
468+
ast::ItemKind::Mod(ast::Mod { inner, .. }) => {
469+
fld.cx.mod_push(item.ident);
470+
let macro_use = contains_macro_use(fld, &item.attrs);
471471

472-
if valid_ident {
473-
fld.cx.mod_push(item.ident);
472+
let directory = fld.cx.directory.clone();
473+
if item.span.contains(inner) {
474+
fld.cx.directory.push(&*{
475+
::attr::first_attr_value_str_by_name(&item.attrs, "path")
476+
.unwrap_or(item.ident.name.as_str())
477+
});
478+
} else {
479+
fld.cx.directory = match inner {
480+
syntax_pos::DUMMY_SP => PathBuf::new(),
481+
_ => PathBuf::from(fld.cx.parse_sess.codemap().span_to_filename(inner)),
482+
};
483+
fld.cx.directory.pop();
474484
}
475-
let macro_use = contains_macro_use(fld, &item.attrs);
485+
476486
let result = fld.with_exts_frame(macro_use, |fld| noop_fold_item(item, fld));
477-
if valid_ident {
478-
fld.cx.mod_pop();
479-
}
487+
fld.cx.directory = directory;
488+
489+
fld.cx.mod_pop();
480490
result
481491
},
482492
_ => noop_fold_item(item, fld),
@@ -639,31 +649,7 @@ impl<'a, 'b> Folder for MacroExpander<'a, 'b> {
639649
}
640650

641651
fn fold_item(&mut self, item: P<ast::Item>) -> SmallVector<P<ast::Item>> {
642-
use std::mem::replace;
643-
let result;
644-
if let ast::ItemKind::Mod(ast::Mod { inner, .. }) = item.node {
645-
if item.span.contains(inner) {
646-
let directory = self.cx.directory.clone();
647-
self.cx.directory.push(&*{
648-
::attr::first_attr_value_str_by_name(&item.attrs, "path")
649-
.unwrap_or(item.ident.name.as_str())
650-
});
651-
result = expand_annotatable(Annotatable::Item(item), self).make_items();
652-
self.cx.directory = directory;
653-
} else {
654-
let mut directory = match inner {
655-
syntax_pos::DUMMY_SP => PathBuf::new(),
656-
_ => PathBuf::from(self.cx.parse_sess.codemap().span_to_filename(inner)),
657-
};
658-
directory.pop();
659-
let directory = replace(&mut self.cx.directory, directory);
660-
result = expand_annotatable(Annotatable::Item(item), self).make_items();
661-
self.cx.directory = directory;
662-
}
663-
} else {
664-
result = expand_annotatable(Annotatable::Item(item), self).make_items();
665-
}
666-
result
652+
expand_annotatable(Annotatable::Item(item), self).make_items()
667653
}
668654

669655
fn fold_stmt(&mut self, stmt: ast::Stmt) -> SmallVector<ast::Stmt> {

0 commit comments

Comments
 (0)