Skip to content

Commit 3637760

Browse files
authored
Merge pull request #1969 from topecongiro/deprecate-binary-search
Remove rewrite_call_with_binary_search()
2 parents d906ea2 + b02e813 commit 3637760

File tree

2 files changed

+5
-94
lines changed

2 files changed

+5
-94
lines changed

src/expr.rs

Lines changed: 5 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ use patterns::{can_be_overflowed_pat, TuplePatField};
3232
use rewrite::{Rewrite, RewriteContext};
3333
use string::{rewrite_string, StringFormat};
3434
use types::{can_be_overflowed_type, rewrite_path, PathContext};
35-
use utils::{binary_search, colon_spaces, contains_skip, extra_offset, first_line_width,
36-
inner_attributes, last_line_extendable, last_line_width, left_most_sub_expr, mk_sp,
37-
outer_attributes, paren_overhead, ptr_vec_to_ref_vec, semicolon_for_stmt, stmt_expr,
35+
use utils::{colon_spaces, contains_skip, extra_offset, first_line_width, inner_attributes,
36+
last_line_extendable, last_line_width, left_most_sub_expr, mk_sp, outer_attributes,
37+
paren_overhead, ptr_vec_to_ref_vec, semicolon_for_stmt, stmt_expr,
3838
trimmed_last_line_width, wrap_str};
3939
use vertical::rewrite_with_alignment;
4040
use visitor::FmtVisitor;
@@ -83,13 +83,8 @@ pub fn format_expr(
8383
},
8484
ast::ExprKind::Call(ref callee, ref args) => {
8585
let inner_span = mk_sp(callee.span.hi(), expr.span.hi());
86-
rewrite_call_with_binary_search(
87-
context,
88-
&**callee,
89-
&ptr_vec_to_ref_vec(&args),
90-
inner_span,
91-
shape,
92-
)
86+
let callee_str = try_opt!(callee.rewrite(context, shape));
87+
rewrite_call(context, &callee_str, &args, inner_span, shape)
9388
}
9489
ast::ExprKind::Paren(ref subexpr) => rewrite_paren(context, subexpr, shape),
9590
ast::ExprKind::Binary(ref op, ref lhs, ref rhs) => {
@@ -2036,46 +2031,6 @@ fn string_requires_rewrite(
20362031
false
20372032
}
20382033

2039-
pub fn rewrite_call_with_binary_search<R>(
2040-
context: &RewriteContext,
2041-
callee: &R,
2042-
args: &[&ast::Expr],
2043-
span: Span,
2044-
shape: Shape,
2045-
) -> Option<String>
2046-
where
2047-
R: Rewrite,
2048-
{
2049-
let force_trailing_comma = if context.inside_macro {
2050-
span_ends_with_comma(context, span)
2051-
} else {
2052-
false
2053-
};
2054-
let closure = |callee_max_width| {
2055-
// FIXME using byte lens instead of char lens (and probably all over the
2056-
// place too)
2057-
let callee_shape = Shape {
2058-
width: callee_max_width,
2059-
..shape
2060-
};
2061-
let callee_str = callee
2062-
.rewrite(context, callee_shape)
2063-
.ok_or(Ordering::Greater)?;
2064-
2065-
rewrite_call_inner(
2066-
context,
2067-
&callee_str,
2068-
args,
2069-
span,
2070-
shape,
2071-
context.config.fn_call_width(),
2072-
force_trailing_comma,
2073-
)
2074-
};
2075-
2076-
binary_search(1, shape.width, closure)
2077-
}
2078-
20792034
pub fn rewrite_call(
20802035
context: &RewriteContext,
20812036
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, ptr};
1514
use syntax::ast::{self, Attribute, MetaItem, MetaItemKind, NestedMetaItem, NestedMetaItemKind,
@@ -439,33 +438,6 @@ impl Rewrite for String {
439438
}
440439
}
441440

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

488-
#[test]
489-
fn bin_search_test() {
490-
let closure = |i| match i {
491-
4 => Ok(()),
492-
j if j > 4 => Err(Ordering::Less),
493-
j if j < 4 => Err(Ordering::Greater),
494-
_ => unreachable!(),
495-
};
496-
497-
assert_eq!(Some(()), binary_search(1, 10, &closure));
498-
assert_eq!(None, binary_search(1, 3, &closure));
499-
assert_eq!(Some(()), binary_search(0, 44, &closure));
500-
assert_eq!(Some(()), binary_search(4, 125, &closure));
501-
assert_eq!(None, binary_search(6, 100, &closure));
502-
}
503-
504460
pub fn left_most_sub_expr(e: &ast::Expr) -> &ast::Expr {
505461
match e.node {
506462
ast::ExprKind::InPlace(ref e, _) |

0 commit comments

Comments
 (0)