]> git.lizzy.rs Git - rust.git/commitdiff
Merge multiline_closure_forces_block and multiline_match_arm_forces_block into force_...
authorNick Cameron <ncameron@mozilla.com>
Mon, 27 Nov 2017 04:01:49 +0000 (17:01 +1300)
committerNick Cameron <ncameron@mozilla.com>
Mon, 27 Nov 2017 04:03:54 +0000 (17:03 +1300)
16 files changed:
Configurations.md
src/closures.rs
src/config.rs
src/expr.rs
tests/source/configs-force_multiline_block-false.rs [new file with mode: 0644]
tests/source/configs-force_multiline_block-true.rs [new file with mode: 0644]
tests/source/configs-multiline_closure_forces_block-false.rs [deleted file]
tests/source/configs-multiline_closure_forces_block-true.rs [deleted file]
tests/source/configs-multiline_match_arm_forces_block-false.rs [deleted file]
tests/source/configs-multiline_match_arm_forces_block-true.rs [deleted file]
tests/target/configs-force_multiline_block-false.rs [new file with mode: 0644]
tests/target/configs-force_multiline_block-true.rs [new file with mode: 0644]
tests/target/configs-multiline_closure_forces_block-false.rs [deleted file]
tests/target/configs-multiline_closure_forces_block-true.rs [deleted file]
tests/target/configs-multiline_match_arm_forces_block-false.rs [deleted file]
tests/target/configs-multiline_match_arm_forces_block-true.rs [deleted file]

index ee4851eb2e5b2313aceec2c4c9b0f8b4e602b069..76589314e03c3d56a34af599688b8be63204b1b6 100644 (file)
@@ -1172,9 +1172,9 @@ pub enum Foo {}
 pub enum Foo {}
 ```
 
-## `multiline_closure_forces_block`
+## `force_multiline_blocks`
 
-Force multiline closure bodies to be wrapped in a block
+Force multiline closure and match arm bodies to be wrapped in a block
 
 - **Default value**: `false`
 - **Possible values**: `false`, `true`
@@ -1186,6 +1186,13 @@ result.and_then(|maybe_value| match maybe_value {
     None => ...,
     Some(value) => ...,
 })
+
+match lorem {
+    None => if ipsum {
+        println!("Hello World");
+    },
+    Some(dolor) => ...,
+}
 ```
 
 #### `true`:
@@ -1198,29 +1205,7 @@ result.and_then(|maybe_value| {
         Some(value) => ...,
     }
 })
