Skip to content

Commit 4f5cfa6

Browse files
committed
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
2 parents 1982f18 + ca35ca8 commit 4f5cfa6

File tree

4 files changed

+22
-0
lines changed

4 files changed

+22
-0
lines changed

src/libsyntax/parse/parser.rs

+11
Original file line numberDiff line numberDiff line change
@@ -6426,6 +6426,17 @@ impl<'a> Parser<'a> {
64266426
self.directory.path.to_mut().push(&path.as_str());
64276427
self.directory.ownership = DirectoryOwnership::Owned { relative: None };
64286428
} else {
6429+
// We have to push on the current module name in the case of relative
6430+
// paths in order to ensure that any additional module paths from inline
6431+
// `mod x { ... }` come after the relative extension.
6432+
//
6433+
// For example, a `mod z { ... }` inside `x/y.rs` should set the current
6434+
// directory path to `/x/y/z`, not `/x/z` with a relative offset of `y`.
6435+
if let DirectoryOwnership::Owned { relative } = &mut self.directory.ownership {
6436+
if let Some(ident) = relative.take() { // remove the relative offset
6437+
self.directory.path.to_mut().push(ident.as_str());
6438+
}
6439+
}
64296440
self.directory.path.to_mut().push(&id.as_str());
64306441
}
64316442
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// compile-pass
2+
3+
mod x;
4+
5+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// ignore-test: not a test
2+
3+
pub mod y {
4+
pub mod z;
5+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
// ignore-test: not a test

0 commit comments

Comments
 (0)