Skip to content

Commit 9de9693

Browse files
committed
Add a test
rustfmt fails to format a function call when it has a single closure argument and that closure has a block body which contains comments at the beginnig of the block, and the block only contains a single expression as its statement. Phew!
1 parent 0a59654 commit 9de9693

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

tests/source/closure.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,16 @@ fn main() {
4141
let closure_with_return_type = |aaaaaaaaaaaaaaaaaaaaaaarg1, aaaaaaaaaaaaaaaaaaaaaaarg2| -> Strong { "sup".to_owned() };
4242

4343
|arg1, arg2, _, _, arg3, arg4| { let temp = arg4 + arg3;
44-
arg2 * arg1 - temp }
44+
arg2 * arg1 - temp };
45+
46+
let block_body_with_comment = args.iter()
47+
.map(|a| {
48+
// Emitting only dep-info is possible only for final crate type, as
49+
// as others may emit required metadata for dependent crate types
50+
if a.starts_with("--emit") && is_final_crate_type && !self.workspace_mode {
51+
"--emit=dep-info"
52+
} else { a }
53+
});
4554
}
4655

4756
fn issue311() {

tests/target/closure.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,17 @@ fn main() {
6060
|arg1, arg2, _, _, arg3, arg4| {
6161
let temp = arg4 + arg3;
6262
arg2 * arg1 - temp
63-
}
63+
};
64+
65+
let block_body_with_comment = args.iter().map(|a| {
66+
// Emitting only dep-info is possible only for final crate type, as
67+
// as others may emit required metadata for dependent crate types
68+
if a.starts_with("--emit") && is_final_crate_type && !self.workspace_mode {
69+
"--emit=dep-info"
70+
} else {
71+
a
72+
}
73+
});
6474
}
6575

6676
fn issue311() {

0 commit comments

Comments
 (0)