Simplify call to is_sorted_by()

I con no longer reproduce an error/warning for this.
This commit is contained in:
Johannes Altmanninger 2023-12-06 11:03:00 +01:00
parent 360c9043cb
commit bb16cad9dc
2 changed files with 2 additions and 14 deletions

View File

@ -172,9 +172,7 @@ impl<'source, 'ast> PrettyPrinter<'source, 'ast> {
tok_ranges.push(SourceRange::new(self.state.source.len(), 0));
// Our tokens should be sorted.
assert!(IsSorted::is_sorted_by(&tok_ranges, |x, y| Some(
range_compare(*x, *y)
)));
assert!(tok_ranges.is_sorted_by(|x, y| Some(range_compare(*x, *y))));
// For each range, add a gap range between the previous range and this range.
let mut gaps = vec![];
@ -474,9 +472,7 @@ impl<'source, 'ast> PrettyPrinterState<'source, 'ast> {
fn range_contained_error(&self, r: SourceRange) -> bool {
let errs = self.errors.as_ref().unwrap();
let range_is_before = |x: SourceRange, y: SourceRange| x.end().cmp(&y.start());
assert!(IsSorted::is_sorted_by(errs, |&x, &y| Some(
range_is_before(x, y)
)));
assert!(errs.is_sorted_by(|&x, &y| Some(range_is_before(x, y))));
errs.partition_point(|&range| range_is_before(range, r).is_lt()) != errs.len()
}

View File

@ -7,7 +7,6 @@ pub trait IsSomeAnd {
#[allow(clippy::wrong_self_convention)]
fn is_none_or(self, s: impl FnOnce(Self::Type) -> bool) -> bool;
}
impl<T> IsSomeAnd for Option<T> {
type Type = T;
fn is_some_and(self, f: impl FnOnce(T) -> bool) -> bool {
@ -30,7 +29,6 @@ pub trait IsOkAnd {
#[allow(clippy::wrong_self_convention)]
fn is_ok_and(self, s: impl FnOnce(Self::Type) -> bool) -> bool;
}
impl<T, E> IsOkAnd for Result<T, E> {
type Type = T;
type Error = E;
@ -60,9 +58,3 @@ impl<T> IsSorted for Vec<T> {
IsSorted::is_sorted_by(&self.as_slice(), pred)
}
}
impl<T> IsSorted for &Vec<T> {
type T = T;
fn is_sorted_by(&self, pred: impl Fn(&T, &T) -> Option<std::cmp::Ordering>) -> bool {
IsSorted::is_sorted_by(&self.as_slice(), pred)
}
}