Skip to content

Commit 5b59640

Browse files
authored
Rollup merge of rust-lang#128279 - slanterns:is_sorted, r=dtolnay
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
2 parents aa07def + ec0b354 commit 5b59640

File tree

18 files changed

+21
-106
lines changed

18 files changed

+21
-106
lines changed

compiler/rustc_codegen_cranelift/example/std_example.rs

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
coroutines,
44
stmt_expr_attributes,
55
coroutine_trait,
6-
is_sorted,
76
repr_simd,
87
tuple_trait,
98
unboxed_closures

compiler/rustc_codegen_gcc/example/std_example.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#![allow(internal_features)]
2-
#![feature(core_intrinsics, coroutines, coroutine_trait, is_sorted, stmt_expr_attributes)]
2+
#![feature(core_intrinsics, coroutines, coroutine_trait, stmt_expr_attributes)]
33

44
#[cfg(feature="master")]
55
#[cfg(target_arch="x86_64")]

compiler/rustc_hir_analysis/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ This API is completely unstable and subject to change.
6464
#![doc(rust_logo)]
6565
#![feature(control_flow_enum)]
6666
#![feature(if_let_guard)]
67-
#![feature(is_sorted)]
6867
#![feature(iter_intersperse)]
6968
#![feature(let_chains)]
7069
#![feature(never_type)]

compiler/rustc_lint_defs/src/builtin.rs

