Skip to content

Commit 9549c3b

Browse files
authored
fixed => () to => {} (#4226)
1 parent 5f536d6 commit 9549c3b

24 files changed

+90
-70
lines changed

src/formatting/matches.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -377,12 +377,14 @@ fn rewrite_match_body(
377377
let comma = arm_comma(context.config, body, is_last);
378378
let alt_block_sep = &shape.indent.to_string_with_newline(context.config);
379379

380-
let combine_orig_body = |body_str: &str| {
380+
let combine_orig_body = |mut body_str: &str| {
381381
let block_sep = match context.config.control_brace_style() {
382382
ControlBraceStyle::AlwaysNextLine if is_block => alt_block_sep,
383383
_ => " ",
384384
};
385-
385+
if body_str == "()" {
386+
body_str = "{}";
387+
}
386388
Some(format!("{} =>{}{}{}", pats_str, block_sep, body_str, comma))
387389
};
388390

tests/source/catch.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ fn main() {
1515
let y = match (try {
1616
foo()?
1717
}) {
18-
_ => (),
18+
_ => {},
1919
};
2020

2121
try {

tests/source/cfg_if/detect/os/linux/auxvec.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ fn auxv_from_buf(buf: &[usize; 64]) -> Result<AuxVec, ()> {
159159
for el in buf.chunks(2) {
160160
match el[0] {
161161
AT_HWCAP => return Ok(AuxVec { hwcap: el[1] }),
162-
_ => (),
162+
_ => {}
163163
}
164164
}
165165
}
@@ -172,7 +172,7 @@ fn auxv_from_buf(buf: &[usize; 64]) -> Result<AuxVec, ()> {
172172
match el[0] {
173173
AT_HWCAP => hwcap = Some(el[1]),
174174
AT_HWCAP2 => hwcap2 = Some(el[1]),
175-
_ => (),
175+
_ => {}
176176
}
177177
}
178178

tests/source/chains-visual.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ fn main() {
1515
// Test case where first chain element isn't a path, but is shorter than
1616
// the size of a tab.
1717
x()
18-
.y(|| match cond() { true => (), false => () });
18+
.y(|| match cond() { true => {}, false => {}, });
1919

2020
loong_func()
2121
.quux(move || if true {

tests/source/chains.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ fn main() {
1616
// Test case where first chain element isn't a path, but is shorter than
1717
// the size of a tab.
1818
x()
19-
.y(|| match cond() { true => (), false => () });
19+
.y(|| match cond() { true => {} false => {} });
2020

2121
loong_func()
2222
.quux(move || if true {

tests/source/hard-tabs.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@ fn generic<T>(arg: T) -> &SomeType
6666

6767
x().y(|| {
6868
match cond() {
69-
true => (),
70-
false => (),
69+
true => {},
70+
false => {},
7171
}
7272
});
7373
}

tests/source/issue-1021.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
// rustfmt-normalize_comments: true
22
fn main() {
33
match x {
4-
S(true , .., true ) => (),
5-
S(true , .. ) => (),
6-
S(.., true ) => (),
7-
S( .. ) => (),
8-
S(_) => (),
9-
S(/* .. */ .. ) => (),
10-
S(/* .. */ .., true ) => (),
4+
S(true , .., true ) => {},
5+
S(true , .. ) => {},
6+
S(.., true ) => {},
7+
S( .. ) => {},
8+
S(_) => {},
9+
S(/* .. */ .. ) => {},
10+
S(/* .. */ .., true ) => {},
1111
}
1212

1313
match y {
14-
(true , .., true ) => (),
15-
(true , .. ) => (),
16-
(.., true ) => (),
17-
( .. ) => (),
18-
(_,) => (),
19-
(/* .. */ .. ) => (),
20-
(/* .. */ .., true ) => (),
14+
(true , .., true ) => {},
15+
(true , .. ) => {},
16+
(.., true ) => {},
17+
( .. ) => {},
18+
(_,) => {},
19+
(/* .. */ .. ) => {},
20+
(/* .. */ .., true ) => {},
2121
}
2222
}

tests/source/issue-1211.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ fn main() {
66
Some(ip) => {
77
sock.send_to(&buf, (ip, 8765)).expect("foobar");
88
}
9-
_ => ()
9+
_ => {},
1010
}
1111
}
12-
_ => ()
12+
_ => {},
1313
};
1414
}
1515
}

tests/source/issue-2955.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// rustfmt-condense_wildcard_suffixes: true
22
fn main() {
33
match (1, 2, 3) {
4-
(_, _, _) => (),
4+
(_, _, _) => {},
55
}
66
}

tests/source/issue-4065.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// rustfmt-match_block_trailing_comma: true
2+
3+
fn main() {
4+
let x = 1;
5+
match x {
6+
1 => (),
7+
2 => (),
8+
}
9+
}

tests/source/macros.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -319,16 +319,16 @@ impl Foo {
319319
// #819
320320
fn macro_in_pattern_position () {
321321
let x = match y {
322-
foo!( ) => (),
322+
foo!( ) => {}
323323
bar!( a, b,
324-
c) => (),
324+
c) => {}
325325
bar!(a
326326
, b
327327
, c
328-
,) => (),
328+
,) => {}
329329
baz!( 1 + 2 + 3, quux.kaas( )
330-
) => (),
331-
quux!(AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA, BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB) => (),
330+
) => {}
331+
quux!(AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA, BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB) => {}
332332
};
333333
}
334334

@@ -382,7 +382,7 @@ fn foo() {
382382
// #2591
383383
fn foo() {
384384
match 0u32 {
385-
0 => (),
385+
0 => {}
386386
_ => unreachable!(/* obviously */),
387387
}
388388
}

tests/source/match.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ fn issue383() {
241241
fn issue507() {
242242
match 1 {
243243
1 => unsafe { std::intrinsics::abort() },
244-
_ => (),
244+
_ => {},
245245
}
246246
}
247247

@@ -440,7 +440,7 @@ fn issue_2151() {
440440
match either {
441441
x => {
442442

443-
}y => ()
443+
}y => {},
444444
}
445445
}
446446

tests/target/catch.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ fn main() {
1111
};
1212

1313
let y = match (try { foo()? }) {
14-
_ => (),
14+
_ => {}
1515
};
1616

1717
try {

tests/target/cfg_if/detect/os/linux/auxvec.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ fn auxv_from_buf(buf: &[usize; 64]) -> Result<AuxVec, ()> {
156156
for el in buf.chunks(2) {
157157
match el[0] {
158158
AT_HWCAP => return Ok(AuxVec { hwcap: el[1] }),
159-
_ => (),
159+
_ => {}
160160
}
161161
}
162162
}
@@ -169,7 +169,7 @@ fn auxv_from_buf(buf: &[usize; 64]) -> Result<AuxVec, ()> {
169169
match el[0] {
170170
AT_HWCAP => hwcap = Some(el[1]),
171171
AT_HWCAP2 => hwcap2 = Some(el[1]),
172-
_ => (),
172+
_ => {}
173173
}
174174
}
175175

tests/target/chains-visual.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ fn main() {
1515
// Test case where first chain element isn't a path, but is shorter than
1616
// the size of a tab.
1717
x().y(|| match cond() {
18-
true => (),
19-
false => (),
18+
true => {}
19+
false => {}
2020
});
2121

2222
loong_func().quux(move || if true { 1 } else { 2 });

tests/target/chains.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ fn main() {
1717
// Test case where first chain element isn't a path, but is shorter than
1818
// the size of a tab.
1919
x().y(|| match cond() {
20-
true => (),
21-
false => (),
20+
true => {}
21+
false => {}
2222
});
2323

2424
loong_func().quux(move || {

tests/target/hard-tabs.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,8 @@ fn main() {
8181
a.b.c.d();
8282

8383
x().y(|| match cond() {
84-
true => (),
85-
false => (),
84+
true => {}
85+
false => {}
8686
});
8787
}
8888

tests/target/issue-1021.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
// rustfmt-normalize_comments: true
22
fn main() {
33
match x {
4-
S(true, .., true) => (),
5-
S(true, ..) => (),
6-
S(.., true) => (),
7-
S(..) => (),
8-
S(_) => (),
9-
S(/* .. */ ..) => (),
10-
S(/* .. */ .., true) => (),
4+
S(true, .., true) => {}
5+
S(true, ..) => {}
6+
S(.., true) => {}
7+
S(..) => {}
8+
S(_) => {}
9+
S(/* .. */ ..) => {}
10+
S(/* .. */ .., true) => {}
1111
}
1212

1313
match y {
14-
(true, .., true) => (),
15-
(true, ..) => (),
16-
(.., true) => (),
17-
(..) => (),
18-
(_,) => (),
19-
(/* .. */ ..) => (),
20-
(/* .. */ .., true) => (),
14+
(true, .., true) => {}
15+
(true, ..) => {}
16+
(.., true) => {}
17+
(..) => {}
18+
(_,) => {}
19+
(/* .. */ ..) => {}
20+
(/* .. */ .., true) => {}
2121
}
2222
}

tests/target/issue-1211.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ fn main() {
55
Some(ip) => {
66
sock.send_to(&buf, (ip, 8765)).expect("foobar");
77
}
8-
_ => (),
8+
_ => {}
99
},
10-
_ => (),
10+
_ => {}
1111
};
1212
}
1313
}

tests/target/issue-2554.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ fn main() {
77
//
88
})
99
}) {
10-
Ok(()) => (),
11-
Err(_) => (),
10+
Ok(()) => {}
11+
Err(_) => {}
1212
}
1313
}

tests/target/issue-2955.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// rustfmt-condense_wildcard_suffixes: true
22
fn main() {
33
match (1, 2, 3) {
4-
(..) => (),
4+
(..) => {}
55
}
66
}

tests/target/issue-4065.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// rustfmt-match_block_trailing_comma: true
2+
3+
fn main() {
4+
let x = 1;
5+
match x {
6+
1 => {},
7+
2 => {},
8+
}
9+
}

tests/target/macros.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -896,14 +896,14 @@ impl Foo {
896896
// #819
897897
fn macro_in_pattern_position() {
898898
let x = match y {
899-
foo!() => (),
900-
bar!(a, b, c) => (),
901-
bar!(a, b, c,) => (),
902-
baz!(1 + 2 + 3, quux.kaas()) => (),
899+
foo!() => {}
900+
bar!(a, b, c) => {}
901+
bar!(a, b, c,) => {}
902+
baz!(1 + 2 + 3, quux.kaas()) => {}
903903
quux!(
904904
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA,
905905
BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB
906-
) => (),
906+
) => {}
907907
};
908908
}
909909

@@ -956,7 +956,7 @@ fn foo() {
956956
// #2591
957957
fn foo() {
958958
match 0u32 {
959-
0 => (),
959+
0 => {}
960960
_ => unreachable!(/* obviously */),
961961
}
962962
}

tests/target/match.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ fn issue507() {
246246
1 => unsafe {
247247
std::intrinsics::abort()
248248
},
249-
_ => (),
249+
_ => {}
250250
}
251251
}
252252

@@ -466,7 +466,7 @@ impl<'tcx> Const<'tcx> {
466466
fn issue_2151() {
467467
match either {
468468
x => {}
469-
y => (),
469+
y => {}
470470
}
471471
}
472472

0 commit comments

Comments
 (0)