Rollup merge of #102977 - lukas-code:is-sorted-hrtb, r=m-ou-se
remove HRTB from `[T]::is_sorted_by{,_key}` Changes the signature of `[T]::is_sorted_by{,_key}` to match `[T]::binary_search_by{,_key}` and make code like https://github.com/rust-lang/rust/issues/53485#issuecomment-885393452 compile. Tracking issue: https://github.com/rust-lang/rust/issues/53485 ~~Do we need an ACP for something like this?~~ Edit: Filed ACP here: https://github.com/rust-lang/libs-team/issues/121
This commit is contained in:
commit
8aca6ccedd
2 changed files with 24 additions and 4 deletions
|
@ -3752,9 +3752,9 @@ impl<T> [T] {
|
||||||
/// [`is_sorted`]: slice::is_sorted
|
/// [`is_sorted`]: slice::is_sorted
|
||||||
#[unstable(feature = "is_sorted", reason = "new API", issue = "53485")]
|
#[unstable(feature = "is_sorted", reason = "new API", issue = "53485")]
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn is_sorted_by<F>(&self, mut compare: F) -> bool
|
pub fn is_sorted_by<'a, F>(&'a self, mut compare: F) -> bool
|
||||||
where
|
where
|
||||||
F: FnMut(&T, &T) -> Option<Ordering>,
|
F: FnMut(&'a T, &'a T) -> Option<Ordering>,
|
||||||
{
|
{
|
||||||
self.iter().is_sorted_by(|a, b| compare(*a, *b))
|
self.iter().is_sorted_by(|a, b| compare(*a, *b))
|
||||||
}
|
}
|
||||||
|
@ -3778,9 +3778,9 @@ impl<T> [T] {
|
||||||
#[inline]
|
#[inline]
|
||||||
#[unstable(feature = "is_sorted", reason = "new API", issue = "53485")]
|
#[unstable(feature = "is_sorted", reason = "new API", issue = "53485")]
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn is_sorted_by_key<F, K>(&self, f: F) -> bool
|
pub fn is_sorted_by_key<'a, F, K>(&'a self, f: F) -> bool
|
||||||
where
|
where
|
||||||
F: FnMut(&T) -> K,
|
F: FnMut(&'a T) -> K,
|
||||||
K: PartialOrd,
|
K: PartialOrd,
|
||||||
{
|
{
|
||||||
self.iter().is_sorted_by_key(f)
|
self.iter().is_sorted_by_key(f)
|
||||||
|
|
20
src/test/ui/array-slice-vec/slice_is_sorted_by_borrow.rs
Normal file
20
src/test/ui/array-slice-vec/slice_is_sorted_by_borrow.rs
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
// check-pass
|
||||||
|
// regression test for https://github.com/rust-lang/rust/issues/53485#issuecomment-885393452
|
||||||
|
|
||||||
|
#![feature(is_sorted)]
|
||||||
|
|
||||||
|
struct A {
|
||||||
|
name: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let a = &[
|
||||||
|
A {
|
||||||
|
name: "1".to_string(),
|
||||||
|
},
|
||||||
|
A {
|
||||||
|
name: "2".to_string(),
|
||||||
|
},
|
||||||
|
];
|
||||||
|
assert!(a.is_sorted_by_key(|a| a.name.as_str()));
|
||||||
|
}
|
Loading…
Reference in a new issue