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
This commit is contained in:
parent
e7f5d48059
commit
ca35ca8395
@ -6426,6 +6426,17 @@ fn push_directory(&mut self, id: Ident, attrs: &[Attribute]) {
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,5 @@
|
||||
// compile-pass
|
||||
|
||||
mod x;
|
||||
|
||||
fn main() {}
|
5
src/test/ui/non_modrs_mods_and_inline_mods/x.rs
Normal file
5
src/test/ui/non_modrs_mods_and_inline_mods/x.rs
Normal file
@ -0,0 +1,5 @@
|
||||
// ignore-test: not a test
|
||||
|
||||
pub mod y {
|
||||
pub mod z;
|
||||
}
|
1
src/test/ui/non_modrs_mods_and_inline_mods/x/y/z/mod.rs
Normal file
1
src/test/ui/non_modrs_mods_and_inline_mods/x/y/z/mod.rs
Normal file
@ -0,0 +1 @@
|
||||
// ignore-test: not a test
|
Loading…
Reference in New Issue
Block a user