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 aa07def + ec0b354 commit 5b59640
Show file tree
Hide file tree
Showing 18 changed files with 21 additions and 106 deletions.
1 change: 0 additions & 1 deletion compiler/rustc_codegen_cranelift/example/std_example.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
coroutines,
stmt_expr_attributes,
coroutine_trait,
is_sorted,
repr_simd,
tuple_trait,
unboxed_closures
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_gcc/example/std_example.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#![allow(internal_features)]
#![feature(core_intrinsics, coroutines, coroutine_trait, is_sorted, stmt_expr_attributes)]
#![feature(core_intrinsics, coroutines, coroutine_trait, stmt_expr_attributes)]

#[cfg(feature="master")]
#[cfg(target_arch="x86_64")]
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_hir_analysis/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ This API is completely unstable and subject to change.
#![doc(rust_logo)]
#![feature(control_flow_enum)]
#![feature(if_let_guard)]
#![feature(is_sorted)]
#![feature(iter_intersperse)]
#![feature(let_chains)]
#![feature(never_type)]
Expand Down
12 changes: 8 additions & 4 deletions compiler/rustc_lint_defs/src/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1984,14 +1984,18 @@ declare_lint! {
///
/// ```rust
/// trait MyIterator : Iterator {
/// // is_sorted is an unstable method that already exists on the Iterator trait
/// fn is_sorted(self) -> bool where Self: Sized {true}
/// // is_partitioned is an unstable method that already exists on the Iterator trait
/// fn is_partitioned<P>(self, predicate: P) -> bool
/// where
/// Self: Sized,
/// P: FnMut(Self::Item) -> bool,
/// {true}
/// }
///
/// impl<T: ?Sized> MyIterator for T where T: Iterator { }
///
/// let x = vec![1, 2, 3];
/// let _ = x.iter().is_sorted();
/// let _ = x.iter().is_partitioned(|_| true);
/// ```
///
/// {{produces}}
Expand All @@ -2007,7 +2011,7 @@ declare_lint! {
/// is an early-warning to let you know that there may be a collision in
/// the future. This can be avoided by adding type annotations to
/// disambiguate which trait method you intend to call, such as
/// `MyIterator::is_sorted(my_iter)` or renaming or removing the method.
/// `MyIterator::is_partitioned(my_iter, my_predicate)` or renaming or removing the method.
///
/// [nightly channel]: https://doc.rust-lang.org/book/appendix-07-nightly-rust.html
/// [`feature` attribute]: https://doc.rust-lang.org/nightly/unstable-book/
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_mir_transform/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
#![feature(decl_macro)]
#![feature(if_let_guard)]
#![feature(impl_trait_in_assoc_type)]
#![feature(is_sorted)]
#![feature(let_chains)]
#![feature(map_try_insert)]
#![feature(never_type)]
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_monomorphize/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// tidy-alphabetical-start
#![feature(array_windows)]
#![feature(is_sorted)]
// tidy-alphabetical-end

use rustc_hir::lang_items::LangItem;
Expand Down
1 change: 0 additions & 1 deletion library/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 library/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 library/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 library/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
11 changes: 0 additions & 11 deletions src/doc/unstable-book/src/library-features/is-sorted.md

This file was deleted.

1 change: 0 additions & 1 deletion src/tools/clippy/clippy_lints/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#![feature(f128)]
#![feature(f16)]
#![feature(if_let_guard)]
#![feature(is_sorted)]
#![feature(iter_intersperse)]
#![feature(iter_partition_in_place)]
#![feature(let_chains)]
Expand Down
1 change: 0 additions & 1 deletion src/tools/clippy/tests/compile-test.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#![feature(is_sorted)]
#![cfg_attr(feature = "deny-warnings", deny(warnings))]
#![warn(rust_2018_idioms, unused_lifetimes)]
#![allow(unused_extern_crates)]
Expand Down
1 change: 0 additions & 1 deletion src/tools/clippy/tests/ui/unit_return_expecting_ord.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
#![allow(clippy::needless_return)]
#![allow(clippy::unused_unit)]
#![allow(clippy::useless_vec)]
#![feature(is_sorted)]

struct Struct {
field: isize,
Expand Down
12 changes: 6 additions & 6 deletions src/tools/clippy/tests/ui/unit_return_expecting_ord.stderr
Original file line number Diff line number Diff line change
@@ -1,37 +1,37 @@
error: this closure returns the unit type which also implements Ord
--> tests/ui/unit_return_expecting_ord.rs:19:25
--> tests/ui/unit_return_expecting_ord.rs:18:25
|
LL | structs.sort_by_key(|s| {
| ^^^
|
help: probably caused by this trailing semicolon
--> tests/ui/unit_return_expecting_ord.rs:21:24
--> tests/ui/unit_return_expecting_ord.rs:20:24
|
LL | double(s.field);
| ^
= note: `-D clippy::unit-return-expecting-ord` implied by `-D warnings`
= help: to override `-D warnings` add `#[allow(clippy::unit_return_expecting_ord)]`

error: this closure returns the unit type which also implements PartialOrd
--> tests/ui/unit_return_expecting_ord.rs:24:30
--> tests/ui/unit_return_expecting_ord.rs:23:30
|
LL | structs.is_sorted_by_key(|s| {
| ^^^
|
help: probably caused by this trailing semicolon
--> tests/ui/unit_return_expecting_ord.rs:26:24
--> tests/ui/unit_return_expecting_ord.rs:25:24
|
LL | double(s.field);
| ^

error: this closure returns the unit type which also implements PartialOrd
--> tests/ui/unit_return_expecting_ord.rs:28:30
--> tests/ui/unit_return_expecting_ord.rs:27:30
|
LL | structs.is_sorted_by_key(|s| {
| ^^^

error: this closure returns the unit type which also implements Ord
--> tests/ui/unit_return_expecting_ord.rs:39:25
--> tests/ui/unit_return_expecting_ord.rs:38:25
|
LL | structs.sort_by_key(|s| unit(s.field));
| ^^^
Expand Down
2 changes: 0 additions & 2 deletions tests/ui/array-slice-vec/slice_is_sorted_by_borrow.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
//@ check-pass
// regression test for https://github.com/rust-lang/rust/issues/53485#issuecomment-885393452

#![feature(is_sorted)]

struct A {
name: String,
}
Expand Down
13 changes: 0 additions & 13 deletions tests/ui/feature-gates/feature-gate-is_sorted.rs

This file was deleted.

43 changes: 0 additions & 43 deletions tests/ui/feature-gates/feature-gate-is_sorted.stderr

This file was deleted.

0 comments on commit 5b59640

Please sign in to comment.