Skip to content

Commit 83f44e2

Browse files
rchaser53topecongiro
authored andcommitted
fix not to overwrite on other platforms (#3971)
1 parent 0e89e3b commit 83f44e2

File tree

5 files changed

+26
-6
lines changed

5 files changed

+26
-6
lines changed

src/modules.rs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -264,12 +264,19 @@ impl<'ast, 'sess, 'c> ModResolver<'ast, 'sess> {
264264
path,
265265
directory_ownership,
266266
..
267-
}) => Ok(if mods_outside_ast.is_empty() {
268-
SubModKind::External(path, directory_ownership)
269-
} else {
270-
mods_outside_ast.push((path, directory_ownership, sub_mod.clone()));
271-
SubModKind::MultiExternal(mods_outside_ast)
272-
}),
267+
}) => {
268+
if mods_outside_ast.is_empty() {
269+
Ok(SubModKind::External(path, directory_ownership))
270+
} else {
271+
let should_insert = !mods_outside_ast
272+
.iter()
273+
.any(|(outside_path, _, _)| outside_path == &path);
274+
if should_insert {
275+
mods_outside_ast.push((path, directory_ownership, sub_mod.clone()));
276+
}
277+
Ok(SubModKind::MultiExternal(mods_outside_ast))
278+
}
279+
}
273280
Err(_) if !mods_outside_ast.is_empty() => {
274281
Ok(SubModKind::MultiExternal(mods_outside_ast))
275282
}

tests/config/issue-3956.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
ignore = [
2+
"tests/**/issue-3956/graphics.rs",
3+
"tests/**/issue-3956/graphics_emu.rs"
4+
]
5+
recursive = true

tests/target/issue-3956/graphics.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// rustfmt-config: issue-3956.toml
2+
pub struct A;
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// rustfmt-config: issue-3956.toml
2+
pub struct B;

tests/target/issue-3956/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// rustfmt-config: issue-3956.toml
2+
#[cfg_attr(windows, path = "graphics.rs")]
3+
#[cfg_attr(not(windows), path = "graphics_emu.rs")]
4+
mod graphics;

0 commit comments

Comments
 (0)