Merge pull request #1511 from topecongiro/bug/closure-fallback

Add fallback path inside rewrite_closure
This commit is contained in:
Nick Cameron 2017-05-08 10:30:50 +12:00 committed by GitHub
commit e5f8a725db
3 changed files with 27 additions and 7 deletions

View 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));
}
}
}

View 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)
})),
})
}
}

View 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)
})),
})
}
}