From 2ee8e730a67de33bb57912d819bd617c70a7b922 Mon Sep 17 00:00:00 2001
From: topecongiro <seuchida@gmail.com>
Date: Sun, 7 May 2017 13:06:54 +0900
Subject: [PATCH] Add fallback path

---
 src/expr.rs             | 12 +++++-------
 tests/source/closure.rs | 11 +++++++++++
 tests/target/closure.rs | 11 +++++++++++
 3 files changed, 27 insertions(+), 7 deletions(-)

diff --git a/src/expr.rs b/src/expr.rs
index bb4caaa7b93..771e3ffcbb9 100644
--- a/src/expr.rs
+++ b/src/expr.rs
@@ -530,13 +530,11 @@ fn rewrite_closure(capture: ast::CaptureBy,
             // We need braces, but we might still prefer a one-liner.
             let stmt = &block.stmts[0];
             // 4 = braces and spaces.
-            let mut rewrite = stmt.rewrite(context, try_opt!(body_shape.sub_width(4)));
-
-            // Checks if rewrite succeeded and fits on a single line.
-            rewrite = and_one_line(rewrite);
-
-            if let Some(rewrite) = rewrite {
-                return Some(format!("{} {{ {} }}", prefix, rewrite));
+            if let Some(body_shape) = body_shape.sub_width(4) {
+                // Checks if rewrite succeeded and fits on a single line.
+                if let Some(rewrite) = and_one_line(stmt.rewrite(context, body_shape)) {
+                    return Some(format!("{} {{ {} }}", prefix, rewrite));
+                }
             }
         }
 
diff --git a/tests/source/closure.rs b/tests/source/closure.rs
index b8d998f2e59..a4395d0286a 100644
--- a/tests/source/closure.rs
+++ b/tests/source/closure.rs
@@ -120,3 +120,14 @@ fn issue470() {
             });
     }}}
 }
+
+// #1509
+impl Foo {
+    pub fn bar(&self) {
+        Some(SomeType {
+            push_closure_out_to_100_chars: iter(otherwise_it_works_ok.into_iter().map(|f| {
+                Ok(f)
+            })),
+        })
+    }
+}
diff --git a/tests/target/closure.rs b/tests/target/closure.rs
index c94d98b3dda..febbb0a46a2 100644
--- a/tests/target/closure.rs
+++ b/tests/target/closure.rs
@@ -139,3 +139,14 @@ fn issue470() {
         }
     }
 }
+
+// #1509
+impl Foo {
+    pub fn bar(&self) {
+        Some(SomeType {
+                 push_closure_out_to_100_chars: iter(otherwise_it_works_ok.into_iter().map(|f| {
+                                                                                               Ok(f)
+                                                                                           })),
+             })
+    }
+}