From c20ad72323a17bd020f2fea7b8decf93e067c161 Mon Sep 17 00:00:00 2001 From: Scott McMurray Date: Mon, 3 Aug 2020 23:18:34 -0700 Subject: [PATCH] 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 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 --- library/core/src/ops/range.rs | 14 ++------------ library/core/tests/lib.rs | 1 - src/librustc_infer/lib.rs | 1 - src/librustc_middle/lib.rs | 1 - src/librustc_mir/lib.rs | 1 - src/test/ui/range_inclusive.rs | 1 - 6 files changed, 2 insertions(+), 17 deletions(-) diff --git a/library/core/src/ops/range.rs b/library/core/src/ops/range.rs index ccabd66aaf6eb..d10829832dd16 100644 --- a/library/core/src/ops/range.rs +++ b/library/core/src/ops/range.rs @@ -125,8 +125,6 @@ impl> Range { /// # Examples /// /// ``` - /// #![feature(range_is_empty)] - /// /// assert!(!(3..5).is_empty()); /// assert!( (3..3).is_empty()); /// assert!( (3..2).is_empty()); @@ -135,13 +133,11 @@ impl> Range { /// The range is empty if either side is incomparable: /// /// ``` - /// #![feature(range_is_empty)] - /// /// assert!(!(3.0..5.0).is_empty()); /// assert!( (3.0..f32::NAN).is_empty()); /// assert!( (f32::NAN..5.0).is_empty()); /// ``` - #[unstable(feature = "range_is_empty", reason = "recently added", issue = "48111")] + #[stable(feature = "range_is_empty", since = "1.47.0")] pub fn is_empty(&self) -> bool { !(self.start < self.end) } @@ -481,8 +477,6 @@ impl> RangeInclusive { /// # Examples /// /// ``` - /// #![feature(range_is_empty)] - /// /// assert!(!(3..=5).is_empty()); /// assert!(!(3..=3).is_empty()); /// assert!( (3..=2).is_empty()); @@ -491,8 +485,6 @@ impl> RangeInclusive { /// The range is empty if either side is incomparable: /// /// ``` - /// #![feature(range_is_empty)] - /// /// assert!(!(3.0..=5.0).is_empty()); /// assert!( (3.0..=f32::NAN).is_empty()); /// assert!( (f32::NAN..=5.0).is_empty()); @@ -501,14 +493,12 @@ impl> RangeInclusive { /// This method returns `true` after iteration has finished: /// /// ``` - /// #![feature(range_is_empty)] - /// /// let mut r = 3..=5; /// for _ in r.by_ref() {} /// // Precise field values are unspecified here /// assert!(r.is_empty()); /// ``` - #[unstable(feature = "range_is_empty", reason = "recently added", issue = "48111")] + #[stable(feature = "range_is_empty", since = "1.47.0")] #[inline] pub fn is_empty(&self) -> bool { self.exhausted || !(self.start <= self.end) diff --git a/library/core/tests/lib.rs b/library/core/tests/lib.rs index 904e3f7284049..81e621318e141 100644 --- a/library/core/tests/lib.rs +++ b/library/core/tests/lib.rs @@ -17,7 +17,6 @@ #![feature(try_find)] #![feature(is_sorted)] #![feature(pattern)] -#![feature(range_is_empty)] #![feature(raw)] #![feature(sort_internals)] #![feature(slice_partition_at_index)] diff --git a/src/librustc_infer/lib.rs b/src/librustc_infer/lib.rs index f135bde7f8337..e05041d88460e 100644 --- a/src/librustc_infer/lib.rs +++ b/src/librustc_infer/lib.rs @@ -22,7 +22,6 @@ #![feature(extend_one)] #![feature(never_type)] #![feature(or_patterns)] -#![feature(range_is_empty)] #![feature(in_band_lifetimes)] #![feature(crate_visibility_modifier)] #![recursion_limit = "512"] // For rustdoc diff --git a/src/librustc_middle/lib.rs b/src/librustc_middle/lib.rs index ec1dcd29ef2d8..1b2dea8a378c3 100644 --- a/src/librustc_middle/lib.rs +++ b/src/librustc_middle/lib.rs @@ -40,7 +40,6 @@ #![feature(nll)] #![feature(option_expect_none)] #![feature(or_patterns)] -#![feature(range_is_empty)] #![feature(min_specialization)] #![feature(trusted_len)] #![feature(stmt_expr_attributes)] diff --git a/src/librustc_mir/lib.rs b/src/librustc_mir/lib.rs index 3118e7ac3ab17..2e3b508463540 100644 --- a/src/librustc_mir/lib.rs +++ b/src/librustc_mir/lib.rs @@ -22,7 +22,6 @@ Rust MIR: a lowered representation of Rust. #![feature(try_blocks)] #![feature(associated_type_bounds)] #![feature(associated_type_defaults)] -#![feature(range_is_empty)] #![feature(stmt_expr_attributes)] #![feature(trait_alias)] #![feature(option_expect_none)] diff --git a/src/test/ui/range_inclusive.rs b/src/test/ui/range_inclusive.rs index 540b35e0392de..7e7a15924b765 100644 --- a/src/test/ui/range_inclusive.rs +++ b/src/test/ui/range_inclusive.rs @@ -1,6 +1,5 @@ // run-pass // Test inclusive range syntax. -#![feature(range_is_empty)] #![allow(unused_braces)] #![allow(unused_comparisons)]