diff --git a/src/formatting/matches.rs b/src/formatting/matches.rs index a8a368a70a8..4d2889e5aa7 100644 --- a/src/formatting/matches.rs +++ b/src/formatting/matches.rs @@ -377,12 +377,14 @@ fn rewrite_match_body( let comma = arm_comma(context.config, body, is_last); let alt_block_sep = &shape.indent.to_string_with_newline(context.config); - let combine_orig_body = |body_str: &str| { + let combine_orig_body = |mut body_str: &str| { let block_sep = match context.config.control_brace_style() { ControlBraceStyle::AlwaysNextLine if is_block => alt_block_sep, _ => " ", }; - + if body_str == "()" { + body_str = "{}"; + } Some(format!("{} =>{}{}{}", pats_str, block_sep, body_str, comma)) }; diff --git a/tests/source/catch.rs b/tests/source/catch.rs index 541db1dc90c..3edafdb9bce 100644 --- a/tests/source/catch.rs +++ b/tests/source/catch.rs @@ -15,7 +15,7 @@ fn main() { let y = match (try { foo()? }) { - _ => (), + _ => {}, }; try { diff --git a/tests/source/cfg_if/detect/os/linux/auxvec.rs b/tests/source/cfg_if/detect/os/linux/auxvec.rs index 07b6432eafd..d7a2ed38ced 100644 --- a/tests/source/cfg_if/detect/os/linux/auxvec.rs +++ b/tests/source/cfg_if/detect/os/linux/auxvec.rs @@ -159,7 +159,7 @@ fn auxv_from_buf(buf: &[usize; 64]) -> Result { for el in buf.chunks(2) { match el[0] { AT_HWCAP => return Ok(AuxVec { hwcap: el[1] }), - _ => (), + _ => {} } } } @@ -172,7 +172,7 @@ fn auxv_from_buf(buf: &[usize; 64]) -> Result { match el[0] { AT_HWCAP => hwcap = Some(el[1]), AT_HWCAP2 => hwcap2 = Some(el[1]), - _ => (), + _ => {} } } diff --git a/tests/source/chains-visual.rs b/tests/source/chains-visual.rs index 20a96311e34..b7b0099c422 100644 --- a/tests/source/chains-visual.rs +++ b/tests/source/chains-visual.rs @@ -15,7 +15,7 @@ fn main() { // Test case where first chain element isn't a path, but is shorter than // the size of a tab. x() - .y(|| match cond() { true => (), false => () }); + .y(|| match cond() { true => {}, false => {}, }); loong_func() .quux(move || if true { diff --git a/tests/source/chains.rs b/tests/source/chains.rs index 3d8960035b4..6b30b43936a 100644 --- a/tests/source/chains.rs +++ b/tests/source/chains.rs @@ -16,7 +16,7 @@ fn main() { // Test case where first chain element isn't a path, but is shorter than // the size of a tab. x() - .y(|| match cond() { true => (), false => () }); + .y(|| match cond() { true => {} false => {} }); loong_func() .quux(move || if true { diff --git a/tests/source/hard-tabs.rs b/tests/source/hard-tabs.rs index e4a0f417007..5047c77bc93 100644 --- a/tests/source/hard-tabs.rs +++ b/tests/source/hard-tabs.rs @@ -66,8 +66,8 @@ fn generic(arg: T) -> &SomeType x().y(|| { match cond() { - true => (), - false => (), + true => {}, + false => {}, } }); } diff --git a/tests/source/issue-1021.rs b/tests/source/issue-1021.rs index 380e24cc0b0..fd21eee3ee5 100644 --- a/tests/source/issue-1021.rs +++ b/tests/source/issue-1021.rs @@ -1,22 +1,22 @@ // rustfmt-normalize_comments: true fn main() { match x { - S(true , .., true ) => (), - S(true , .. ) => (), - S(.., true ) => (), - S( .. ) => (), - S(_) => (), - S(/* .. */ .. ) => (), - S(/* .. */ .., true ) => (), + S(true , .., true ) => {}, + S(true , .. ) => {}, + S(.., true ) => {}, + S( .. ) => {}, + S(_) => {}, + S(/* .. */ .. ) => {}, + S(/* .. */ .., true ) => {}, } match y { - (true , .., true ) => (), - (true , .. ) => (), - (.., true ) => (), - ( .. ) => (), - (_,) => (), - (/* .. */ .. ) => (), - (/* .. */ .., true ) => (), + (true , .., true ) => {}, + (true , .. ) => {}, + (.., true ) => {}, + ( .. ) => {}, + (_,) => {}, + (/* .. */ .. ) => {}, + (/* .. */ .., true ) => {}, } } diff --git a/tests/source/issue-1211.rs b/tests/source/issue-1211.rs index 5818736bf6b..f1db21d4f80 100644 --- a/tests/source/issue-1211.rs +++ b/tests/source/issue-1211.rs @@ -6,10 +6,10 @@ fn main() { Some(ip) => { sock.send_to(&buf, (ip, 8765)).expect("foobar"); } - _ => () + _ => {}, } } - _ => () + _ => {}, }; } } diff --git a/tests/source/issue-2955.rs b/tests/source/issue-2955.rs index 525e070a57e..bd57db7cf68 100644 --- a/tests/source/issue-2955.rs +++ b/tests/source/issue-2955.rs @@ -1,6 +1,6 @@ // rustfmt-condense_wildcard_suffixes: true fn main() { match (1, 2, 3) { - (_, _, _) => (), + (_, _, _) => {}, } } diff --git a/tests/source/issue-4065.rs b/tests/source/issue-4065.rs new file mode 100644 index 00000000000..c0b2680ab66 --- /dev/null +++ b/tests/source/issue-4065.rs @@ -0,0 +1,9 @@ +// rustfmt-match_block_trailing_comma: true + +fn main() { + let x = 1; + match x { + 1 => (), + 2 => (), + } +} diff --git a/tests/source/macros.rs b/tests/source/macros.rs index 3b699dc204c..2611dd84826 100644 --- a/tests/source/macros.rs +++ b/tests/source/macros.rs @@ -319,16 +319,16 @@ impl Foo { // #819 fn macro_in_pattern_position () { let x = match y { - foo!( ) => (), + foo!( ) => {} bar!( a, b, - c) => (), + c) => {} bar!(a , b , c - ,) => (), + ,) => {} baz!( 1 + 2 + 3, quux.kaas( ) - ) => (), - quux!(AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA, BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB) => (), + ) => {} + quux!(AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA, BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB) => {} }; } @@ -382,7 +382,7 @@ fn foo() { // #2591 fn foo() { match 0u32 { - 0 => (), + 0 => {} _ => unreachable!(/* obviously */), } } diff --git a/tests/source/match.rs b/tests/source/match.rs index 79d66162b6e..1ac31a9e196 100644 --- a/tests/source/match.rs +++ b/tests/source/match.rs @@ -241,7 +241,7 @@ fn issue383() { fn issue507() { match 1 { 1 => unsafe { std::intrinsics::abort() }, - _ => (), + _ => {}, } } @@ -440,7 +440,7 @@ fn issue_2151() { match either { x => { - }y => () + }y => {}, } } diff --git a/tests/target/catch.rs b/tests/target/catch.rs index 20ef9595025..04ca5576bd2 100644 --- a/tests/target/catch.rs +++ b/tests/target/catch.rs @@ -11,7 +11,7 @@ fn main() { }; let y = match (try { foo()? }) { - _ => (), + _ => {} }; try { diff --git a/tests/target/cfg_if/detect/os/linux/auxvec.rs b/tests/target/cfg_if/detect/os/linux/auxvec.rs index 6ebae67fbf8..c4dfcc2ae82 100644 --- a/tests/target/cfg_if/detect/os/linux/auxvec.rs +++ b/tests/target/cfg_if/detect/os/linux/auxvec.rs @@ -156,7 +156,7 @@ fn auxv_from_buf(buf: &[usize; 64]) -> Result { for el in buf.chunks(2) { match el[0] { AT_HWCAP => return Ok(AuxVec { hwcap: el[1] }), - _ => (), + _ => {} } } } @@ -169,7 +169,7 @@ fn auxv_from_buf(buf: &[usize; 64]) -> Result { match el[0] { AT_HWCAP => hwcap = Some(el[1]), AT_HWCAP2 => hwcap2 = Some(el[1]), - _ => (), + _ => {} } } diff --git a/tests/target/chains-visual.rs b/tests/target/chains-visual.rs index 76ef99a4b59..bc0f4335c6f 100644 --- a/tests/target/chains-visual.rs +++ b/tests/target/chains-visual.rs @@ -15,8 +15,8 @@ fn main() { // Test case where first chain element isn't a path, but is shorter than // the size of a tab. x().y(|| match cond() { - true => (), - false => (), + true => {} + false => {} }); loong_func().quux(move || if true { 1 } else { 2 }); diff --git a/tests/target/chains.rs b/tests/target/chains.rs index dbace9a5bd4..d54bffb734b 100644 --- a/tests/target/chains.rs +++ b/tests/target/chains.rs @@ -17,8 +17,8 @@ fn main() { // Test case where first chain element isn't a path, but is shorter than // the size of a tab. x().y(|| match cond() { - true => (), - false => (), + true => {} + false => {} }); loong_func().quux(move || { diff --git a/tests/target/hard-tabs.rs b/tests/target/hard-tabs.rs index aca7e09c0ea..d581b8ae0ca 100644 --- a/tests/target/hard-tabs.rs +++ b/tests/target/hard-tabs.rs @@ -81,8 +81,8 @@ fn main() { a.b.c.d(); x().y(|| match cond() { - true => (), - false => (), + true => {} + false => {} }); } diff --git a/tests/target/issue-1021.rs b/tests/target/issue-1021.rs index ba1029d4e61..68855fe5ee0 100644 --- a/tests/target/issue-1021.rs +++ b/tests/target/issue-1021.rs @@ -1,22 +1,22 @@ // rustfmt-normalize_comments: true fn main() { match x { - S(true, .., true) => (), - S(true, ..) => (), - S(.., true) => (), - S(..) => (), - S(_) => (), - S(/* .. */ ..) => (), - S(/* .. */ .., true) => (), + S(true, .., true) => {} + S(true, ..) => {} + S(.., true) => {} + S(..) => {} + S(_) => {} + S(/* .. */ ..) => {} + S(/* .. */ .., true) => {} } match y { - (true, .., true) => (), - (true, ..) => (), - (.., true) => (), - (..) => (), - (_,) => (), - (/* .. */ ..) => (), - (/* .. */ .., true) => (), + (true, .., true) => {} + (true, ..) => {} + (.., true) => {} + (..) => {} + (_,) => {} + (/* .. */ ..) => {} + (/* .. */ .., true) => {} } } diff --git a/tests/target/issue-1211.rs b/tests/target/issue-1211.rs index de4c5c87ee6..be5b447a88b 100644 --- a/tests/target/issue-1211.rs +++ b/tests/target/issue-1211.rs @@ -5,9 +5,9 @@ fn main() { Some(ip) => { sock.send_to(&buf, (ip, 8765)).expect("foobar"); } - _ => (), + _ => {} }, - _ => (), + _ => {} }; } } diff --git a/tests/target/issue-2554.rs b/tests/target/issue-2554.rs index d5f0563a6f1..5eceda2f0a4 100644 --- a/tests/target/issue-2554.rs +++ b/tests/target/issue-2554.rs @@ -7,7 +7,7 @@ fn main() { // }) }) { - Ok(()) => (), - Err(_) => (), + Ok(()) => {} + Err(_) => {} } } diff --git a/tests/target/issue-2955.rs b/tests/target/issue-2955.rs index 799cd36e29a..2e03377b45a 100644 --- a/tests/target/issue-2955.rs +++ b/tests/target/issue-2955.rs @@ -1,6 +1,6 @@ // rustfmt-condense_wildcard_suffixes: true fn main() { match (1, 2, 3) { - (..) => (), + (..) => {} } } diff --git a/tests/target/issue-4065.rs b/tests/target/issue-4065.rs new file mode 100644 index 00000000000..c41d279d256 --- /dev/null +++ b/tests/target/issue-4065.rs @@ -0,0 +1,9 @@ +// rustfmt-match_block_trailing_comma: true + +fn main() { + let x = 1; + match x { + 1 => {}, + 2 => {}, + } +} diff --git a/tests/target/macros.rs b/tests/target/macros.rs index e930b5037d9..8c0db14a4b1 100644 --- a/tests/target/macros.rs +++ b/tests/target/macros.rs @@ -896,14 +896,14 @@ impl Foo { // #819 fn macro_in_pattern_position() { let x = match y { - foo!() => (), - bar!(a, b, c) => (), - bar!(a, b, c,) => (), - baz!(1 + 2 + 3, quux.kaas()) => (), + foo!() => {} + bar!(a, b, c) => {} + bar!(a, b, c,) => {} + baz!(1 + 2 + 3, quux.kaas()) => {} quux!( AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA, BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB - ) => (), + ) => {} }; } @@ -956,7 +956,7 @@ fn foo() { // #2591 fn foo() { match 0u32 { - 0 => (), + 0 => {} _ => unreachable!(/* obviously */), } } diff --git a/tests/target/match.rs b/tests/target/match.rs index b02eca78d64..7f91f4359bc 100644 --- a/tests/target/match.rs +++ b/tests/target/match.rs @@ -246,7 +246,7 @@ fn issue507() { 1 => unsafe { std::intrinsics::abort() }, - _ => (), + _ => {} } } @@ -466,7 +466,7 @@ impl<'tcx> Const<'tcx> { fn issue_2151() { match either { x => {} - y => (), + y => {} } }