]> git.lizzy.rs Git - rust.git/commitdiff
Improve `directory` computation during invocation collection.
authorJeffrey Seyfried <jeffrey.seyfried@gmail.com>
Mon, 5 Sep 2016 04:08:38 +0000 (04:08 +0000)
committerJeffrey Seyfried <jeffrey.seyfried@gmail.com>
Wed, 7 Sep 2016 22:42:17 +0000 (22:42 +0000)
src/libsyntax/ext/expand.rs

index c5b637a980000f50bbc42546aba64ecbfeed0670..4715eda8374900fb488ea6d6e5522b44a7d0d4ee 100644 (file)
@@ -615,16 +615,20 @@ fn fold_item(&mut self, item: P<ast::Item>) -> SmallVector<P<ast::Item>> {
             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();
                 }