Skip to content

Commit ce47dde

Browse files
committed
Add is_sorted unstable documentation
1 parent 02477f6 commit ce47dde

File tree

5 files changed

+41
-3
lines changed

5 files changed

+41
-3
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# `is_sorted`
2+
3+
The tracking issue for this feature is: [#53485]
4+
5+
[#53485]: https://github.com/rust-lang/rust/issues/53485
6+
7+
------------------------
8+
9+
Add the methods `is_sorted`, `is_sorted_by` and `is_sorted_by_key` to `[T]`;
10+
add the methods `is_sorted`, `is_sorted_by` and `is_sorted_by_key` to
11+
`Iterator`.

src/libcore/iter/iterator.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2626,6 +2626,7 @@ pub trait Iterator {
26262626
/// assert!(std::iter::empty::<i32>().is_sorted());
26272627
/// assert!(![0.0, 1.0, std::f32::NAN].iter().is_sorted());
26282628
/// ```
2629+
#[inline]
26292630
#[unstable(feature = "is_sorted", reason = "new API", issue = "53485")]
26302631
fn is_sorted(self) -> bool
26312632
where
@@ -2676,6 +2677,7 @@ pub trait Iterator {
26762677
/// assert!(["c", "bb", "aaa"].iter().is_sorted_by_key(|s| s.len()));
26772678
/// assert!(![-2i32, -1, 0, 3].iter().is_sorted_by_key(|n| n.abs()));
26782679
/// ```
2680+
#[inline]
26792681
#[unstable(feature = "is_sorted", reason = "new API", issue = "53485")]
26802682
fn is_sorted_by_key<F, K>(self, mut f: F) -> bool
26812683
where

src/libcore/slice/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2272,6 +2272,7 @@ impl<T> [T] {
22722272
/// assert!(empty.is_sorted());
22732273
/// assert!(![0.0, 1.0, std::f32::NAN].is_sorted());
22742274
/// ```
2275+
#[inline]
22752276
#[unstable(feature = "is_sorted", reason = "new API", issue = "53485")]
22762277
pub fn is_sorted(&self) -> bool
22772278
where
@@ -2319,6 +2320,7 @@ impl<T> [T] {
23192320
/// assert!(["c", "bb", "aaa"].is_sorted_by_key(|s| s.len()));
23202321
/// assert!(![-2i32, -1, 0, 3].is_sorted_by_key(|n| n.abs()));
23212322
/// ```
2323+
#[inline]
23222324
#[unstable(feature = "is_sorted", reason = "new API", issue = "53485")]
23232325
pub fn is_sorted_by_key<F, K>(&self, mut f: F) -> bool
23242326
where

src/test/ui/feature-gates/feature-gate-is_sorted.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,15 @@
99
// except according to those terms.
1010

1111
fn main() {
12+
// Assert `Iterator` methods are feature gated
1213
assert!([1, 2, 2, 9].iter().is_sorted());
1314
//^ ERROR: use of unstable library feature 'is_sorted'
1415
assert!(![-2i32, -1, 0, 3].iter().is_sorted_by_key(|n| n.abs()));
1516
//^ ERROR: use of unstable library feature 'is_sorted'
17+
18+
// Assert `[T]` methods are feature gated
19+
assert!([1, 2, 2, 9].is_sorted());
20+
//^ ERROR: use of unstable library feature 'is_sorted'
21+
assert!(![-2i32, -1, 0, 3].is_sorted_by_key(|n| n.abs()));
22+
//^ ERROR: use of unstable library feature 'is_sorted'
1623
}
Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,35 @@
11
error[E0658]: use of unstable library feature 'is_sorted': new API (see issue #53485)
2-
--> $DIR/feature-gate-is_sorted.rs:12:33
2+
--> $DIR/feature-gate-is_sorted.rs:13:33
33
|
44
LL | assert!([1, 2, 2, 9].iter().is_sorted());
55
| ^^^^^^^^^
66
|
77
= help: add #![feature(is_sorted)] to the crate attributes to enable
88

99
error[E0658]: use of unstable library feature 'is_sorted': new API (see issue #53485)
10-
--> $DIR/feature-gate-is_sorted.rs:14:39
10+
--> $DIR/feature-gate-is_sorted.rs:15:39
1111
|
1212
LL | assert!(![-2i32, -1, 0, 3].iter().is_sorted_by_key(|n| n.abs()));
1313
| ^^^^^^^^^^^^^^^^
1414
|
1515
= help: add #![feature(is_sorted)] to the crate attributes to enable
1616

17-
error: aborting due to 2 previous errors
17+
error[E0658]: use of unstable library feature 'is_sorted': new API (see issue #53485)
18+
--> $DIR/feature-gate-is_sorted.rs:19:26
19+
|
20+
LL | assert!([1, 2, 2, 9].is_sorted());
21+
| ^^^^^^^^^
22+
|
23+
= help: add #![feature(is_sorted)] to the crate attributes to enable
24+
25+
error[E0658]: use of unstable library feature 'is_sorted': new API (see issue #53485)
26+
--> $DIR/feature-gate-is_sorted.rs:21:32
27+
|
28+
LL | assert!(![-2i32, -1, 0, 3].is_sorted_by_key(|n| n.abs()));
29+
| ^^^^^^^^^^^^^^^^
30+
|
31+
= help: add #![feature(is_sorted)] to the crate attributes to enable
32+
33+
error: aborting due to 4 previous errors
1834

1935
For more information about this error, try `rustc --explain E0658`.

0 commit comments

Comments
 (0)