Skip to content

Commit 89b7f5f

Browse files
mahkohcalebcartwright
mahkoh
authored andcommitted
Fix module resolution in inner modules with paths (#4194)
1 parent aa11c27 commit 89b7f5f

File tree

4 files changed

+13
-16
lines changed

4 files changed

+13
-16
lines changed

src/modules.rs

+1-16
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,6 @@ enum SubModKind<'a, 'ast> {
5656
External(PathBuf, DirectoryOwnership, Cow<'ast, ast::Mod>),
5757
/// `mod foo;` with multiple sources.
5858
MultiExternal(Vec<(PathBuf, DirectoryOwnership, Cow<'ast, ast::Mod>)>),
59-
/// `#[path = "..."] mod foo {}`
60-
InternalWithPath(PathBuf),
6159
/// `mod foo {}`
6260
Internal(&'a ast::Item),
6361
}
@@ -173,12 +171,7 @@ impl<'ast, 'sess, 'c> ModResolver<'ast, 'sess> {
173171
self.find_external_module(item.ident, &item.attrs, sub_mod)
174172
} else {
175173
// An internal module (`mod foo { /* ... */ }`);
176-
if let Some(path) = find_path_value(&item.attrs) {
177-
let path = Path::new(&*path.as_str()).to_path_buf();
178-
Ok(Some(SubModKind::InternalWithPath(path)))
179-
} else {
180-
Ok(Some(SubModKind::Internal(item)))
181-
}
174+
Ok(Some(SubModKind::Internal(item)))
182175
}
183176
}
184177

@@ -218,14 +211,6 @@ impl<'ast, 'sess, 'c> ModResolver<'ast, 'sess> {
218211
};
219212
self.visit_sub_mod_after_directory_update(sub_mod, Some(directory))
220213
}
221-
SubModKind::InternalWithPath(mod_path) => {
222-
// All `#[path]` files are treated as though they are a `mod.rs` file.
223-
let directory = Directory {
224-
path: mod_path,
225-
ownership: DirectoryOwnership::Owned { relative: None },
226-
};
227-
self.visit_sub_mod_after_directory_update(sub_mod, Some(directory))
228-
}
229214
SubModKind::Internal(ref item) => {
230215
self.push_inline_mod_directory(item.ident, &item.attrs);
231216
self.visit_sub_mod_after_directory_update(sub_mod, None)

tests/target/inner-module-path/b.rs

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

tests/target/inner-module-path/c/d.rs

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

tests/target/inner-module-path/lib.rs

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// rustfmt-recursive: true
2+
3+
#[path = "."]
4+
mod a {
5+
mod b;
6+
}
7+
8+
mod c {
9+
mod d;
10+
}

0 commit comments

Comments
 (0)