Skip to content

Commit

Permalink
Rollup merge of rust-lang#128279 - slanterns:is_sorted, r=dtolnay
Browse files Browse the repository at this point in the history
Stabilize `is_sorted`

Closes: rust-lang#53485.

~~Question: does~~ https://github.com/rust-lang/rust/blob/8fe0c753f23e7050b87a444b6622caf4d2272d5d/compiler/rustc_lint_defs/src/builtin.rs#L1986-L1994 ~~need a new example?~~
edit: It causes a test failure and needs to be changed anyway.

``@rustbot`` label: +T-libs-api

r? libs-api
  • Loading branch information
matthiaskrgr authored Jul 28, 2024
2 parents 4ea98d7 + fcbdcae commit 357ff7a
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 19 deletions.
1 change: 0 additions & 1 deletion alloc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@
// tidy-alphabetical-start
#![cfg_attr(not(no_global_oom_handling), feature(const_alloc_error))]
#![cfg_attr(not(no_global_oom_handling), feature(const_btree_len))]
#![cfg_attr(test, feature(is_sorted))]
#![cfg_attr(test, feature(new_uninit))]
#![feature(alloc_layout_extra)]
#![feature(allocator_api)]
Expand Down
12 changes: 3 additions & 9 deletions core/src/iter/traits/iterator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3951,16 +3951,14 @@ pub trait Iterator {
/// # Examples
///
/// ```
/// #![feature(is_sorted)]
///
/// assert!([1, 2, 2, 9].iter().is_sorted());
/// assert!(![1, 3, 2, 4].iter().is_sorted());
/// assert!([0].iter().is_sorted());
/// assert!(std::iter::empty::<i32>().is_sorted());
/// assert!(![0.0, 1.0, f32::NAN].iter().is_sorted());
/// ```
#[inline]
#[unstable(feature = "is_sorted", reason = "new API", issue = "53485")]
#[stable(feature = "is_sorted", since = "CURRENT_RUSTC_VERSION")]
#[rustc_do_not_const_check]
fn is_sorted(self) -> bool
where
Expand All @@ -3978,8 +3976,6 @@ pub trait Iterator {
/// # Examples
///
/// ```
/// #![feature(is_sorted)]
///
/// assert!([1, 2, 2, 9].iter().is_sorted_by(|a, b| a <= b));
/// assert!(![1, 2, 2, 9].iter().is_sorted_by(|a, b| a < b));
///
Expand All @@ -3989,7 +3985,7 @@ pub trait Iterator {
/// assert!(std::iter::empty::<i32>().is_sorted_by(|a, b| false));
/// assert!(std::iter::empty::<i32>().is_sorted_by(|a, b| true));
/// ```
#[unstable(feature = "is_sorted", reason = "new API", issue = "53485")]
#[stable(feature = "is_sorted", since = "CURRENT_RUSTC_VERSION")]
#[rustc_do_not_const_check]
fn is_sorted_by<F>(mut self, compare: F) -> bool
where
Expand Down Expand Up @@ -4030,13 +4026,11 @@ pub trait Iterator {
/// # Examples
///
/// ```
/// #![feature(is_sorted)]
///
/// assert!(["c", "bb", "aaa"].iter().is_sorted_by_key(|s| s.len()));
/// assert!(![-2i32, -1, 0, 3].iter().is_sorted_by_key(|n| n.abs()));
/// ```
#[inline]
#[unstable(feature = "is_sorted", reason = "new API", issue = "53485")]
#[stable(feature = "is_sorted", since = "CURRENT_RUSTC_VERSION")]
#[rustc_do_not_const_check]
fn is_sorted_by_key<F, K>(self, f: F) -> bool
where
Expand Down
11 changes: 3 additions & 8 deletions core/src/slice/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4069,7 +4069,6 @@ impl<T> [T] {
/// # Examples
///
/// ```
/// #![feature(is_sorted)]
/// let empty: [i32; 0] = [];
///
/// assert!([1, 2, 2, 9].is_sorted());
Expand All @@ -4079,7 +4078,7 @@ impl<T> [T] {
/// assert!(![0.0, 1.0, f32::NAN].is_sorted());
/// ```
#[inline]
#[unstable(feature = "is_sorted", reason = "new API", issue = "53485")]
#[stable(feature = "is_sorted", since = "CURRENT_RUSTC_VERSION")]
#[must_use]
pub fn is_sorted(&self) -> bool
where
Expand All @@ -4096,8 +4095,6 @@ impl<T> [T] {
/// # Examples
///
/// ```
/// #![feature(is_sorted)]
///
/// assert!([1, 2, 2, 9].is_sorted_by(|a, b| a <= b));
/// assert!(![1, 2, 2, 9].is_sorted_by(|a, b| a < b));
///
Expand All @@ -4108,7 +4105,7 @@ impl<T> [T] {
/// assert!(empty.is_sorted_by(|a, b| false));
/// assert!(empty.is_sorted_by(|a, b| true));
/// ```
#[unstable(feature = "is_sorted", reason = "new API", issue = "53485")]
#[stable(feature = "is_sorted", since = "CURRENT_RUSTC_VERSION")]
#[must_use]
pub fn is_sorted_by<'a, F>(&'a self, mut compare: F) -> bool
where
Expand All @@ -4128,13 +4125,11 @@ impl<T> [T] {
/// # Examples
///
/// ```
/// #![feature(is_sorted)]
///
/// assert!(["c", "bb", "aaa"].is_sorted_by_key(|s| s.len()));
/// assert!(![-2i32, -1, 0, 3].is_sorted_by_key(|n| n.abs()));
/// ```
#[inline]
#[unstable(feature = "is_sorted", reason = "new API", issue = "53485")]
#[stable(feature = "is_sorted", since = "CURRENT_RUSTC_VERSION")]
#[must_use]
pub fn is_sorted_by_key<'a, F, K>(&'a self, f: F) -> bool
where
Expand Down
1 change: 0 additions & 1 deletion core/tests/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
#![feature(hasher_prefixfree_extras)]
#![feature(hashmap_internals)]
#![feature(try_find)]
#![feature(is_sorted)]
#![feature(layout_for_ptr)]
#![feature(pattern)]
#![feature(slice_take)]
Expand Down

0 comments on commit 357ff7a

Please sign in to comment.