Fix module resolution in inner modules with paths (#4194)
This commit is contained in:
parent
aa11c27490
commit
89b7f5f382
@ -56,8 +56,6 @@ enum SubModKind<'a, 'ast> {
|
||||
External(PathBuf, DirectoryOwnership, Cow<'ast, ast::Mod>),
|
||||
/// `mod foo;` with multiple sources.
|
||||
MultiExternal(Vec<(PathBuf, DirectoryOwnership, Cow<'ast, ast::Mod>)>),
|
||||
/// `#[path = "..."] mod foo {}`
|
||||
InternalWithPath(PathBuf),
|
||||
/// `mod foo {}`
|
||||
Internal(&'a ast::Item),
|
||||
}
|
||||
@ -173,12 +171,7 @@ impl<'ast, 'sess, 'c> ModResolver<'ast, 'sess> {
|
||||
self.find_external_module(item.ident, &item.attrs, sub_mod)
|
||||
} else {
|
||||
// An internal module (`mod foo { /* ... */ }`);
|
||||
if let Some(path) = find_path_value(&item.attrs) {
|
||||
let path = Path::new(&*path.as_str()).to_path_buf();
|
||||
Ok(Some(SubModKind::InternalWithPath(path)))
|
||||
} else {
|
||||
Ok(Some(SubModKind::Internal(item)))
|
||||
}
|
||||
Ok(Some(SubModKind::Internal(item)))
|
||||
}
|
||||
}
|
||||
|
||||
@ -218,14 +211,6 @@ impl<'ast, 'sess, 'c> ModResolver<'ast, 'sess> {
|
||||
};
|
||||
self.visit_sub_mod_after_directory_update(sub_mod, Some(directory))
|
||||
}
|
||||
SubModKind::InternalWithPath(mod_path) => {
|
||||
// All `#[path]` files are treated as though they are a `mod.rs` file.
|
||||
let directory = Directory {
|
||||
path: mod_path,
|
||||
ownership: DirectoryOwnership::Owned { relative: None },
|
||||
};
|
||||
self.visit_sub_mod_after_directory_update(sub_mod, Some(directory))
|
||||
}
|
||||
SubModKind::Internal(ref item) => {
|
||||
self.push_inline_mod_directory(item.ident, &item.attrs);
|
||||
self.visit_sub_mod_after_directory_update(sub_mod, None)
|
||||
|
1
tests/target/inner-module-path/b.rs
Normal file
1
tests/target/inner-module-path/b.rs
Normal file
@ -0,0 +1 @@
|
||||
|
1
tests/target/inner-module-path/c/d.rs
Normal file
1
tests/target/inner-module-path/c/d.rs
Normal file
@ -0,0 +1 @@
|
||||
|
10
tests/target/inner-module-path/lib.rs
Normal file
10
tests/target/inner-module-path/lib.rs
Normal file
@ -0,0 +1,10 @@
|
||||
// rustfmt-recursive: true
|
||||
|
||||
#[path = "."]
|
||||
mod a {
|
||||
mod b;
|
||||
}
|
||||
|
||||
mod c {
|
||||
mod d;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user