Skip to content

Commit 6445dea

Browse files
committed
Add is_sorted unstable documentation
1 parent e3e72cd commit 6445dea

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
@@ -2606,6 +2606,7 @@ pub trait Iterator {
26062606
/// assert!(std::iter::empty::<i32>().is_sorted());
26072607
/// assert!(![0.0, 1.0, std::f32::NAN].iter().is_sorted());
26082608
/// ```
2609+
#[inline]
26092610
#[unstable(feature = "is_sorted", reason = "new API", issue = "53485")]
26102611
fn is_sorted(self) -> bool
26112612
where
@@ -2656,6 +2657,7 @@ pub trait Iterator {
26562657
/// assert!(["c", "bb", "aaa"].iter().is_sorted_by_key(|s| s.len()));
26572658
/// assert!(![-2i32, -1, 0, 3].iter().is_sorted_by_key(|n| n.abs()));
26582659
/// ```
2660+
#[inline]
26592661
#[unstable(feature = "is_sorted", reason = "new API", issue = "53485")]
26602662
fn is_sorted_by_key<F, K>(self, mut f: F) -> bool
26612663
where

src/libcore/slice/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2280,6 +2280,7 @@ impl<T> [T] {
22802280
/// assert!(empty.is_sorted());
22812281
/// assert!(![0.0, 1.0, std::f32::NAN].is_sorted());
22822282
/// ```
2283+
#[inline]
22832284
#[unstable(feature = "is_sorted", reason = "new API", issue = "53485")]
22842285
pub fn is_sorted(&self) -> bool
22852286
where
@@ -2327,6 +2328,7 @@ impl<T> [T] {
23272328
/// assert!(["c", "bb", "aaa"].is_sorted_by_key(|s| s.len()));
23282329
/// assert!(![-2i32, -1, 0, 3].is_sorted_by_key(|n| n.abs()));
23292330
/// ```
2331+
#[inline]
23302332
#[unstable(feature = "is_sorted", reason = "new API", issue = "53485")]
23312333
pub fn is_sorted_by_key<F, K>(&self, mut f: F) -> bool
23322334
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)