From: Nick Cameron Date: Mon, 27 Nov 2017 04:35:27 +0000 (+1300) Subject: Rename wrap_match_arms to match_arm_blocks X-Git-Url: https://git.lizzy.rs/?a=commitdiff_plain;h=9a332558348cda0c5f0e2a1647b8e8be38553784;p=rust.git Rename wrap_match_arms to match_arm_blocks --- diff --git a/Configurations.md b/Configurations.md index 76589314e03..50a0c4a1c89 100644 --- a/Configurations.md +++ b/Configurations.md @@ -1138,7 +1138,7 @@ match lorem { } ``` -See also: [`trailing_comma`](#trailing_comma), [`wrap_match_arms`](#wrap_match_arms). +See also: [`trailing_comma`](#trailing_comma), [`match_arm_blocks`](#match_arm_blocks). ## `max_width` @@ -1806,7 +1806,7 @@ Break comments to fit on the line // commodo consequat. ``` -## `wrap_match_arms` +## `match_arm_blocks` Wrap the body of arms in blocks when it does not fit on the same line with the pattern of arms diff --git a/src/config.rs b/src/config.rs index c6225222231..f1ce217a36b 100644 --- a/src/config.rs +++ b/src/config.rs @@ -618,12 +618,6 @@ pub fn get_toml_path(dir: &Path) -> Result, Error> { reorder_imported_names: bool, true, false, "Reorder lists of names in import statements alphabetically"; - // Match - wrap_match_arms: bool, true, false, "Wrap the body of arms in blocks when it does not fit on \ - the same line with the pattern of arms"; - match_block_trailing_comma: bool, false, false, - "Put a trailing comma after a block based match arm (non-block arms are not affected)"; - // Spaces around punctuation binop_separator: SeparatorPlace, SeparatorPlace::Front, false, "Where to put a binary operator when a binary expression goes multiline."; @@ -643,6 +637,8 @@ pub fn get_toml_path(dir: &Path) -> Result, Error> { "Remove blank lines at start or end of a block"; same_line_attributes: bool, true, false, "Try to put attributes on the same line as fields and variants."; + match_arm_blocks: bool, true, false, "Wrap the body of arms in blocks when it does not fit on \ + the same line with the pattern of arms"; force_multiline_blocks: bool, false, false, "Force multiline closure bodies and match arms to be wrapped in a block"; fn_args_density: Density, Density::Tall, false, "Argument density in functions"; @@ -653,6 +649,8 @@ pub fn get_toml_path(dir: &Path) -> Result, Error> { "How to handle trailing commas for lists"; trailing_semicolon: bool, true, false, "Add trailing semicolon after break, continue and return"; + match_block_trailing_comma: bool, false, false, + "Put a trailing comma after a block based match arm (non-block arms are not affected)"; // Options that can change the source code beyond whitespace/blocks (somewhat linty things) merge_derives: bool, true, true, "Merge multiple `#[derive(...)]` into a single one"; diff --git a/src/expr.rs b/src/expr.rs index 9d29425a5dd..812ebd5cf3a 100644 --- a/src/expr.rs +++ b/src/expr.rs @@ -1559,7 +1559,7 @@ fn rewrite_match_body( let indent_str = shape.indent.to_string(context.config); let nested_indent_str = next_line_indent.to_string(context.config); - let (body_prefix, body_suffix) = if context.config.wrap_match_arms() { + let (body_prefix, body_suffix) = if context.config.match_arm_blocks() { let comma = if context.config.match_block_trailing_comma() { "," } else { diff --git a/tests/source/configs-match_arm_blocks-false.rs b/tests/source/configs-match_arm_blocks-false.rs new file mode 100644 index 00000000000..53e37e13c4f --- /dev/null +++ b/tests/source/configs-match_arm_blocks-false.rs @@ -0,0 +1,11 @@ +// rustfmt-match_arm_blocks: false +// Wrap match-arms + +fn main() { + match lorem { + true => foooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo(x), + false => { + println!("{}", sit) + } + } +} diff --git a/tests/source/configs-match_arm_blocks-true.rs b/tests/source/configs-match_arm_blocks-true.rs new file mode 100644 index 00000000000..a452b13cd27 --- /dev/null +++ b/tests/source/configs-match_arm_blocks-true.rs @@ -0,0 +1,11 @@ +// rustfmt-match_arm_blocks: true +// Wrap match-arms + +fn main() { + match lorem { + true => foooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo(x), + false => { + println!("{}", sit) + } + } +} diff --git a/tests/source/configs-wrap_match_arms-false.rs b/tests/source/configs-wrap_match_arms-false.rs deleted file mode 100644 index d1c05c27fd7..00000000000 --- a/tests/source/configs-wrap_match_arms-false.rs +++ /dev/null @@ -1,11 +0,0 @@ -// rustfmt-wrap_match_arms: false -// Wrap match-arms - -fn main() { - match lorem { - true => foooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo(x), - false => { - println!("{}", sit) - } - } -} diff --git a/tests/source/configs-wrap_match_arms-true.rs b/tests/source/configs-wrap_match_arms-true.rs deleted file mode 100644 index 8ddc5ebdc2e..00000000000 --- a/tests/source/configs-wrap_match_arms-true.rs +++ /dev/null @@ -1,11 +0,0 @@ -// rustfmt-wrap_match_arms: true -// Wrap match-arms - -fn main() { - match lorem { - true => foooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo(x), - false => { - println!("{}", sit) - } - } -} diff --git a/tests/source/issue-1127.rs b/tests/source/issue-1127.rs index 4820f5ea229..9996c194818 100644 --- a/tests/source/issue-1127.rs +++ b/tests/source/issue-1127.rs @@ -1,5 +1,5 @@ // rustfmt-max_width:120 -// rustfmt-wrap_match_arms: false +// rustfmt-match_arm_blocks: false // rustfmt-match_block_trailing_comma: true fn a_very_very_very_very_very_very_very_very_very_very_very_long_function_name() -> i32 { diff --git a/tests/source/match-nowrap-trailing-comma.rs b/tests/source/match-nowrap-trailing-comma.rs index f6e88406bb4..134d2fdf9a4 100644 --- a/tests/source/match-nowrap-trailing-comma.rs +++ b/tests/source/match-nowrap-trailing-comma.rs @@ -1,4 +1,4 @@ -// rustfmt-wrap_match_arms: false +// rustfmt-match_arm_blocks: false // rustfmt-match_block_trailing_comma: true // Match expressions, no unwrapping of block arms or wrapping of multiline // expressions. diff --git a/tests/source/match-nowrap.rs b/tests/source/match-nowrap.rs index 83e0fbbd450..db22cd9f010 100644 --- a/tests/source/match-nowrap.rs +++ b/tests/source/match-nowrap.rs @@ -1,4 +1,4 @@ -// rustfmt-wrap_match_arms: false +// rustfmt-match_arm_blocks: false // Match expressions, no unwrapping of block arms or wrapping of multiline // expressions. diff --git a/tests/target/configs-control_style-rfc.rs b/tests/target/configs-control_style-rfc.rs index 5e19681f90b..6619d8b2630 100644 --- a/tests/target/configs-control_style-rfc.rs +++ b/tests/target/configs-control_style-rfc.rs @@ -26,7 +26,7 @@ fn issue1656() { match rewrite { Some(ref body_str) if (!body_str.contains('\n') && body_str.len() <= arm_shape.width) - || !context.config.wrap_match_arms() + || !context.config.match_arm_blocks() || (extend && first_line_width(body_str) <= arm_shape.width) || is_block => { diff --git a/tests/target/configs-match_arm_blocks-false.rs b/tests/target/configs-match_arm_blocks-false.rs new file mode 100644 index 00000000000..4d53a96a7b7 --- /dev/null +++ b/tests/target/configs-match_arm_blocks-false.rs @@ -0,0 +1,10 @@ +// rustfmt-match_arm_blocks: false +// Wrap match-arms + +fn main() { + match lorem { + true => + foooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo(x), + false => println!("{}", sit), + } +} diff --git a/tests/target/configs-match_arm_blocks-true.rs b/tests/target/configs-match_arm_blocks-true.rs new file mode 100644 index 00000000000..d75ef03397a --- /dev/null +++ b/tests/target/configs-match_arm_blocks-true.rs @@ -0,0 +1,11 @@ +// rustfmt-match_arm_blocks: true +// Wrap match-arms + +fn main() { + match lorem { + true => { + foooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo(x) + } + false => println!("{}", sit), + } +} diff --git a/tests/target/configs-wrap_match_arms-false.rs b/tests/target/configs-wrap_match_arms-false.rs deleted file mode 100644 index e4ca37bc6e5..00000000000 --- a/tests/target/configs-wrap_match_arms-false.rs +++ /dev/null @@ -1,10 +0,0 @@ -// rustfmt-wrap_match_arms: false -// Wrap match-arms - -fn main() { - match lorem { - true => - foooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo(x), - false => println!("{}", sit), - } -} diff --git a/tests/target/configs-wrap_match_arms-true.rs b/tests/target/configs-wrap_match_arms-true.rs deleted file mode 100644 index f6307e53e43..00000000000 --- a/tests/target/configs-wrap_match_arms-true.rs +++ /dev/null @@ -1,11 +0,0 @@ -// rustfmt-wrap_match_arms: true -// Wrap match-arms - -fn main() { - match lorem { - true => { - foooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo(x) - } - false => println!("{}", sit), - } -} diff --git a/tests/target/issue-1127.rs b/tests/target/issue-1127.rs index afc79767cb7..dbdd234b8e4 100644 --- a/tests/target/issue-1127.rs +++ b/tests/target/issue-1127.rs @@ -1,5 +1,5 @@ // rustfmt-max_width:120 -// rustfmt-wrap_match_arms: false +// rustfmt-match_arm_blocks: false // rustfmt-match_block_trailing_comma: true fn a_very_very_very_very_very_very_very_very_very_very_very_long_function_name() -> i32 { diff --git a/tests/target/match-nowrap-trailing-comma.rs b/tests/target/match-nowrap-trailing-comma.rs index 0abc358a340..19ef2144822 100644 --- a/tests/target/match-nowrap-trailing-comma.rs +++ b/tests/target/match-nowrap-trailing-comma.rs @@ -1,4 +1,4 @@ -// rustfmt-wrap_match_arms: false +// rustfmt-match_arm_blocks: false // rustfmt-match_block_trailing_comma: true // Match expressions, no unwrapping of block arms or wrapping of multiline // expressions. diff --git a/tests/target/match-nowrap.rs b/tests/target/match-nowrap.rs index 14571098218..9e674b1e2f5 100644 --- a/tests/target/match-nowrap.rs +++ b/tests/target/match-nowrap.rs @@ -1,4 +1,4 @@ -// rustfmt-wrap_match_arms: false +// rustfmt-match_arm_blocks: false // Match expressions, no unwrapping of block arms or wrapping of multiline // expressions.