Skip to content

Commit 2f3c4f1

Browse files
committed
Improve directory computation during invocation collection.
1 parent 9594f16 commit 2f3c4f1

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
@@ -608,16 +608,20 @@ impl<'a, 'b> Folder for InvocationCollector<'a, 'b> {
608608
ast::ItemKind::Mod(ast::Mod { inner, .. }) => {
609609
let mut paths = (*self.cx.syntax_env.paths()).clone();
610610
paths.mod_path.push(item.ident);
611-
if item.span.contains(inner) {
611+
612+
// Detect if this is an inline module (`mod m { ... }` as opposed to `mod m;`).
613+
// In the non-inline case, `inner` is never the dummy span (c.f. `parse_item_mod`).
614+
// Thus, if `inner` is the dummy span, we know the module is inline.
615+
let inline_module = item.span.contains(inner) || inner == syntax_pos::DUMMY_SP;
616+
617+
if inline_module {
612618
paths.directory.push(&*{
613619
::attr::first_attr_value_str_by_name(&item.attrs, "path")
614620
.unwrap_or(item.ident.name.as_str())
615621
});
616622
} else {
617-
paths.directory = match inner {
618-
syntax_pos::DUMMY_SP => PathBuf::new(),
619-
_ => PathBuf::from(self.cx.parse_sess.codemap().span_to_filename(inner)),
620-
};
623+
paths.directory =
624+
PathBuf::from(self.cx.parse_sess.codemap().span_to_filename(inner));
621625
paths.directory.pop();
622626
}
623627

0 commit comments

Comments
 (0)