diff options
| author | topecongiro <seuchida@gmail.com> | 2017-04-17 22:57:07 +0900 |
|---|---|---|
| committer | topecongiro <seuchida@gmail.com> | 2017-04-17 23:17:17 +0900 |
| commit | 02c9ac93be959272ffbb3fbbec79dbe9fc734140 (patch) | |
| tree | 1440ea1e34cee68707690fb096e970b19a14580b /src/expr.rs | |
| parent | 8dc53d3750e3b683673b09785b2787543af19bb8 (diff) | |
Prohibit long return val from 'rewrite_closure_block'
Diffstat (limited to 'src/expr.rs')
| -rw-r--r-- | src/expr.rs | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/src/expr.rs b/src/expr.rs index a8223fbc400..f282f7c0b57 100644 --- a/src/expr.rs +++ b/src/expr.rs @@ -172,9 +172,8 @@ fn format_expr(expr: &ast::Expr, ast::ExprKind::Mac(ref mac) => { // Failure to rewrite a marco should not imply failure to // rewrite the expression. - rewrite_macro(mac, None, context, shape, MacroPosition::Expression).or_else(|| { - wrap_str(context.snippet(expr.span), context.config.max_width, shape) - }) + rewrite_macro(mac, None, context, shape, MacroPosition::Expression) + .or_else(|| wrap_str(context.snippet(expr.span), context.config.max_width, shape)) } ast::ExprKind::Ret(None) => wrap_str("return".to_owned(), context.config.max_width, shape), ast::ExprKind::Ret(Some(ref expr)) => { @@ -576,14 +575,18 @@ fn rewrite_closure(capture: ast::CaptureBy, let block_threshold = context.config.closure_block_indent_threshold; if block_threshold < 0 || rewrite.matches('\n').count() <= block_threshold as usize { - return Some(format!("{} {}", prefix, rewrite)); + if let Some(rewrite) = wrap_str(rewrite, context.config.max_width, shape) { + return Some(format!("{} {}", prefix, rewrite)); + } } // The body of the closure is big enough to be block indented, that // means we must re-format. let block_shape = shape.block(); let rewrite = try_opt!(block.rewrite(&context, block_shape)); - Some(format!("{} {}", prefix, rewrite)) + Some(format!("{} {}", + prefix, + try_opt!(wrap_str(rewrite, block_shape.width, block_shape)))) } } |
