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
19 changes: 13 additions & 6 deletions src/modules.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,12 +264,19 @@ impl<'ast, 'sess, 'c> ModResolver<'ast, 'sess> {
path,
directory_ownership,
..
}) => Ok(if mods_outside_ast.is_empty() {
SubModKind::External(path, directory_ownership)
} else {
mods_outside_ast.push((path, directory_ownership, sub_mod.clone()));
SubModKind::MultiExternal(mods_outside_ast)
}),
}) => {
if mods_outside_ast.is_empty() {
Ok(SubModKind::External(path, directory_ownership))
} else {
let should_insert = !mods_outside_ast
.iter()
.any(|(outside_path, _, _)| outside_path == &path);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: sorry for being picky, but I would rather write this using all instead of negation + any:

                    let should_insert = mods_outside_ast
                        .iter()
                        .all(|(outside_path, _, _)| outside_path != &path);

if should_insert {
mods_outside_ast.push((path, directory_ownership, sub_mod.clone()));
}
Ok(SubModKind::MultiExternal(mods_outside_ast))
}
}
Err(_) if !mods_outside_ast.is_empty() => {
Ok(SubModKind::MultiExternal(mods_outside_ast))
}
Expand Down
5 changes: 5 additions & 0 deletions tests/config/issue-3956.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
ignore = [
"tests/**/issue-3956/graphics.rs",
"tests/**/issue-3956/graphics_emu.rs"
]
recursive = true
2 changes: 2 additions & 0 deletions tests/target/issue-3956/graphics.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// rustfmt-config: issue-3956.toml
pub struct A;
2 changes: 2 additions & 0 deletions tests/target/issue-3956/graphics_emu.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// rustfmt-config: issue-3956.toml
pub struct B;
4 changes: 4 additions & 0 deletions tests/target/issue-3956/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// rustfmt-config: issue-3956.toml
#[cfg_attr(windows, path = "graphics.rs")]
#[cfg_attr(not(windows), path = "graphics_emu.rs")]
mod graphics;