Skip to content

Commit 3906144

Browse files
author
mahkoh
authored
Fix module resolution in inner modules with paths (#4194)
1 parent 2fec368 commit 3906144

File tree

4 files changed

+13
-16
lines changed

4 files changed

+13
-16
lines changed

rustfmt-core/rustfmt-lib/src/formatting/modules.rs

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,6 @@ enum SubModKind<'a, 'ast> {
3737
External(PathBuf, DirectoryOwnership, Cow<'ast, ast::Mod>),
3838
/// `mod foo;` with multiple sources.
3939
MultiExternal(Vec<(PathBuf, DirectoryOwnership, Cow<'ast, ast::Mod>)>),
40-
/// `#[path = "..."] mod foo {}`
41-
InternalWithPath(PathBuf),
4240
/// `mod foo {}`
4341
Internal(&'a ast::Item),
4442
}
@@ -154,12 +152,7 @@ impl<'ast, 'sess, 'c> ModResolver<'ast, 'sess> {
154152
self.find_external_module(item.ident, &item.attrs, sub_mod)
155153
} else {
156154
// An internal module (`mod foo { /* ... */ }`);
157-
if let Some(path) = find_path_value(&item.attrs) {
158-
let path = Path::new(&*path.as_str()).to_path_buf();
159-
Ok(Some(SubModKind::InternalWithPath(path)))
160-
} else {
161-
Ok(Some(SubModKind::Internal(item)))
162-
}
155+
Ok(Some(SubModKind::Internal(item)))
163156
}
164157
}
165158

@@ -199,14 +192,6 @@ impl<'ast, 'sess, 'c> ModResolver<'ast, 'sess> {
199192
};
200193
self.visit_sub_mod_after_directory_update(sub_mod, Some(directory))
201194
}
202-
SubModKind::InternalWithPath(mod_path) => {
203-
// All `#[path]` files are treated as though they are a `mod.rs` file.
204-
let directory = Directory {
205-
path: mod_path,
206-
ownership: DirectoryOwnership::Owned { relative: None },
207-
};
208-
self.visit_sub_mod_after_directory_update(sub_mod, Some(directory))
209-
}
210195
SubModKind::Internal(ref item) => {
211196
self.push_inline_mod_directory(item.ident, &item.attrs);
212197
self.visit_sub_mod_after_directory_update(sub_mod, None)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Lines changed: 10 additions & 0 deletions
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)