about summary refs log tree commit diff
path: root/src/libsyntax/ext
diff options
context:
space:
mode:
authorJeffrey Seyfried <jeffrey.seyfried@gmail.com>2016-09-05 04:08:38 +0000
committerJeffrey Seyfried <jeffrey.seyfried@gmail.com>2016-09-07 22:42:17 +0000
commit9ac91fa48b3eb479cccb5695395faed8f59ece8e (patch)
treec120b3573d6c60429d98df001c059f046d5e0d74 /src/libsyntax/ext
parent2d759046ba685f419b3de79367e5b973c1b84105 (diff)
downloadrust-9ac91fa48b3eb479cccb5695395faed8f59ece8e.tar.gz
rust-9ac91fa48b3eb479cccb5695395faed8f59ece8e.zip
Improve `directory` computation during invocation collection.
Diffstat (limited to 'src/libsyntax/ext')
-rw-r--r--src/libsyntax/ext/expand.rs14
1 files changed, 9 insertions, 5 deletions
diff --git a/src/libsyntax/ext/expand.rs b/src/libsyntax/ext/expand.rs
index c5b637a9800..4715eda8374 100644
--- a/src/libsyntax/ext/expand.rs
+++ b/src/libsyntax/ext/expand.rs
@@ -615,16 +615,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();
                 }