about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authortopecongiro <seuchida@gmail.com>2017-04-17 22:57:07 +0900
committertopecongiro <seuchida@gmail.com>2017-04-17 23:17:17 +0900
commit02c9ac93be959272ffbb3fbbec79dbe9fc734140 (patch)
tree1440ea1e34cee68707690fb096e970b19a14580b /src
parent8dc53d3750e3b683673b09785b2787543af19bb8 (diff)
Prohibit long return val from 'rewrite_closure_block'
Diffstat (limited to 'src')
-rw-r--r--src/expr.rs13
-rw-r--r--src/file_lines.rs5
-rw-r--r--src/items.rs13
-rw-r--r--src/macros.rs11
4 files changed, 22 insertions, 20 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))))
     }
 }
 
diff --git a/src/file_lines.rs b/src/file_lines.rs
index e68751eb887..f11a0aaf6e2 100644
--- a/src/file_lines.rs
+++ b/src/file_lines.rs
@@ -194,9 +194,8 @@ impl JsonSpan {
     // To allow `collect()`ing into a `MultiMap`.
     fn into_tuple(self) -> Result<(String, Range), String> {
         let (lo, hi) = self.range;
-        let canonical = try!(canonicalize_path_string(&self.file).map_err(|_| {
-            format!("Can't canonicalize {}", &self.file)
-        }));
+        let canonical = try!(canonicalize_path_string(&self.file)
+                                 .map_err(|_| format!("Can't canonicalize {}", &self.file)));
         Ok((canonical, Range::new(lo, hi)))
     }
 }
diff --git a/src/items.rs b/src/items.rs
index 2cb4e46ecb5..1909b0d2679 100644
--- a/src/items.rs
+++ b/src/items.rs
@@ -1326,12 +1326,13 @@ pub fn rewrite_associated_type(ident: ast::Ident,
 
     let type_bounds_str = if let Some(ty_param_bounds) = ty_param_bounds_opt {
         let bounds: &[_] = ty_param_bounds;
-        let bound_str = try_opt!(bounds.iter()
-            .map(|ty_bound| {
-                ty_bound.rewrite(context, Shape::legacy(context.config.max_width, indent))
-            })
-            .intersperse(Some(" + ".to_string()))
-            .collect::<Option<String>>());
+        let bound_str = try_opt!(bounds
+                                     .iter()
+                                     .map(|ty_bound| {
+            ty_bound.rewrite(context, Shape::legacy(context.config.max_width, indent))
+        })
+                                     .intersperse(Some(" + ".to_string()))
+                                     .collect::<Option<String>>());
         if bounds.len() > 0 {
             format!(": {}", bound_str)
         } else {
diff --git a/src/macros.rs b/src/macros.rs
index fd5578e7f00..0bdc7eb60e0 100644
--- a/src/macros.rs
+++ b/src/macros.rs
@@ -146,12 +146,11 @@ pub fn rewrite_macro(mac: &ast::Mac,
         MacroStyle::Parens => {
             // Format macro invocation as function call, forcing no trailing
             // comma because not all macros support them.
-            rewrite_call(context, &macro_name, &expr_vec, mac.span, shape, true).map(|rw| {
-                match position {
-                    MacroPosition::Item => format!("{};", rw),
-                    _ => rw,
-                }
-            })
+            rewrite_call(context, &macro_name, &expr_vec, mac.span, shape, true)
+                .map(|rw| match position {
+                         MacroPosition::Item => format!("{};", rw),
+                         _ => rw,
+                     })
         }
         MacroStyle::Brackets => {
             // Format macro invocation as array literal.