+8-4
Original file line numberDiff line numberDiff line change
@@ -1984,14 +1984,18 @@ declare_lint! {
19841984
///
19851985
/// ```rust
19861986
/// trait MyIterator : Iterator {
1987-
/// // is_sorted is an unstable method that already exists on the Iterator trait
1988-
/// fn is_sorted(self) -> bool where Self: Sized {true}
1987+
/// // is_partitioned is an unstable method that already exists on the Iterator trait
1988+
/// fn is_partitioned<P>(self, predicate: P) -> bool
1989+
/// where
1990+
/// Self: Sized,
1991+
/// P: FnMut(Self::Item) -> bool,
1992+
/// {true}
19891993
/// }
19901994
///
19911995
/// impl<T: ?Sized> MyIterator for T where T: Iterator { }
19921996
///
19931997
/// let x = vec![1, 2, 3];
1994-
/// let _ = x.iter().is_sorted();
1998+
/// let _ = x.iter().is_partitioned(|_| true);
19951999
/// ```
19962000
///
19972001
/// {{produces}}
@@ -2007,7 +2011,7 @@ declare_lint! {
20072011
/// is an early-warning to let you know that there may be a collision in
20082012
/// the future. This can be avoided by adding type annotations to
20092013
/// disambiguate which trait method you intend to call, such as
2010-
/// `MyIterator::is_sorted(my_iter)` or renaming or removing the method.
2014+
/// `MyIterator::is_partitioned(my_iter, my_predicate)` or renaming or removing the method.
20112015
///
20122016
/// [nightly channel]: https://doc.rust-lang.org/book/appendix-07-nightly-rust.html
20132017
/// [`feature` attribute]: https://doc.rust-lang.org/nightly/unstable-book/

compiler/rustc_mir_transform/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
#![feature(decl_macro)]
77
#![feature(if_let_guard)]
88
#![feature(impl_trait_in_assoc_type)]
9-
#![feature(is_sorted)]
109
#![feature(let_chains)]
1110
#![feature(map_try_insert)]
1211
#![feature(never_type)]

compiler/rustc_monomorphize/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
// tidy-alphabetical-start
22
#![feature(array_windows)]
3-
#![feature(is_sorted)]
43
// tidy-alphabetical-end
54

65
use rustc_hir::lang_items::LangItem;

library/alloc/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,6 @@
9292
// tidy-alphabetical-start
9393
#![cfg_attr(not(no_global_oom_handling), feature(const_alloc_error))]
9494
#![cfg_attr(not(no_global_oom_handling), feature(const_btree_len))]
95-
#![cfg_attr(test, feature(is_sorted))]
9695
#![cfg_attr(test, feature(new_uninit))]
9796
#![feature(alloc_layout_extra)]
9897
#![feature(allocator_api)]

library/core/src/iter/traits/iterator.rs

+3-9
Original file line numberDiff line numberDiff line change
@@ -3951,16 +3951,14 @@ pub trait Iterator {
39513951
/// # Examples
39523952
///
39533953
/// ```
3954-
/// #![feature(is_sorted)]
3955-
///
39563954
/// assert!([1, 2, 2, 9].iter().is_sorted());
39573955
/// assert!(![1, 3, 2, 4].iter().is_sorted());
39583956
/// assert!([0].iter().is_sorted());
39593957
/// assert!(std::iter::empty::<i32>().is_sorted());
39603958
/// assert!(![0.0, 1.0, f32::NAN].iter().is_sorted());
39613959
/// ```
39623960
#[inline]
3963-
#[unstable(feature = "is_sorted", reason = "new API", issue = "53485")]
3961+
#[stable(feature = "is_sorted", since = "CURRENT_RUSTC_VERSION")]
39643962
#[rustc_do_not_const_check]
39653963
fn is_sorted(self) -> bool
39663964
where
@@ -3978,8 +3976,6 @@ pub trait Iterator {
39783976
/// # Examples
39793977
///
39803978
/// ```
3981-
/// #![feature(is_sorted)]
3982-
///
39833979
/// assert!([1, 2, 2, 9].iter().is_sorted_by(|a, b| a <= b));
39843980
/// assert!(![1, 2, 2, 9].iter().is_sorted_by(|a, b| a < b));
39853981
///
@@ -3989,7 +3985,7 @@ pub trait Iterator {
39893985
/// assert!(std::iter::empty::<i32>().is_sorted_by(|a, b| false));
39903986
/// assert!(std::iter::empty::<i32>().is_sorted_by(|a, b| true));
39913987
/// ```
3992-
#[unstable(feature = "is_sorted", reason = "new API", issue = "53485")]
3988+
#[stable(feature = "is_sorted", since = "CURRENT_RUSTC_VERSION")]
39933989
#[rustc_do_not_const_check]
39943990
fn is_sorted_by<F>(mut self, compare: F) -> bool
39953991
where
@@ -4030,13 +4026,11 @@ pub trait Iterator {
40304026
/// # Examples
40314027
///
40324028
/// ```
4033-
/// #![feature(is_sorted)]
4034-
///
40354029
/// assert!(["c", "bb", "aaa"].iter().is_sorted_by_key(|s| s.len()));
40364030
/// assert!(![-2i32, -1, 0, 3].iter().is_sorted_by_key(|n| n.abs()));
40374031
/// ```
40384032
#[inline]
4039-
#[unstable(feature = "is_sorted", reason = "new API", issue = "53485")]
4033+
#[stable(feature = "is_sorted", since = "CURRENT_RUSTC_VERSION")]
40404034
#[rustc_do_not_const_check]
40414035
fn is_sorted_by_key<F, K>(self, f: F) -> bool
40424036
where

library/core/src/slice/mod.rs

+3-8
Original file line numberDiff line numberDiff line change
@@ -4069,7 +4069,6 @@ impl<T> [T] {
40694069
/// # Examples
40704070
///
40714071
/// ```
4072-
/// #![feature(is_sorted)]
40734072
/// let empty: [i32; 0] = [];
40744073
///
40754074
/// assert!([1, 2, 2, 9].is_sorted());
@@ -4079,7 +4078,7 @@ impl<T> [T] {
40794078
/// assert!(![0.0, 1.0, f32::NAN].is_sorted());
40804079
/// ```
40814080
#[inline]
4082-
#[unstable(feature = "is_sorted", reason = "new API", issue = "53485")]
4081+
#[stable(feature = "is_sorted", since = "CURRENT_RUSTC_VERSION")]
40834082
#[must_use]
40844083
pub fn is_sorted(&self) -> bool
40854084
where
@@ -4096,8 +4095,6 @@ impl<T> [T] {
40964095
/// # Examples
40974096
///
40984097
/// ```
4099-
/// #![feature(is_sorted)]
4100-
///
41014098
/// assert!([1, 2, 2, 9].is_sorted_by(|a, b| a <= b));
41024099
/// assert!(![1, 2, 2, 9].is_sorted_by(|a, b| a < b));
41034100
///
@@ -4108,7 +4105,7 @@ impl<T> [T] {
41084105
/// assert!(empty.is_sorted_by(|a, b| false));
41094106
/// assert!(empty.is_sorted_by(|a, b| true));
41104107
/// ```
4111-
#[unstable(feature = "is_sorted", reason = "new API", issue = "53485")]
4108+
#[stable(feature = "is_sorted", since = "CURRENT_RUSTC_VERSION")]
41124109
#[must_use]
41134110
pub fn is_sorted_by<'a, F>(&'a self, mut compare: F) -> bool
41144111
where
@@ -4128,13 +4125,11 @@ impl<T> [T] {
41284125
/// # Examples
41294126
///
41304127
/// ```
4131-
/// #![feature(is_sorted)]
4132-
///
41334128
/// assert!(["c", "bb", "aaa"].is_sorted_by_key(|s| s.len()));
41344129
/// assert!(![-2i32, -1, 0, 3].is_sorted_by_key(|n| n.abs()));
41354130
/// ```
41364131
#[inline]
4137-
#[unstable(feature = "is_sorted", reason = "new API", issue = "53485")]
4132+
#[stable(feature = "is_sorted", since = "CURRENT_RUSTC_VERSION")]
41384133
#[must_use]
41394134
pub fn is_sorted_by_key<'a, F, K>(&'a self, f: F) -> bool
41404135
where

library/core/tests/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@
4444
#![feature(hasher_prefixfree_extras)]
4545
#![feature(hashmap_internals)]
4646
#![feature(try_find)]
47-
#![feature(is_sorted)]
4847
#![feature(layout_for_ptr)]
4948
#![feature(pattern)]
5049
#![feature(slice_take)]

src/doc/unstable-book/src/library-features/is-sorted.md

-11
This file was deleted.

src/tools/clippy/clippy_lints/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
#![feature(f128)]
66
#![feature(f16)]
77
#![feature(if_let_guard)]
8-
#![feature(is_sorted)]
98
#![feature(iter_intersperse)]
109
#![feature(iter_partition_in_place)]
1110
#![feature(let_chains)]

src/tools/clippy/tests/compile-test.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#![feature(is_sorted)]
21
#![cfg_attr(feature = "deny-warnings", deny(warnings))]
32
#![warn(rust_2018_idioms, unused_lifetimes)]
43
#![allow(unused_extern_crates)]

src/tools/clippy/tests/ui/unit_return_expecting_ord.rs

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
#![allow(clippy::needless_return)]
33
#![allow(clippy::unused_unit)]
44
#![allow(clippy::useless_vec)]
5-
#![feature(is_sorted)]
65

76
struct Struct {
87
field: isize,

src/tools/clippy/tests/ui/unit_return_expecting_ord.stderr

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,37 @@
11
error: this closure returns the unit type which also implements Ord
2-
--> tests/ui/unit_return_expecting_ord.rs:19:25
2+
--> tests/ui/unit_return_expecting_ord.rs:18:25
33
|
44
LL | structs.sort_by_key(|s| {
55
| ^^^
66
|
77
help: probably caused by this trailing semicolon
8-
--> tests/ui/unit_return_expecting_ord.rs:21:24
8+
--> tests/ui/unit_return_expecting_ord.rs:20:24
99
|
1010
LL | double(s.field);
1111
| ^
1212
= note: `-D clippy::unit-return-expecting-ord` implied by `-D warnings`
1313
= help: to override `-D warnings` add `#[allow(clippy::unit_return_expecting_ord)]`
1414

1515
error: this closure returns the unit type which also implements PartialOrd
16-
--> tests/ui/unit_return_expecting_ord.rs:24:30
16+
--> tests/ui/unit_return_expecting_ord.rs:23:30
1717
|
1818
LL | structs.is_sorted_by_key(|s| {
1919
| ^^^
2020
|
2121
help: probably caused by this trailing semicolon
22-
--> tests/ui/unit_return_expecting_ord.rs:26:24
22+
--> tests/ui/unit_return_expecting_ord.rs:25:24
2323
|
2424
LL | double(s.field);
2525
| ^
2626

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

3333
error: this closure returns the unit type which also implements Ord
34-
--> tests/ui/unit_return_expecting_ord.rs:39:25
34+
--> tests/ui/unit_return_expecting_ord.rs:38:25
3535
|
3636
LL | structs.sort_by_key(|s| unit(s.field));
3737
| ^^^

tests/ui/array-slice-vec/slice_is_sorted_by_borrow.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
//@ check-pass
22
// regression test for https://github.com/rust-lang/rust/issues/53485#issuecomment-885393452
33

4-
#![feature(is_sorted)]
5-
64
struct A {
75
name: String,
86
}

tests/ui/feature-gates/feature-gate-is_sorted.rs

-13
This file was deleted.

tests/ui/feature-gates/feature-gate-is_sorted.stderr

-43
This file was deleted.

0 commit comments

Comments
 (0)