Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 1 addition & 16 deletions rustfmt-core/rustfmt-lib/src/formatting/modules.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,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),
}
Expand Down Expand Up @@ -154,12 +152,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)))
}
}

Expand Down Expand Up @@ -199,14 +192,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)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

10 changes: 10 additions & 0 deletions rustfmt-core/rustfmt-lib/tests/target/inner-module-path/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// rustfmt-recursive: true

#[path = "."]
mod a {
mod b;
}

mod c {
mod d;
}