diff --git a/src/builtins/fish_indent.rs b/src/builtins/fish_indent.rs index 975104843..62b50f039 100644 --- a/src/builtins/fish_indent.rs +++ b/src/builtins/fish_indent.rs @@ -24,7 +24,7 @@ use crate::env::environment::Environment; use crate::expand::INTERNAL_SEPARATOR; #[allow(unused_imports)] -use crate::future::{IsSomeAnd, IsSorted}; +use crate::future::IsSomeAnd; use crate::future_feature_flags; use crate::global_safety::RelaxedAtomicBool; use crate::highlight::{HighlightRole, HighlightSpec, colorize, highlight_shell}; @@ -213,7 +213,7 @@ fn prettify(&mut self) -> WString { // Return the gap ranges from our ast. fn compute_gaps(&self) -> Vec { let range_compare = |r1: SourceRange, r2: SourceRange| { - (r1.start(), r1.length()).cmp(&(r2.start(), r2.length())) + (r1.start(), r1.length()) <= (r2.start(), r2.length()) }; // Collect the token ranges into a list. let mut tok_ranges = vec![]; @@ -229,7 +229,7 @@ fn compute_gaps(&self) -> Vec { tok_ranges.push(SourceRange::new(self.state.source.len(), 0)); // Our tokens should be sorted. - assert!(tok_ranges.is_sorted_by(|x, y| Some(range_compare(*x, *y)))); + assert!(tok_ranges.is_sorted_by(|x, y| range_compare(*x, *y))); // For each range, add a gap range between the previous range and this range. let mut gaps = vec![]; @@ -369,7 +369,7 @@ fn compute_multi_line_brace_statement_locations(&self) -> Vec { result.push(brace_statement.source_range().start()); } } - assert!(result.is_sorted_by(|l, r| Some(l.cmp(r)))); + assert!(result.is_sorted_by(|l, r| l <= r)); result } } @@ -587,7 +587,7 @@ fn range_contained_error(&self, r: SourceRange) -> bool { let range_is_before = |x: SourceRange, y: SourceRange| x.end().cmp(&y.start()); // FIXME: We want to have the errors sorted, but in some cases they aren't. // I suspect this is when the ast is unwinding because the source is fudged up. - if errs.is_sorted_by(|&x, &y| Some(range_is_before(x, y))) { + if errs.is_sorted_by(|&x, &y| range_is_before(x, y).is_le()) { errs.partition_point(|&range| range_is_before(range, r).is_lt()) != errs.len() } else { false diff --git a/src/future.rs b/src/future.rs index a7e61d864..674e13e29 100644 --- a/src/future.rs +++ b/src/future.rs @@ -15,23 +15,3 @@ fn is_none_or(self, f: impl FnOnce(T) -> bool) -> bool { } } } - -// TODO(MSRV): is_sorted_by was added in rust 1.82 -pub trait IsSorted { - type T; - fn is_sorted_by(&self, pred: impl Fn(&Self::T, &Self::T) -> Option) - -> bool; -} -impl IsSorted for &[T] { - type T = T; - fn is_sorted_by(&self, pred: impl Fn(&T, &T) -> Option) -> bool { - self.windows(2) - .all(|w| pred(&w[0], &w[1]).is_none_or(|order| order.is_le())) - } -} -impl IsSorted for Vec { - type T = T; - fn is_sorted_by(&self, pred: impl Fn(&T, &T) -> Option) -> bool { - IsSorted::is_sorted_by(&self.as_slice(), pred) - } -}