From 2f3c4f1ecaabfb1dc8a0371dbc2a5d8b0a6ec812 Mon Sep 17 00:00:00 2001 From: Jeffrey Seyfried Date: Mon, 5 Sep 2016 04:08:38 +0000 Subject: [PATCH] Improve `directory` computation during invocation collection. --- src/libsyntax/ext/expand.rs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/libsyntax/ext/expand.rs b/src/libsyntax/ext/expand.rs index 3242d32c621b6..a9f0822e0f7cd 100644 --- a/src/libsyntax/ext/expand.rs +++ b/src/libsyntax/ext/expand.rs @@ -608,16 +608,20 @@ impl<'a, 'b> Folder for InvocationCollector<'a, 'b> { ast::ItemKind::Mod(ast::Mod { inner, .. }) => { let mut paths = (*self.cx.syntax_env.paths()).clone(); paths.mod_path.push(item.ident); - if item.span.contains(inner) { + + // Detect if this is an inline module (`mod m { ... }` as opposed to `mod m;`). + // In the non-inline case, `inner` is never the dummy span (c.f. `parse_item_mod`). + // Thus, if `inner` is the dummy span, we know the module is inline. + let inline_module = item.span.contains(inner) || inner == syntax_pos::DUMMY_SP; + + if inline_module { paths.directory.push(&*{ ::attr::first_attr_value_str_by_name(&item.attrs, "path") .unwrap_or(item.ident.name.as_str()) }); } else { - paths.directory = match inner { - syntax_pos::DUMMY_SP => PathBuf::new(), - _ => PathBuf::from(self.cx.parse_sess.codemap().span_to_filename(inner)), - }; + paths.directory = + PathBuf::from(self.cx.parse_sess.codemap().span_to_filename(inner)); paths.directory.pop(); }