Skip to content

Commit 9ac91fa

Browse files
committed
Improve directory computation during invocation collection.
1 parent 2d75904 commit 9ac91fa

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

src/libsyntax/ext/expand.rs

+9-5
Original file line numberDiff line numberDiff line change
@@ -615,16 +615,20 @@ impl<'a, 'b> Folder for InvocationCollector<'a, 'b> {
615615
ast::ItemKind::Mod(ast::Mod { inner, .. }) => {
616616
let mut paths = (*self.cx.syntax_env.paths()).clone();
617617
paths.mod_path.push(item.ident);
618-
if item.span.contains(inner) {
618+
619+
// Detect if this is an inline module (`mod m { ... }` as opposed to `mod m;`).
620+
// In the non-inline case, `inner` is never the dummy span (c.f. `parse_item_mod`).
621+
// Thus, if `inner` is the dummy span, we know the module is inline.
622+
let inline_module = item.span.contains(inner) || inner == syntax_pos::DUMMY_SP;
623+
624+
if inline_module {
619625
paths.directory.push(&*{
620626
::attr::first_attr_value_str_by_name(&item.attrs, "path")
621627
.unwrap_or(item.ident.name.as_str())
622628
});
623629
} else {
624-
paths.directory = match inner {
625-
syntax_pos::DUMMY_SP => PathBuf::new(),
626-
_ => PathBuf::from(self.cx.parse_sess.codemap().span_to_filename(inner)),
627-
};
630+
paths.directory =
631+
PathBuf::from(self.cx.parse_sess.codemap().span_to_filename(inner));
628632
paths.directory.pop();
629633
}
630634

0 commit comments

Comments
 (0)