-```
-
-## `multiline_match_arm_forces_block`
-
-Force multiline match arm bodies to be wrapped in a block
-
-- **Default value**: `false`
-- **Possible values**: `false`, `true`
-
-#### `false` (default):
-
-```rust
-match lorem {
-    None => if ipsum {
-        println!("Hello World");
-    },
-    Some(dolor) => ...,
-}
-```
 
-#### `true`:
-
-```rust
 match lorem {
     None => {
         if ipsum {
@@ -1231,6 +1216,7 @@ match lorem {
 }
 ```
 
+
 ## `newline_style`
 
 Unix or Windows line endings
index ebc12382bd75b4fd16c685e6b69a1535e0a3063b..71862b82ba05d11f04906437fa1cd7ccde3b47bf 100644 (file)
@@ -146,7 +146,7 @@ fn rewrite_closure_expr(
         rewrite = and_one_line(rewrite);
     }
     rewrite = rewrite.and_then(|rw| {
-        if context.config.multiline_closure_forces_block() && rw.contains('\n') {
+        if context.config.force_multiline_blocks() && rw.contains('\n') {
             None
         } else {
             Some(rw)
index fe18f02d33e9bb431a72aed21e8e5784e55019fd..c622522223102f277c7aa0fc8f71795467f6adc3 100644 (file)
@@ -621,8 +621,6 @@ pub fn get_toml_path(dir: &Path) -> Result<Option<PathBuf>, Error> {
     // 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";
-    multiline_match_arm_forces_block: bool, false, false,
-        "Force multiline match arm bodies to be wrapped in a block";
     match_block_trailing_comma: bool, false, false,
         "Put a trailing comma after a block based match arm (non-block arms are not affected)";
 
@@ -645,8 +643,8 @@ pub fn get_toml_path(dir: &Path) -> Result<Option<PathBuf>, 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.";
-    multiline_closure_forces_block: bool, false, false,
-        "Force multiline closure bodies to be wrapped in a block";
+    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";
     brace_style: BraceStyle, BraceStyle::SameLineWhere, false, "Brace style for items";
     control_brace_style: ControlBraceStyle, ControlBraceStyle::AlwaysSameLine, false,
index 14913fef9e7a2fc1d120a60df564ef63e1e06e41..9d29425a5ddc7fd914dab963b9a51c88b1dfa947 100644 (file)
@@ -1499,8 +1499,7 @@ fn flatten_arm_body<'a>(context: &'a RewriteContext, body: &'a ast::Expr) -> (bo
         {
             if let ast::StmtKind::Expr(ref expr) = block.stmts[0].node {
                 (
-                    !context.config.multiline_match_arm_forces_block()
-                        && expr.can_be_overflowed(context, 1),
+                    !context.config.force_multiline_blocks() && expr.can_be_overflowed(context, 1),
                     &**expr,
                 )
             } else {
@@ -1508,8 +1507,7 @@ fn flatten_arm_body<'a>(context: &'a RewriteContext, body: &'a ast::Expr) -> (bo
             }
         }
         _ => (
-            !context.config.multiline_match_arm_forces_block()
-                && body.can_be_overflowed(context, 1),
+            !context.config.force_multiline_blocks() && body.can_be_overflowed(context, 1),
             &*body,
         ),
     }
diff --git a/tests/source/configs-force_multiline_block-false.rs b/tests/source/configs-force_multiline_block-false.rs
new file mode 100644 (file)
index 0000000..b97e348
--- /dev/null
@@ -0,0 +1,22 @@
+// rustfmt-force_multiline_blocks: false
+// Option forces multiline match arm and closure bodies to be wrapped in a block
+
+fn main() {
+    match lorem {
+        Lorem::Ipsum => {
+            if ipsum {
+                println!("dolor");
+            }
+        }
+        Lorem::Dolor => println!("amet"),
+    }
+}
+
+fn main() {
+    result.and_then(|maybe_value| {
+        match maybe_value {
+            None => Err("oops"),
+            Some(value) => Ok(1),
+        }
+    });
+}
diff --git a/tests/source/configs-force_multiline_block-true.rs b/tests/source/configs-force_multiline_block-true.rs
new file mode 100644 (file)
index 0000000..db9d3de
--- /dev/null
@@ -0,0 +1,18 @@
+// rustfmt-force_multiline_blocks: true
+// Option forces multiline match arm and closure bodies to be wrapped in a block
+
+fn main() {
+    match lorem {
+        Lorem::Ipsum => if ipsum {
+            println!("dolor");
+        },
+        Lorem::Dolor => println!("amet"),
+    }
+}
+
+fn main() {
+    result.and_then(|maybe_value| match maybe_value {
+        None => Err("oops"),
+        Some(value) => Ok(1),
+    });
+}
diff --git a/tests/source/configs-multiline_closure_forces_block-false.rs b/tests/source/configs-multiline_closure_forces_block-false.rs
deleted file mode 100644 (file)
index e885dff..0000000
+++ /dev/null
@@ -1,11 +0,0 @@
-// rustfmt-multiline_closure_forces_block: false
-// Option forces multiline closure bodies to be wrapped in a block
-
-fn main() {
-    result.and_then(|maybe_value| {
-        match maybe_value {
-            None => Err("oops"),
-            Some(value) => Ok(1),
-        }
-    });
-}
diff --git a/tests/source/configs-multiline_closure_forces_block-true.rs b/tests/source/configs-multiline_closure_forces_block-true.rs
deleted file mode 100644 (file)
index f267466..0000000
+++ /dev/null
@@ -1,9 +0,0 @@
-// rustfmt-multiline_closure_forces_block: true
-// Option forces multiline closure bodies to be wrapped in a block
-
-fn main() {
-    result.and_then(|maybe_value| match maybe_value {
-        None => Err("oops"),
-        Some(value) => Ok(1),
-    });
-}
diff --git a/tests/source/configs-multiline_match_arm_forces_block-false.rs b/tests/source/configs-multiline_match_arm_forces_block-false.rs
deleted file mode 100644 (file)
index 4cbec0c..0000000
+++ /dev/null
@@ -1,13 +0,0 @@
-// rustfmt-multiline_match_arm_forces_block: false
-// Option forces multiline match arm bodies to be wrapped in a block
-
-fn main() {
-    match lorem {
-        Lorem::Ipsum => {
-            if ipsum {
-                println!("dolor");
-            }
-        }
-        Lorem::Dolor => println!("amet"),
-    }
-}
diff --git a/tests/source/configs-multiline_match_arm_forces_block-true.rs b/tests/source/configs-multiline_match_arm_forces_block-true.rs
deleted file mode 100644 (file)
index 602076a..0000000
+++ /dev/null
@@ -1,11 +0,0 @@
-// rustfmt-multiline_match_arm_forces_block: true
-// Option forces multiline match arm bodies to be wrapped in a block
-
-fn main() {
-    match lorem {
-        Lorem::Ipsum => if ipsum {
-            println!("dolor");
-        },
-        Lorem::Dolor => println!("amet"),
-    }
-}
diff --git a/tests/target/configs-force_multiline_block-false.rs b/tests/target/configs-force_multiline_block-false.rs
new file mode 100644 (file)
index 0000000..11ccc9a
--- /dev/null
@@ -0,0 +1,18 @@
+// rustfmt-force_multiline_blocks: false
+// Option forces multiline match arm and closure bodies to be wrapped in a block
+
+fn main() {
+    match lorem {
+        Lorem::Ipsum => if ipsum {
+            println!("dolor");
+        },
+        Lorem::Dolor => println!("amet"),
+    }
+}
+
+fn main() {
+    result.and_then(|maybe_value| match maybe_value {
+        None => Err("oops"),
+        Some(value) => Ok(1),
+    });
+}
diff --git a/tests/target/configs-force_multiline_block-true.rs b/tests/target/configs-force_multiline_block-true.rs
new file mode 100644 (file)
index 0000000..aec50af
--- /dev/null
@@ -0,0 +1,22 @@
+// rustfmt-force_multiline_blocks: true
+// Option forces multiline match arm and closure bodies to be wrapped in a block
+
+fn main() {
+    match lorem {
+        Lorem::Ipsum => {
+            if ipsum {
+                println!("dolor");
+            }
+        }
+        Lorem::Dolor => println!("amet"),
+    }
+}
+
+fn main() {
+    result.and_then(|maybe_value| {
+        match maybe_value {
+            None => Err("oops"),
+            Some(value) => Ok(1),
+        }
+    });
+}
diff --git a/tests/target/configs-multiline_closure_forces_block-false.rs b/tests/target/configs-multiline_closure_forces_block-false.rs
deleted file mode 100644 (file)
index 7fb3d59..0000000
+++ /dev/null
@@ -1,9 +0,0 @@
-// rustfmt-multiline_closure_forces_block: false
-// Option forces multiline closure bodies to be wrapped in a block
-
-fn main() {
-    result.and_then(|maybe_value| match maybe_value {
-        None => Err("oops"),
-        Some(value) => Ok(1),
-    });
-}
diff --git a/tests/target/configs-multiline_closure_forces_block-true.rs b/tests/target/configs-multiline_closure_forces_block-true.rs
deleted file mode 100644 (file)
index 01e2de4..0000000
+++ /dev/null
@@ -1,11 +0,0 @@
-// rustfmt-multiline_closure_forces_block: true
-// Option forces multiline closure bodies to be wrapped in a block
-
-fn main() {
-    result.and_then(|maybe_value| {
-        match maybe_value {
-            None => Err("oops"),
-            Some(value) => Ok(1),
-        }
-    });
-}
diff --git a/tests/target/configs-multiline_match_arm_forces_block-false.rs b/tests/target/configs-multiline_match_arm_forces_block-false.rs
deleted file mode 100644 (file)
index 3c4c147..0000000
+++ /dev/null
@@ -1,11 +0,0 @@
-// rustfmt-multiline_match_arm_forces_block: false
-// Option forces multiline match arm bodies to be wrapped in a block
-
-fn main() {
-    match lorem {
-        Lorem::Ipsum => if ipsum {
-            println!("dolor");
-        },
-        Lorem::Dolor => println!("amet"),
-    }
-}
diff --git a/tests/target/configs-multiline_match_arm_forces_block-true.rs b/tests/target/configs-multiline_match_arm_forces_block-true.rs
deleted file mode 100644 (file)
index c36d59c..0000000
+++ /dev/null
@@ -1,13 +0,0 @@
-// rustfmt-multiline_match_arm_forces_block: true
-// Option forces multiline match arm bodies to be wrapped in a block
-
-fn main() {
-    match lorem {
-        Lorem::Ipsum => {
-            if ipsum {
-                println!("dolor");
-            }
-        }
-        Lorem::Dolor => println!("amet"),
-    }
-}