--- /dev/null
+# `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`.
/// assert!(std::iter::empty::<i32>().is_sorted());
/// assert!(![0.0, 1.0, std::f32::NAN].iter().is_sorted());
/// ```
+ #[inline]
#[unstable(feature = "is_sorted", reason = "new API", issue = "53485")]
fn is_sorted(self) -> bool
where
/// 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")]
fn is_sorted_by_key<F, K>(self, mut f: F) -> bool
where
/// assert!(empty.is_sorted());
/// assert!(![0.0, 1.0, std::f32::NAN].is_sorted());
/// ```
+ #[inline]
#[unstable(feature = "is_sorted", reason = "new API", issue = "53485")]
pub fn is_sorted(&self) -> bool
where
/// 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")]
pub fn is_sorted_by_key<F, K>(&self, mut f: F) -> bool
where
// except according to those terms.
fn main() {
+ // Assert `Iterator` methods are feature gated
assert!([1, 2, 2, 9].iter().is_sorted());
//^ ERROR: use of unstable library feature 'is_sorted'
assert!(![-2i32, -1, 0, 3].iter().is_sorted_by_key(|n| n.abs()));
//^ ERROR: use of unstable library feature 'is_sorted'
+
+ // Assert `[T]` methods are feature gated
+ assert!([1, 2, 2, 9].is_sorted());
+ //^ ERROR: use of unstable library feature 'is_sorted'
+ assert!(![-2i32, -1, 0, 3].is_sorted_by_key(|n| n.abs()));
+ //^ ERROR: use of unstable library feature 'is_sorted'
}
error[E0658]: use of unstable library feature 'is_sorted': new API (see issue #53485)
- --> $DIR/feature-gate-is_sorted.rs:12:33
+ --> $DIR/feature-gate-is_sorted.rs:13:33
|
LL | assert!([1, 2, 2, 9].iter().is_sorted());
| ^^^^^^^^^
= help: add #![feature(is_sorted)] to the crate attributes to enable
error[E0658]: use of unstable library feature 'is_sorted': new API (see issue #53485)
- --> $DIR/feature-gate-is_sorted.rs:14:39
+ --> $DIR/feature-gate-is_sorted.rs:15:39
|
LL | assert!(![-2i32, -1, 0, 3].iter().is_sorted_by_key(|n| n.abs()));
| ^^^^^^^^^^^^^^^^
|
= help: add #![feature(is_sorted)] to the crate attributes to enable
-error: aborting due to 2 previous errors
+error[E0658]: use of unstable library feature 'is_sorted': new API (see issue #53485)
+ --> $DIR/feature-gate-is_sorted.rs:19:26
+ |
+LL | assert!([1, 2, 2, 9].is_sorted());
+ | ^^^^^^^^^
+ |
+ = help: add #![feature(is_sorted)] to the crate attributes to enable
+
+error[E0658]: use of unstable library feature 'is_sorted': new API (see issue #53485)
+ --> $DIR/feature-gate-is_sorted.rs:21:32
+ |
+LL | assert!(![-2i32, -1, 0, 3].is_sorted_by_key(|n| n.abs()));
+ | ^^^^^^^^^^^^^^^^
+ |
+ = help: add #![feature(is_sorted)] to the crate attributes to enable
+
+error: aborting due to 4 previous errors
For more information about this error, try `rustc --explain E0658`.