about summary refs log tree commit diff
path: root/src/libsyntax
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2018-10-28 13:13:55 +0000
committerbors <bors@rust-lang.org>2018-10-28 13:13:55 +0000
commit4f5cfa611d392e87166dfe053ca253c3e822d835 (patch)
treefe2f5727a9d012bd90378a38ee9cf499f4ab1a73 /src/libsyntax
parent1982f1887ad524951f24c12a6cc7bf05148aec14 (diff)
parentca35ca839582d74f045a4a1eb9e1a82e29f0e032 (diff)
downloadrust-4f5cfa611d392e87166dfe053ca253c3e822d835.tar.gz
rust-4f5cfa611d392e87166dfe053ca253c3e822d835.zip
Auto merge of #55192 - cramertj:nested-mod, r=petrochenkov
Fix ordering of nested modules in non-mod.rs mods

Flatten relative offset into directory path before adding inline
(mod x { ... }) module names to the current directory path.

Fix #55094
Diffstat (limited to 'src/libsyntax')
-rw-r--r--src/libsyntax/parse/parser.rs11
1 files changed, 11 insertions, 0 deletions
diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs
index 589b3e30fcf..be448f960df 100644
--- a/src/libsyntax/parse/parser.rs
+++ b/src/libsyntax/parse/parser.rs
@@ -6426,6 +6426,17 @@ impl<'a> Parser<'a> {
             self.directory.path.to_mut().push(&path.as_str());
             self.directory.ownership = DirectoryOwnership::Owned { relative: None };
         } else {
+            // We have to push on the current module name in the case of relative
+            // paths in order to ensure that any additional module paths from inline
+            // `mod x { ... }` come after the relative extension.
+            //
+            // For example, a `mod z { ... }` inside `x/y.rs` should set the current
+            // directory path to `/x/y/z`, not `/x/z` with a relative offset of `y`.
+            if let DirectoryOwnership::Owned { relative } = &mut self.directory.ownership {
+                if let Some(ident) = relative.take() { // remove the relative offset
+                    self.directory.path.to_mut().push(ident.as_str());
+                }
+            }
             self.directory.path.to_mut().push(&id.as_str());
         }
     }