diff --git a/src/expr.rs b/src/expr.rs index e48b534da18..590360f0dbe 100644 --- a/src/expr.rs +++ b/src/expr.rs @@ -32,9 +32,9 @@ use patterns::{can_be_overflowed_pat, TuplePatField}; use rewrite::{Rewrite, RewriteContext}; use string::{rewrite_string, StringFormat}; use types::{can_be_overflowed_type, rewrite_path, PathContext}; -use utils::{binary_search, colon_spaces, contains_skip, extra_offset, first_line_width, - inner_attributes, last_line_extendable, last_line_width, left_most_sub_expr, mk_sp, - outer_attributes, paren_overhead, ptr_vec_to_ref_vec, semicolon_for_stmt, stmt_expr, +use utils::{colon_spaces, contains_skip, extra_offset, first_line_width, inner_attributes, + last_line_extendable, last_line_width, left_most_sub_expr, mk_sp, outer_attributes, + paren_overhead, ptr_vec_to_ref_vec, semicolon_for_stmt, stmt_expr, trimmed_last_line_width, wrap_str}; use vertical::rewrite_with_alignment; use visitor::FmtVisitor; @@ -83,13 +83,8 @@ pub fn format_expr( }, ast::ExprKind::Call(ref callee, ref args) => { let inner_span = mk_sp(callee.span.hi(), expr.span.hi()); - rewrite_call_with_binary_search( - context, - &**callee, - &ptr_vec_to_ref_vec(&args), - inner_span, - shape, - ) + let callee_str = try_opt!(callee.rewrite(context, shape)); + rewrite_call(context, &callee_str, &args, inner_span, shape) } ast::ExprKind::Paren(ref subexpr) => rewrite_paren(context, subexpr, shape), ast::ExprKind::Binary(ref op, ref lhs, ref rhs) => { @@ -2036,46 +2031,6 @@ fn string_requires_rewrite( false } -pub fn rewrite_call_with_binary_search( - context: &RewriteContext, - callee: &R, - args: &[&ast::Expr], - span: Span, - shape: Shape, -) -> Option -where - R: Rewrite, -{ - let force_trailing_comma = if context.inside_macro { - span_ends_with_comma(context, span) - } else { - false - }; - let closure = |callee_max_width| { - // FIXME using byte lens instead of char lens (and probably all over the - // place too) - let callee_shape = Shape { - width: callee_max_width, - ..shape - }; - let callee_str = callee - .rewrite(context, callee_shape) - .ok_or(Ordering::Greater)?; - - rewrite_call_inner( - context, - &callee_str, - args, - span, - shape, - context.config.fn_call_width(), - force_trailing_comma, - ) - }; - - binary_search(1, shape.width, closure) -} - pub fn rewrite_call( context: &RewriteContext, callee: &str, diff --git a/src/utils.rs b/src/utils.rs index c0795403a0c..3a53d6c48fc 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -9,7 +9,6 @@ // except according to those terms. use std::borrow::Cow; -use std::cmp::Ordering; use syntax::{abi, ptr}; use syntax::ast::{self, Attribute, MetaItem, MetaItemKind, NestedMetaItem, NestedMetaItemKind, @@ -439,33 +438,6 @@ impl Rewrite for String { } } -// Binary search in integer range. Returns the first Ok value returned by the -// callback. -// The callback takes an integer and returns either an Ok, or an Err indicating -// whether the `guess' was too high (Ordering::Less), or too low. -// This function is guaranteed to try to the hi value first. -pub fn binary_search(mut lo: usize, mut hi: usize, callback: C) -> Option -where - C: Fn(usize) -> Result, -{ - let mut middle = hi; - - while lo <= hi { - match callback(middle) { - Ok(val) => return Some(val), - Err(Ordering::Less) => { - hi = middle - 1; - } - Err(..) => { - lo = middle + 1; - } - } - middle = (hi + lo) / 2; - } - - None -} - #[inline] pub fn colon_spaces(before: bool, after: bool) -> &'static str { match (before, after) { @@ -485,22 +457,6 @@ pub fn paren_overhead(context: &RewriteContext) -> usize { } } -#[test] -fn bin_search_test() { - let closure = |i| match i { - 4 => Ok(()), - j if j > 4 => Err(Ordering::Less), - j if j < 4 => Err(Ordering::Greater), - _ => unreachable!(), - }; - - assert_eq!(Some(()), binary_search(1, 10, &closure)); - assert_eq!(None, binary_search(1, 3, &closure)); - assert_eq!(Some(()), binary_search(0, 44, &closure)); - assert_eq!(Some(()), binary_search(4, 125, &closure)); - assert_eq!(None, binary_search(6, 100, &closure)); -} - pub fn left_most_sub_expr(e: &ast::Expr) -> &ast::Expr { match e.node { ast::ExprKind::InPlace(ref e, _) |