Skip to content

Commit

Permalink
fixed => () to => {} (#4226)
Browse files Browse the repository at this point in the history
  • Loading branch information
lukebhan authored Jun 2, 2020
1 parent 5f536d6 commit 9549c3b
Show file tree
Hide file tree
Showing 24 changed files with 90 additions and 70 deletions.
6 changes: 4 additions & 2 deletions src/formatting/matches.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
};

Expand Down
2 changes: 1 addition & 1 deletion tests/source/catch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ fn main() {
let y = match (try {
foo()?
}) {
_ => (),
_ => {},
};

try {
Expand Down
4 changes: 2 additions & 2 deletions tests/source/cfg_if/detect/os/linux/auxvec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ fn auxv_from_buf(buf: &[usize; 64]) -> Result<AuxVec, ()> {
for el in buf.chunks(2) {
match el[0] {
AT_HWCAP => return Ok(AuxVec { hwcap: el[1] }),
_ => (),
_ => {}
}
}
}
Expand All @@ -172,7 +172,7 @@ fn auxv_from_buf(buf: &[usize; 64]) -> Result<AuxVec, ()> {
match el[0] {
AT_HWCAP => hwcap = Some(el[1]),
AT_HWCAP2 => hwcap2 = Some(el[1]),
_ => (),
_ => {}
}
}

Expand Down
2 changes: 1 addition & 1 deletion tests/source/chains-visual.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion tests/source/chains.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions tests/source/hard-tabs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ fn generic<T>(arg: T) -> &SomeType

x().y(|| {
match cond() {
true => (),
false => (),
true => {},
false => {},
}
});
}
Expand Down
28 changes: 14 additions & 14 deletions tests/source/issue-1021.rs
Original file line number Diff line number Diff line change
@@ -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 ) => {},
}
}
4 changes: 2 additions & 2 deletions tests/source/issue-1211.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ fn main() {
Some(ip) => {
sock.send_to(&buf, (ip, 8765)).expect("foobar");
}
_ => ()
_ => {},
}
}
_ => ()
_ => {},
};
}
}
2 changes: 1 addition & 1 deletion tests/source/issue-2955.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// rustfmt-condense_wildcard_suffixes: true
fn main() {
match (1, 2, 3) {
(_, _, _) => (),
(_, _, _) => {},
}
}
9 changes: 9 additions & 0 deletions tests/source/issue-4065.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// rustfmt-match_block_trailing_comma: true

fn main() {
let x = 1;
match x {
1 => (),
2 => (),
}
}
12 changes: 6 additions & 6 deletions tests/source/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {}
};
}

Expand Down Expand Up @@ -382,7 +382,7 @@ fn foo() {
// #2591
fn foo() {
match 0u32 {
0 => (),
0 => {}
_ => unreachable!(/* obviously */),
}
}
Expand Down
4 changes: 2 additions & 2 deletions tests/source/match.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ fn issue383() {
fn issue507() {
match 1 {
1 => unsafe { std::intrinsics::abort() },
_ => (),
_ => {},
}
}

Expand Down Expand Up @@ -440,7 +440,7 @@ fn issue_2151() {
match either {
x => {

}y => ()
}y => {},
}
}

Expand Down
2 changes: 1 addition & 1 deletion tests/target/catch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ fn main() {
};

let y = match (try { foo()? }) {
_ => (),
_ => {}
};

try {
Expand Down
4 changes: 2 additions & 2 deletions tests/target/cfg_if/detect/os/linux/auxvec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ fn auxv_from_buf(buf: &[usize; 64]) -> Result<AuxVec, ()> {
for el in buf.chunks(2) {
match el[0] {
AT_HWCAP => return Ok(AuxVec { hwcap: el[1] }),
_ => (),
_ => {}
}
}
}
Expand All @@ -169,7 +169,7 @@ fn auxv_from_buf(buf: &[usize; 64]) -> Result<AuxVec, ()> {
match el[0] {
AT_HWCAP => hwcap = Some(el[1]),
AT_HWCAP2 => hwcap2 = Some(el[1]),
_ => (),
_ => {}
}
}

Expand Down
4 changes: 2 additions & 2 deletions tests/target/chains-visual.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
Expand Down
4 changes: 2 additions & 2 deletions tests/target/chains.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 || {
Expand Down
4 changes: 2 additions & 2 deletions tests/target/hard-tabs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ fn main() {
a.b.c.d();

x().y(|| match cond() {
true => (),
false => (),
true => {}
false => {}
});
}

Expand Down
28 changes: 14 additions & 14 deletions tests/target/issue-1021.rs
Original file line number Diff line number Diff line change
@@ -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) => {}
}
}
4 changes: 2 additions & 2 deletions tests/target/issue-1211.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ fn main() {
Some(ip) => {
sock.send_to(&buf, (ip, 8765)).expect("foobar");
}
_ => (),
_ => {}
},
_ => (),
_ => {}
};
}
}
4 changes: 2 additions & 2 deletions tests/target/issue-2554.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ fn main() {
//
})
}) {
Ok(()) => (),
Err(_) => (),
Ok(()) => {}
Err(_) => {}
}
}
2 changes: 1 addition & 1 deletion tests/target/issue-2955.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// rustfmt-condense_wildcard_suffixes: true
fn main() {
match (1, 2, 3) {
(..) => (),
(..) => {}
}
}
9 changes: 9 additions & 0 deletions tests/target/issue-4065.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// rustfmt-match_block_trailing_comma: true

fn main() {
let x = 1;
match x {
1 => {},
2 => {},
}
}
12 changes: 6 additions & 6 deletions tests/target/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
) => (),
) => {}
};
}

Expand Down Expand Up @@ -956,7 +956,7 @@ fn foo() {
// #2591
fn foo() {
match 0u32 {
0 => (),
0 => {}
_ => unreachable!(/* obviously */),
}
}
Expand Down
4 changes: 2 additions & 2 deletions tests/target/match.rs
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ fn issue507() {
1 => unsafe {
std::intrinsics::abort()
},
_ => (),
_ => {}
}
}

Expand Down Expand Up @@ -466,7 +466,7 @@ impl<'tcx> Const<'tcx> {
fn issue_2151() {
match either {
x => {}
y => (),
y => {}
}
}

Expand Down

0 comments on commit 9549c3b

Please sign in to comment.