Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove HRTB from [T]::is_sorted_by{,_key} #102977

Merged
merged 2 commits into from
Nov 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions library/core/src/slice/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3724,9 +3724,9 @@ impl<T> [T] {
/// [`is_sorted`]: slice::is_sorted
#[unstable(feature = "is_sorted", reason = "new API", issue = "53485")]
#[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
F: FnMut(&T, &T) -> Option<Ordering>,
F: FnMut(&'a T, &'a T) -> Option<Ordering>,
{
self.iter().is_sorted_by(|a, b| compare(*a, *b))
}
Expand All @@ -3750,9 +3750,9 @@ impl<T> [T] {
#[inline]
#[unstable(feature = "is_sorted", reason = "new API", issue = "53485")]
#[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
F: FnMut(&T) -> K,
F: FnMut(&'a T) -> K,
K: PartialOrd,
{
self.iter().is_sorted_by_key(f)
Expand Down
20 changes: 20 additions & 0 deletions src/test/ui/array-slice-vec/slice_is_sorted_by_borrow.rs
Original file line number Diff line number Diff line change
@@ -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()));
}