Skip to content

Commit eda3e16

Browse files
committed
Remove rewrite_call_with_binary_search()
1 parent 7e309a4 commit eda3e16

File tree

2 files changed

+5
-95
lines changed

2 files changed

+5
-95
lines changed

src/expr.rs

Lines changed: 5 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,9 @@ use patterns::{can_be_overflowed_pat, TuplePatField};
3131
use rewrite::{Rewrite, RewriteContext};
3232
use string::{rewrite_string, StringFormat};
3333
use types::{can_be_overflowed_type, rewrite_path, PathContext};
34-
use utils::{binary_search, colon_spaces, contains_skip, extra_offset, first_line_width,
35-
inner_attributes, last_line_extendable, last_line_width, left_most_sub_expr, mk_sp,
36-
outer_attributes, paren_overhead, semicolon_for_stmt, stmt_expr,
37-
trimmed_last_line_width, wrap_str};
34+
use utils::{colon_spaces, contains_skip, extra_offset, first_line_width, inner_attributes,
35+
last_line_extendable, last_line_width, left_most_sub_expr, mk_sp, outer_attributes,
36+
paren_overhead, semicolon_for_stmt, stmt_expr, trimmed_last_line_width, wrap_str};
3837
use vertical::rewrite_with_alignment;
3938
use visitor::FmtVisitor;
4039

@@ -82,13 +81,8 @@ pub fn format_expr(
8281
},
8382
ast::ExprKind::Call(ref callee, ref args) => {
8483
let inner_span = mk_sp(callee.span.hi(), expr.span.hi());
85-
rewrite_call_with_binary_search(
86-
context,
87-
&**callee,
88-
&args.iter().map(|x| &**x).collect::<Vec<_>>()[..],
89-
inner_span,
90-
shape,
91-
)
84+
let callee_str = try_opt!(callee.rewrite(context, shape));
85+
rewrite_call(context, &callee_str, &args, inner_span, shape)
9286
}
9387
ast::ExprKind::Paren(ref subexpr) => rewrite_paren(context, subexpr, shape),
9488
ast::ExprKind::Binary(ref op, ref lhs, ref rhs) => {
@@ -1982,46 +1976,6 @@ fn string_requires_rewrite(
19821976
false
19831977
}
19841978

1985-
pub fn rewrite_call_with_binary_search<R>(
1986-
context: &RewriteContext,
1987-
callee: &R,
1988-
args: &[&ast::Expr],
1989-
span: Span,
1990-
shape: Shape,
1991-
) -> Option<String>
1992-
where
1993-
R: Rewrite,
1994-
{
1995-
let force_trailing_comma = if context.inside_macro {
1996-
span_ends_with_comma(context, span)
1997-
} else {
1998-
false
1999-
};
2000-
let closure = |callee_max_width| {
2001-
// FIXME using byte lens instead of char lens (and probably all over the
2002-
// place too)
2003-
let callee_shape = Shape {
2004-
width: callee_max_width,
2005-
..shape
2006-
};
2007-
let callee_str = callee
2008-
.rewrite(context, callee_shape)
2009-
.ok_or(Ordering::Greater)?;
2010-
2011-
rewrite_call_inner(
2012-
context,
2013-
&callee_str,
2014-
args,
2015-
span,
2016-
shape,
2017-
context.config.fn_call_width(),
2018-
force_trailing_comma,
2019-
)
2020-
};
2021-
2022-
binary_search(1, shape.width, closure)
2023-
}
2024-
20251979
pub fn rewrite_call(
20261980
context: &RewriteContext,
20271981
callee: &str,

src/utils.rs

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
// except according to those terms.
1010

1111
use std::borrow::Cow;
12-
use std::cmp::Ordering;
1312

1413
use syntax::abi;
1514
use syntax::ast::{self, Attribute, MetaItem, MetaItemKind, NestedMetaItem, NestedMetaItemKind,
@@ -433,33 +432,6 @@ impl Rewrite for String {
433432
}
434433
}
435434

436-
// Binary search in integer range. Returns the first Ok value returned by the
437-
// callback.
438-
// The callback takes an integer and returns either an Ok, or an Err indicating
439-
// whether the `guess' was too high (Ordering::Less), or too low.
440-
// This function is guaranteed to try to the hi value first.
441-
pub fn binary_search<C, T>(mut lo: usize, mut hi: usize, callback: C) -> Option<T>
442-
where
443-
C: Fn(usize) -> Result<T, Ordering>,
444-
{
445-
let mut middle = hi;
446-
447-
while lo <= hi {
448-
match callback(middle) {
449-
Ok(val) => return Some(val),
450-
Err(Ordering::Less) => {
451-
hi = middle - 1;
452-
}
453-
Err(..) => {
454-
lo = middle + 1;
455-
}
456-
}
457-
middle = (hi + lo) / 2;
458-
}
459-
460-
None
461-
}
462-
463435
#[inline]
464436
pub fn colon_spaces(before: bool, after: bool) -> &'static str {
465437
match (before, after) {
@@ -479,22 +451,6 @@ pub fn paren_overhead(context: &RewriteContext) -> usize {
479451
}
480452
}
481453

482-
#[test]
483-
fn bin_search_test() {
484-
let closure = |i| match i {
485-
4 => Ok(()),
486-
j if j > 4 => Err(Ordering::Less),
487-
j if j < 4 => Err(Ordering::Greater),
488-
_ => unreachable!(),
489-
};
490-
491-
assert_eq!(Some(()), binary_search(1, 10, &closure));
492-
assert_eq!(None, binary_search(1, 3, &closure));
493-
assert_eq!(Some(()), binary_search(0, 44, &closure));
494-
assert_eq!(Some(()), binary_search(4, 125, &closure));
495-
assert_eq!(None, binary_search(6, 100, &closure));
496-
}
497-
498454
pub fn left_most_sub_expr(e: &ast::Expr) -> &ast::Expr {
499455
match e.node {
500456
ast::ExprKind::InPlace(ref e, _) |

0 commit comments

Comments
 (0)