Skip to content

Commit c20ad72

Browse files
committed
Stabilize Range[Inclusive]::is_empty
I would like to propose these two simple methods for stabilization: - Knowing that a range is exhaused isn't otherwise trivial - Clippy would like to suggest them, but had to do extra work to disable that path <rust-lang/rust-clippy#3807> because they're unstable - These work on `PartialOrd`, consistently with now-stable `contains`, and are thus more general than iterator-based approaches that need `Step` - They've been unchanged for some time, and have picked up uses in the compiler - Stabilizing them doesn't block any future iterator-based is_empty plans, as the inherent ones are preferred in name resolution
1 parent e6d85ea commit c20ad72

File tree

6 files changed

+2
-17
lines changed

6 files changed

+2
-17
lines changed

library/core/src/ops/range.rs

+2-12
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,6 @@ impl<Idx: PartialOrd<Idx>> Range<Idx> {
125125
/// # Examples
126126
///
127127
/// ```
128-
/// #![feature(range_is_empty)]
129-
///
130128
/// assert!(!(3..5).is_empty());
131129
/// assert!( (3..3).is_empty());
132130
/// assert!( (3..2).is_empty());
@@ -135,13 +133,11 @@ impl<Idx: PartialOrd<Idx>> Range<Idx> {
135133
/// The range is empty if either side is incomparable:
136134
///
137135
/// ```
138-
/// #![feature(range_is_empty)]
139-
///
140136
/// assert!(!(3.0..5.0).is_empty());
141137
/// assert!( (3.0..f32::NAN).is_empty());
142138
/// assert!( (f32::NAN..5.0).is_empty());
143139
/// ```
144-
#[unstable(feature = "range_is_empty", reason = "recently added", issue = "48111")]
140+
#[stable(feature = "range_is_empty", since = "1.47.0")]
145141
pub fn is_empty(&self) -> bool {
146142
!(self.start < self.end)
147143
}
@@ -481,8 +477,6 @@ impl<Idx: PartialOrd<Idx>> RangeInclusive<Idx> {
481477
/// # Examples
482478
///
483479
/// ```
484-
/// #![feature(range_is_empty)]
485-
///
486480
/// assert!(!(3..=5).is_empty());
487481
/// assert!(!(3..=3).is_empty());
488482
/// assert!( (3..=2).is_empty());
@@ -491,8 +485,6 @@ impl<Idx: PartialOrd<Idx>> RangeInclusive<Idx> {
491485
/// The range is empty if either side is incomparable:
492486
///
493487
/// ```
494-
/// #![feature(range_is_empty)]
495-
///
496488
/// assert!(!(3.0..=5.0).is_empty());
497489
/// assert!( (3.0..=f32::NAN).is_empty());
498490
/// assert!( (f32::NAN..=5.0).is_empty());
@@ -501,14 +493,12 @@ impl<Idx: PartialOrd<Idx>> RangeInclusive<Idx> {
501493
/// This method returns `true` after iteration has finished:
502494
///
503495
/// ```
504-
/// #![feature(range_is_empty)]
505-
///
506496
/// let mut r = 3..=5;
507497
/// for _ in r.by_ref() {}
508498
/// // Precise field values are unspecified here
509499
/// assert!(r.is_empty());
510500
/// ```
511-
#[unstable(feature = "range_is_empty", reason = "recently added", issue = "48111")]
501+
#[stable(feature = "range_is_empty", since = "1.47.0")]
512502
#[inline]
513503
pub fn is_empty(&self) -> bool {
514504
self.exhausted || !(self.start <= self.end)

library/core/tests/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
#![feature(try_find)]
1818
#![feature(is_sorted)]
1919
#![feature(pattern)]
20-
#![feature(range_is_empty)]
2120
#![feature(raw)]
2221
#![feature(sort_internals)]
2322
#![feature(slice_partition_at_index)]

src/librustc_infer/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
#![feature(extend_one)]
2323
#![feature(never_type)]
2424
#![feature(or_patterns)]
25-
#![feature(range_is_empty)]
2625
#![feature(in_band_lifetimes)]
2726
#![feature(crate_visibility_modifier)]
2827
#![recursion_limit = "512"] // For rustdoc

src/librustc_middle/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@
4040
#![feature(nll)]
4141
#![feature(option_expect_none)]
4242
#![feature(or_patterns)]
43-
#![feature(range_is_empty)]
4443
#![feature(min_specialization)]
4544
#![feature(trusted_len)]
4645
#![feature(stmt_expr_attributes)]

src/librustc_mir/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ Rust MIR: a lowered representation of Rust.
2222
#![feature(try_blocks)]
2323
#![feature(associated_type_bounds)]
2424
#![feature(associated_type_defaults)]
25-
#![feature(range_is_empty)]
2625
#![feature(stmt_expr_attributes)]
2726
#![feature(trait_alias)]
2827
#![feature(option_expect_none)]

src/test/ui/range_inclusive.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
// run-pass
22
// Test inclusive range syntax.
3-
#![feature(range_is_empty)]
43
#![allow(unused_braces)]
54
#![allow(unused_comparisons)]
65

0 commit comments

Comments
 (0)