about summary refs log tree commit diff
path: root/src/expr.rs
diff options
context:
space:
mode:
authortopecongiro <seuchida@gmail.com>2017-05-04 00:21:51 +0900
committertopecongiro <seuchida@gmail.com>2017-05-04 00:21:51 +0900
commit58d957be3fd559787b7f489ee5f1089ce9a87f30 (patch)
tree92cb093963db8bd1c76c7bcd39fd18f7c236bfb3 /src/expr.rs
parent6d14ac84a40a4eae077a691de4baae885f97ea1c (diff)
Check format failures explicitly in visit_block
Diffstat (limited to 'src/expr.rs')
-rw-r--r--src/expr.rs24
1 files changed, 6 insertions, 18 deletions
diff --git a/src/expr.rs b/src/expr.rs
index 75a7ff21abe..5876409a9fa 100644
--- a/src/expr.rs
+++ b/src/expr.rs
@@ -570,19 +570,6 @@ fn rewrite_closure(capture: ast::CaptureBy,
         rewrite.map(|rw| format!("{} {}", prefix, rw))
     }
 
-    fn no_weird_visual_indent(block_str: &str, context: &RewriteContext) -> bool {
-        let mut prev_indent_width = 0;
-        for line in block_str.lines() {
-            let cur_indent_width = line.find(|c: char| !c.is_whitespace()).unwrap_or(0);
-            if prev_indent_width > cur_indent_width + context.config.tab_spaces &&
-               line.find('}').unwrap_or(0) != cur_indent_width {
-                return false;
-            }
-            prev_indent_width = cur_indent_width;
-        }
-        true
-    }
-
     fn rewrite_closure_block(block: &ast::Block,
                              prefix: String,
                              context: &RewriteContext,
@@ -592,9 +579,7 @@ fn rewrite_closure(capture: ast::CaptureBy,
         // closure is large.
         if let Some(block_str) = block.rewrite(&context, shape) {
             let block_threshold = context.config.closure_block_indent_threshold;
-            if (block_threshold < 0 ||
-                block_str.matches('\n').count() <= block_threshold as usize) &&
-               no_weird_visual_indent(&block_str, context) {
+            if block_threshold < 0 || block_str.matches('\n').count() <= block_threshold as usize {
                 if let Some(block_str) = block_str.rewrite(context, shape) {
                     return Some(format!("{} {}", prefix, block_str));
                 }
@@ -697,8 +682,11 @@ impl Rewrite for ast::Block {
         };
 
         visitor.visit_block(self);
-
-        Some(format!("{}{}", prefix, visitor.buffer))
+        if visitor.failed {
+            None
+        } else {
+            Some(format!("{}{}", prefix, visitor.buffer))
+        }
     }
 }