mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-22 06:44:35 +00:00
stabilize is_sorted
This commit is contained in:
parent
8fe0c753f2
commit
ec0b354092
@ -3,7 +3,6 @@
|
||||
coroutines,
|
||||
stmt_expr_attributes,
|
||||
coroutine_trait,
|
||||
is_sorted,
|
||||
repr_simd,
|
||||
tuple_trait,
|
||||
unboxed_closures
|
||||
|
@ -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")]
|
||||
|
@ -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)]
|
||||
|
@ -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}}
|
||||
@ -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/
|
||||
|
@ -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)]
|
||||
|
@ -1,6 +1,5 @@
|
||||
// tidy-alphabetical-start
|
||||
#![feature(array_windows)]
|
||||
#![feature(is_sorted)]
|
||||
// tidy-alphabetical-end
|
||||
|
||||
use rustc_hir::lang_items::LangItem;
|
||||
|
@ -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)]
|
||||
|
@ -3951,8 +3951,6 @@ 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());
|
||||
@ -3960,7 +3958,7 @@ pub trait Iterator {
|
||||
/// 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
|
||||
@ -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));
|
||||
///
|
||||
@ -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
|
||||
@ -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
|
||||
|
@ -4069,7 +4069,6 @@ impl<T> [T] {
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// #![feature(is_sorted)]
|
||||
/// let empty: [i32; 0] = [];
|
||||
///
|
||||
/// assert!([1, 2, 2, 9].is_sorted());
|
||||
@ -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
|
||||
@ -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));
|
||||
///
|
||||
@ -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
|
||||
@ -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
|
||||
|
@ -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)]
|
||||
|
@ -1,11 +0,0 @@
|
||||
# `is_sorted`
|
||||
|
||||
The tracking issue for this feature is: [#53485]
|
||||
|
||||
[#53485]: https://github.com/rust-lang/rust/issues/53485
|
||||
|
||||
------------------------
|
||||
|
||||
Add the methods `is_sorted`, `is_sorted_by` and `is_sorted_by_key` to `[T]`;
|
||||
add the methods `is_sorted`, `is_sorted_by` and `is_sorted_by_key` to
|
||||
`Iterator`.
|
@ -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)]
|
||||
|
@ -1,4 +1,3 @@
|
||||
#![feature(is_sorted)]
|
||||
#![cfg_attr(feature = "deny-warnings", deny(warnings))]
|
||||
#![warn(rust_2018_idioms, unused_lifetimes)]
|
||||
#![allow(unused_extern_crates)]
|
||||
|
@ -2,7 +2,6 @@
|
||||
#![allow(clippy::needless_return)]
|
||||
#![allow(clippy::unused_unit)]
|
||||
#![allow(clippy::useless_vec)]
|
||||
#![feature(is_sorted)]
|
||||
|
||||
struct Struct {
|
||||
field: isize,
|
||||
|
@ -1,11 +1,11 @@
|
||||
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);
|
||||
| ^
|
||||
@ -13,25 +13,25 @@ LL | double(s.field);
|
||||
= 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));
|
||||
| ^^^
|
||||
|
@ -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,
|
||||
}
|
||||
|
@ -1,13 +0,0 @@
|
||||
fn main() {
|
||||
// Assert `Iterator` methods are unstable
|
||||
assert!([1, 2, 2, 9].iter().is_sorted());
|
||||
//~^ ERROR: use of unstable library feature 'is_sorted': new API
|
||||
assert!(![-2i32, -1, 0, 3].iter().is_sorted_by_key(|n| n.abs()));
|
||||
//~^ ERROR: use of unstable library feature 'is_sorted': new API
|
||||
|
||||
// Assert `[T]` methods are unstable
|
||||
assert!([1, 2, 2, 9].is_sorted());
|
||||
//~^ ERROR: use of unstable library feature 'is_sorted': new API
|
||||
assert!(![-2i32, -1, 0, 3].is_sorted_by_key(|n| n.abs()));
|
||||
//~^ ERROR: use of unstable library feature 'is_sorted': new API
|
||||
}
|
@ -1,43 +0,0 @@
|
||||
error[E0658]: use of unstable library feature 'is_sorted': new API
|
||||
--> $DIR/feature-gate-is_sorted.rs:3:33
|
||||
|
|
||||
LL | assert!([1, 2, 2, 9].iter().is_sorted());
|
||||
| ^^^^^^^^^
|
||||
|
|
||||
= note: see issue #53485 <https://github.com/rust-lang/rust/issues/53485> for more information
|
||||
= help: add `#![feature(is_sorted)]` to the crate attributes to enable
|
||||
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
|
||||
|
||||
error[E0658]: use of unstable library feature 'is_sorted': new API
|
||||
--> $DIR/feature-gate-is_sorted.rs:5:39
|
||||
|
|
||||
LL | assert!(![-2i32, -1, 0, 3].iter().is_sorted_by_key(|n| n.abs()));
|
||||
| ^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: see issue #53485 <https://github.com/rust-lang/rust/issues/53485> for more information
|
||||
= help: add `#![feature(is_sorted)]` to the crate attributes to enable
|
||||
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
|
||||
|
||||
error[E0658]: use of unstable library feature 'is_sorted': new API
|
||||
--> $DIR/feature-gate-is_sorted.rs:9:26
|
||||
|
|
||||
LL | assert!([1, 2, 2, 9].is_sorted());
|
||||
| ^^^^^^^^^
|
||||
|
|
||||
= note: see issue #53485 <https://github.com/rust-lang/rust/issues/53485> for more information
|
||||
= help: add `#![feature(is_sorted)]` to the crate attributes to enable
|
||||
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
|
||||
|
||||
error[E0658]: use of unstable library feature 'is_sorted': new API
|
||||
--> $DIR/feature-gate-is_sorted.rs:11:32
|
||||
|
|
||||
LL | assert!(![-2i32, -1, 0, 3].is_sorted_by_key(|n| n.abs()));
|
||||
| ^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: see issue #53485 <https://github.com/rust-lang/rust/issues/53485> for more information
|
||||
= help: add `#![feature(is_sorted)]` to the crate attributes to enable
|
||||
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
|
||||
|
||||
error: aborting due to 4 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0658`.
|
Loading…
Reference in New Issue
Block a user