]> git.lizzy.rs Git - rust.git/commitdiff
Add fallback path
authortopecongiro <seuchida@gmail.com>
Sun, 7 May 2017 04:06:54 +0000 (13:06 +0900)
committertopecongiro <seuchida@gmail.com>
Sun, 7 May 2017 04:13:44 +0000 (13:13 +0900)
src/expr.rs
tests/source/closure.rs
tests/target/closure.rs

index bb4caaa7b935485b8c1b636e6997abde5b30c282..771e3ffcbb9421c3d445a1f49673c8c0afa23618 100644 (file)
@@ -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));
+                }
             }
         }
 
index b8d998f2e5975ecc0ae2fb3f0950e2410713432a..a4395d0286af841571df8aa5e7fa16bfb425894c 100644 (file)
@@ -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)
+            })),
+        })
+    }
+}
index c94d98b3dda5d26d86d4590fce3541e7ab34cdc2..febbb0a46a253d7192e033dab8c7972db4d63b74 100644 (file)
@@ -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)
+                                                                                           })),
+             })
+    }
+}