From ca35ca839582d74f045a4a1eb9e1a82e29f0e032 Mon Sep 17 00:00:00 2001 From: Taylor Cramer Date: Thu, 18 Oct 2018 17:11:51 -0700 Subject: 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 --- src/libsyntax/parse/parser.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'src/libsyntax/parse') diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index c7089a295fc..6c90b2d2acb 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()); } } -- cgit 1.4.1-3-g733a5