]> git.lizzy.rs Git - rust.git/commitdiff
Force chains to adhere to restrictions
authorMarcus Klaas <mail@marcusklaas.nl>
Sat, 14 Nov 2015 20:59:04 +0000 (21:59 +0100)
committerMarcus Klaas <mail@marcusklaas.nl>
Fri, 20 Nov 2015 20:09:34 +0000 (21:09 +0100)
src/chains.rs
src/items.rs
tests/source/match.rs
tests/target/match.rs

index a011ad2ffefd042de0d7d1808b46a0bb2874869f..665fb5ac0739e36f3db8747218ded4aae099edec 100644 (file)
@@ -21,7 +21,7 @@
 
 use Indent;
 use rewrite::{Rewrite, RewriteContext};
-use utils::first_line_width;
+use utils::{wrap_str, first_line_width};
 use expr::rewrite_call;
 use config::BlockIndentStyle;
 
@@ -58,12 +58,8 @@ pub fn rewrite_chain(mut expr: &ast::Expr,
     } else {
         match context.config.chain_indent {
             BlockIndentStyle::Inherit => (context.block_indent, false),
-            BlockIndentStyle::Tabbed => {
-                (context.block_indent.block_indent(context.config), false)
-            }
-            BlockIndentStyle::Visual => {
-                (offset + Indent::new(context.config.tab_spaces, 0), false)
-            }
+            BlockIndentStyle::Tabbed => (context.block_indent.block_indent(context.config), false),
+            BlockIndentStyle::Visual => (offset + Indent::new(context.config.tab_spaces, 0), false),
         }
     };
 
@@ -142,10 +138,13 @@ pub fn rewrite_chain(mut expr: &ast::Expr,
         &connector[..]
     };
 
-    Some(format!("{}{}{}",
-                 parent_rewrite,
-                 first_connector,
-                 rewrites.join(&connector)))
+    wrap_str(format!("{}{}{}",
+                     parent_rewrite,
+                     first_connector,
+                     rewrites.join(&connector)),
+             context.config.max_width,
+             width,
+             offset)
 }
 
 // States whether an expression's last line exclusively consists of closing
index 4f3c82ee0abb118e6ba7c5764de9c08fea0bf9fa..19aec73f1165942fbdd4cc8509e24739c6f897a8 100644 (file)
@@ -875,12 +875,14 @@ fn format_struct_struct(&self,
                                               offset + header_str.len(),
                                               mk_sp(span.lo, body_lo)))
             }
-            None => if self.config.item_brace_style == BraceStyle::AlwaysNextLine &&
-                       !fields.is_empty() {
-                format!("\n{}{{", self.block_indent.to_string(self.config))
-            } else {
-                " {".to_owned()
-            },
+            None => {
+                if self.config.item_brace_style == BraceStyle::AlwaysNextLine &&
+                   !fields.is_empty() {
+                    format!("\n{}{{", self.block_indent.to_string(self.config))
+                } else {
+                    " {".to_owned()
+                }
+            }
         };
         result.push_str(&generics_str);
 
index 9277319295e104eed1f9fc7c96b32a218115dd8d..b4d35cb3815438863089a7b7f8b7ec88241f8f86 100644 (file)
@@ -11,7 +11,6 @@ fn foo() {
             an_expression;
             foo()
         }
-        // Perhaps this should introduce braces?
         Foo(ref bar) =>
             aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa,
         Pattern1 | Pattern2 | Pattern3 => false,
@@ -83,7 +82,11 @@ fn main() {
                                                 "scopeid"),
                                            true,
                                            true),
-    }
+    };
+
+    match  x{
+    y=>{/*Block with comment. Preserve me.*/  }
+    z=>{stmt();} }
 }
 
 fn matches() {
index b7f41c1dd6b802bb19f8ae87d347895eab274d6d..2c238ea8a685ff4214732d0471698017cf7662c5 100644 (file)
@@ -12,7 +12,6 @@ fn foo() {
             an_expression;
             foo()
         }
-        // Perhaps this should introduce braces?
         Foo(ref bar) => {
             aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
         }
@@ -93,6 +92,15 @@ fn main() {
              true,
              true)
         }
+    };
+
+    match x {
+        y => {
+            // Block with comment. Preserve me.
+        }
+        z => {
+            stmt();
+        }
     }
 }