about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorNick Cameron <nrc@ncameron.org>2017-10-04 20:14:10 +0800
committerGitHub <noreply@github.com>2017-10-04 20:14:10 +0800
commit2aa2d4ebe3aa02999558b8aa1c75cf1a0855cb34 (patch)
tree4822804d7604bdaeec95c29dba5cedc4b63e8d68 /src
parent687acdf84ed90493b9fe4f54bb315b74a5889713 (diff)
parent436a083fceae8e0f71605aa07dce047a316576c6 (diff)
Merge pull request #2011 from topecongiro/rewrite_call_inner
Change return type of rewrite_call_inner() to Option<String>
Diffstat (limited to 'src')
-rw-r--r--src/expr.rs27
-rw-r--r--src/items.rs20
-rw-r--r--src/macros.rs5
-rw-r--r--src/patterns.rs2
4 files changed, 23 insertions, 31 deletions
diff --git a/src/expr.rs b/src/expr.rs
index 9b59e0cbd78..c3fd5609458 100644
--- a/src/expr.rs
+++ b/src/expr.rs
@@ -8,7 +8,7 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
-use std::cmp::{min, Ordering};
+use std::cmp::min;
 use std::borrow::Cow;
 use std::fmt::Write;
 use std::iter::{repeat, ExactSizeIterator};
@@ -2033,7 +2033,7 @@ pub fn rewrite_call(
         shape,
         context.config.fn_call_width(),
         force_trailing_comma,
-    ).ok()
+    )
 }
 
 pub fn rewrite_call_inner<'a, T>(
@@ -2044,7 +2044,7 @@ pub fn rewrite_call_inner<'a, T>(
     shape: Shape,
     args_max_width: usize,
     force_trailing_comma: bool,
-) -> Result<String, Ordering>
+) -> Option<String>
 where
     T: Rewrite + Spanned + ToExpr + 'a,
 {
@@ -2055,22 +2055,19 @@ where
         1
     };
     let used_width = extra_offset(callee_str, shape);
-    let one_line_width = shape
-        .width
-        .checked_sub(used_width + 2 * paren_overhead)
-        .ok_or(Ordering::Greater)?;
+    let one_line_width = try_opt!(shape.width.checked_sub(used_width + 2 * paren_overhead));
 
-    let nested_shape = shape_from_fn_call_style(
+    let nested_shape = try_opt!(shape_from_fn_call_style(
         context,
         shape,
         used_width + 2 * paren_overhead,
         used_width + paren_overhead,
-    ).ok_or(Ordering::Greater)?;
+    ));
 
     let span_lo = context.codemap.span_after(span, "(");
     let args_span = mk_sp(span_lo, span.hi());
 
-    let (extendable, list_str) = rewrite_call_args(
+    let (extendable, list_str) = try_opt!(rewrite_call_args(
         context,
         args,
         args_span,
@@ -2078,7 +2075,7 @@ where
         one_line_width,
         args_max_width,
         force_trailing_comma,
-    ).ok_or(Ordering::Less)?;
+    ));
 
     if !context.use_block_indent() && need_block_indent(&list_str, nested_shape) && !extendable {
         let mut new_context = context.clone();
@@ -2094,10 +2091,8 @@ where
         );
     }
 
-    let args_shape = shape
-        .sub_width(last_line_width(callee_str))
-        .ok_or(Ordering::Less)?;
-    Ok(format!(
+    let args_shape = try_opt!(shape.sub_width(last_line_width(callee_str)));
+    Some(format!(
         "{}{}",
         callee_str,
         wrap_args_with_parens(context, &list_str, extendable, args_shape, nested_shape)
@@ -2805,7 +2800,7 @@ where
             shape,
             context.config.fn_call_width(),
             force_trailing_comma,
-        ).ok()
+        )
     } else {
         rewrite_tuple_in_visual_indent_style(context, items, span, shape)
     }
diff --git a/src/items.rs b/src/items.rs
index 8fdfdb4110c..f3cefca7175 100644
--- a/src/items.rs
+++ b/src/items.rs
@@ -1212,17 +1212,15 @@ fn format_tuple_struct(
         result.push(')');
     } else {
         // 3 = `();`
-        let body = try_opt!(
-            rewrite_call_inner(
-                context,
-                "",
-                &fields.iter().map(|field| field).collect::<Vec<_>>()[..],
-                span,
-                Shape::legacy(context.budget(last_line_width(&result) + 3), offset),
-                context.config.fn_call_width(),
-                false,
-            ).ok()
-        );
+        let body = try_opt!(rewrite_call_inner(
+            context,
+            "",
+            &fields.iter().map(|field| field).collect::<Vec<_>>()[..],
+            span,
+            Shape::legacy(context.budget(last_line_width(&result) + 3), offset),
+            context.config.fn_call_width(),
+            false,
+        ));
         result.push_str(&body);
     }
 
diff --git a/src/macros.rs b/src/macros.rs
index 5b52567087e..4eaf97dd254 100644
--- a/src/macros.rs
+++ b/src/macros.rs
@@ -202,7 +202,7 @@ pub fn rewrite_macro(
         MacroStyle::Parens => {
             // Format macro invocation as function call, forcing no trailing
             // comma because not all macros support them.
-            let rw = rewrite_call_inner(
+            rewrite_call_inner(
                 context,
                 &macro_name,
                 &arg_vec.iter().map(|e| &*e).collect::<Vec<_>>()[..],
@@ -210,8 +210,7 @@ pub fn rewrite_macro(
                 shape,
                 context.config.fn_call_width(),
                 trailing_comma,
-            );
-            rw.ok().map(|rw| match position {
+            ).map(|rw| match position {
                 MacroPosition::Item => format!("{};", rw),
                 _ => rw,
             })
diff --git a/src/patterns.rs b/src/patterns.rs
index b05889c29e9..6d289736c51 100644
--- a/src/patterns.rs
+++ b/src/patterns.rs
@@ -346,7 +346,7 @@ fn rewrite_tuple_pat(
         shape,
         shape.width,
         add_comma,
-    ).ok()
+    )
 }
 
 fn count_wildcard_suffix_len(