diff --git a/src/expr.rs b/src/expr.rs index 9b59e0cbd787..c3fd5609458a 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 +) -> Option 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 8fdfdb4110cf..f3cefca7175b 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::>()[..], - 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::>()[..], + 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 5b52567087ec..4eaf97dd254c 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, ¯o_name, &arg_vec.iter().map(|e| &*e).collect::>()[..], @@ -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 b05889c29e9a..6d289736c51e 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(