1- //! # Experimental replacement range types
1+ //! # Replacement range types
22//!
3- //! The types within this module are meant to replace the existing
4- //! `Range `, `RangeInclusive`, and `RangeFrom` types in a future edition.
3+ //! The types within this module are meant to replace the legacy `Range`,
4+ //! `RangeInclusive `, `RangeToInclusive` and `RangeFrom` types in a future edition.
55//!
66//! ```
7- //! #![feature(new_range_api)]
8- //! use core::range::{Range, RangeFrom, RangeInclusive};
7+ //! use core::range::{Range, RangeFrom, RangeInclusive, RangeToInclusive};
98//!
109//! let arr = [0, 1, 2, 3, 4];
11- //! assert_eq!(arr[ .. ], [0, 1, 2, 3, 4]);
12- //! assert_eq!(arr[ .. 3 ], [0, 1, 2 ]);
13- //! assert_eq!(arr[ ..=3 ], [0, 1, 2, 3 ]);
14- //! assert_eq!(arr[ RangeFrom::from(1.. )], [ 1, 2, 3, 4]);
15- //! assert_eq!(arr[ Range::from(1..3 )], [ 1, 2 ]);
16- //! assert_eq!(arr[RangeInclusive::from(1..=3)], [ 1, 2, 3 ]);
10+ //! assert_eq!(arr[ .. ], [0, 1, 2, 3, 4]);
11+ //! assert_eq!(arr[ .. 3 ], [0, 1, 2 ]);
12+ //! assert_eq!(arr[RangeToInclusive::from( ..=3) ], [0, 1, 2, 3 ]);
13+ //! assert_eq!(arr[ RangeFrom::from(1.. )], [ 1, 2, 3, 4]);
14+ //! assert_eq!(arr[ Range::from(1..3 )], [ 1, 2 ]);
15+ //! assert_eq!(arr[ RangeInclusive::from(1..=3)], [ 1, 2, 3 ]);
1716//! ```
1817
1918use crate :: fmt;
2019use crate :: hash:: Hash ;
2120
2221mod iter;
2322
24- #[ unstable( feature = "new_range_api " , issue = "125687" ) ]
23+ #[ unstable( feature = "new_range_api_legacy " , issue = "125687" ) ]
2524pub mod legacy;
2625
2726#[ doc( inline) ]
@@ -31,7 +30,7 @@ pub use iter::RangeFromIter;
3130#[ stable( feature = "new_range_inclusive_api" , since = "1.95.0" ) ]
3231pub use iter:: RangeInclusiveIter ;
3332#[ doc( inline) ]
34- #[ unstable ( feature = "new_range_api" , issue = "125687 " ) ]
33+ #[ stable ( feature = "new_range_api" , since = "CURRENT_RUSTC_VERSION " ) ]
3534pub use iter:: RangeIter ;
3635
3736// FIXME(#125687): re-exports temporarily removed
@@ -57,7 +56,6 @@ use crate::ops::{IntoBounds, OneSidedRange, OneSidedRangeBound, RangeBounds};
5756/// # Examples
5857///
5958/// ```
60- /// #![feature(new_range_api)]
6159/// use core::range::Range;
6260///
6361/// assert_eq!(Range::from(3..5), Range { start: 3, end: 5 });
@@ -66,17 +64,17 @@ use crate::ops::{IntoBounds, OneSidedRange, OneSidedRangeBound, RangeBounds};
6664#[ lang = "RangeCopy" ]
6765#[ derive( Copy , Hash ) ]
6866#[ derive_const( Clone , Default , PartialEq , Eq ) ]
69- #[ unstable ( feature = "new_range_api" , issue = "125687 " ) ]
67+ #[ stable ( feature = "new_range_api" , since = "CURRENT_RUSTC_VERSION " ) ]
7068pub struct Range < Idx > {
7169 /// The lower bound of the range (inclusive).
72- #[ unstable ( feature = "new_range_api" , issue = "125687 " ) ]
70+ #[ stable ( feature = "new_range_api" , since = "CURRENT_RUSTC_VERSION " ) ]
7371 pub start : Idx ,
7472 /// The upper bound of the range (exclusive).
75- #[ unstable ( feature = "new_range_api" , issue = "125687 " ) ]
73+ #[ stable ( feature = "new_range_api" , since = "CURRENT_RUSTC_VERSION " ) ]
7674 pub end : Idx ,
7775}
7876
79- #[ unstable ( feature = "new_range_api" , issue = "125687 " ) ]
77+ #[ stable ( feature = "new_range_api" , since = "CURRENT_RUSTC_VERSION " ) ]
8078impl < Idx : fmt:: Debug > fmt:: Debug for Range < Idx > {
8179 fn fmt ( & self , fmt : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
8280 self . start . fmt ( fmt) ?;
@@ -94,15 +92,14 @@ impl<Idx: Step> Range<Idx> {
9492 /// # Examples
9593 ///
9694 /// ```
97- /// #![feature(new_range_api)]
9895 /// use core::range::Range;
9996 ///
10097 /// let mut i = Range::from(3..9).iter().map(|n| n*n);
10198 /// assert_eq!(i.next(), Some(9));
10299 /// assert_eq!(i.next(), Some(16));
103100 /// assert_eq!(i.next(), Some(25));
104101 /// ```
105- #[ unstable ( feature = "new_range_api" , issue = "125687 " ) ]
102+ #[ stable ( feature = "new_range_api" , since = "CURRENT_RUSTC_VERSION " ) ]
106103 #[ inline]
107104 pub fn iter ( & self ) -> RangeIter < Idx > {
108105 self . clone ( ) . into_iter ( )
@@ -115,7 +112,6 @@ impl<Idx: PartialOrd<Idx>> Range<Idx> {
115112 /// # Examples
116113 ///
117114 /// ```
118- /// #![feature(new_range_api)]
119115 /// use core::range::Range;
120116 ///
121117 /// assert!(!Range::from(3..5).contains(&2));
@@ -132,7 +128,7 @@ impl<Idx: PartialOrd<Idx>> Range<Idx> {
132128 /// assert!(!Range::from(f32::NAN..1.0).contains(&0.5));
133129 /// ```
134130 #[ inline]
135- #[ unstable ( feature = "new_range_api" , issue = "125687 " ) ]
131+ #[ stable ( feature = "new_range_api" , since = "CURRENT_RUSTC_VERSION " ) ]
136132 #[ rustc_const_unstable( feature = "const_range" , issue = "none" ) ]
137133 pub const fn contains < U > ( & self , item : & U ) -> bool
138134 where
@@ -147,7 +143,6 @@ impl<Idx: PartialOrd<Idx>> Range<Idx> {
147143 /// # Examples
148144 ///
149145 /// ```
150- /// #![feature(new_range_api)]
151146 /// use core::range::Range;
152147 ///
153148 /// assert!(!Range::from(3..5).is_empty());
@@ -158,15 +153,14 @@ impl<Idx: PartialOrd<Idx>> Range<Idx> {
158153 /// The range is empty if either side is incomparable:
159154 ///
160155 /// ```
161- /// #![feature(new_range_api)]
162156 /// use core::range::Range;
163157 ///
164158 /// assert!(!Range::from(3.0..5.0).is_empty());
165159 /// assert!( Range::from(3.0..f32::NAN).is_empty());
166160 /// assert!( Range::from(f32::NAN..5.0).is_empty());
167161 /// ```
168162 #[ inline]
169- #[ unstable ( feature = "new_range_api" , issue = "125687 " ) ]
163+ #[ stable ( feature = "new_range_api" , since = "CURRENT_RUSTC_VERSION " ) ]
170164 #[ rustc_const_unstable( feature = "const_range" , issue = "none" ) ]
171165 pub const fn is_empty ( & self ) -> bool
172166 where
@@ -176,7 +170,7 @@ impl<Idx: PartialOrd<Idx>> Range<Idx> {
176170 }
177171}
178172
179- #[ unstable ( feature = "new_range_api" , issue = "125687 " ) ]
173+ #[ stable ( feature = "new_range_api" , since = "CURRENT_RUSTC_VERSION " ) ]
180174#[ rustc_const_unstable( feature = "const_range" , issue = "none" ) ]
181175impl < T > const RangeBounds < T > for Range < T > {
182176 fn start_bound ( & self ) -> Bound < & T > {
@@ -193,7 +187,7 @@ impl<T> const RangeBounds<T> for Range<T> {
193187/// If you need to use this implementation where `T` is unsized,
194188/// consider using the `RangeBounds` impl for a 2-tuple of [`Bound<&T>`][Bound],
195189/// i.e. replace `start..end` with `(Bound::Included(start), Bound::Excluded(end))`.
196- #[ unstable ( feature = "new_range_api" , issue = "125687 " ) ]
190+ #[ stable ( feature = "new_range_api" , since = "CURRENT_RUSTC_VERSION " ) ]
197191#[ rustc_const_unstable( feature = "const_range" , issue = "none" ) ]
198192impl < T > const RangeBounds < T > for Range < & T > {
199193 fn start_bound ( & self ) -> Bound < & T > {
@@ -204,25 +198,23 @@ impl<T> const RangeBounds<T> for Range<&T> {
204198 }
205199}
206200
207- // #[unstable(feature = "range_into_bounds", issue = "136903")]
208- #[ unstable( feature = "new_range_api" , issue = "125687" ) ]
201+ #[ unstable( feature = "range_into_bounds" , issue = "136903" ) ]
209202#[ rustc_const_unstable( feature = "const_range" , issue = "none" ) ]
210203impl < T > const IntoBounds < T > for Range < T > {
211204 fn into_bounds ( self ) -> ( Bound < T > , Bound < T > ) {
212205 ( Included ( self . start ) , Excluded ( self . end ) )
213206 }
214207}
215208
216- #[ unstable ( feature = "new_range_api" , issue = "125687 " ) ]
209+ #[ stable ( feature = "new_range_api" , since = "CURRENT_RUSTC_VERSION " ) ]
217210#[ rustc_const_unstable( feature = "const_convert" , issue = "143773" ) ]
218211impl < T > const From < Range < T > > for legacy:: Range < T > {
219212 #[ inline]
220213 fn from ( value : Range < T > ) -> Self {
221214 Self { start : value. start , end : value. end }
222215 }
223216}
224-
225- #[ unstable( feature = "new_range_api" , issue = "125687" ) ]
217+ #[ stable( feature = "new_range_api" , since = "CURRENT_RUSTC_VERSION" ) ]
226218#[ rustc_const_unstable( feature = "const_convert" , issue = "143773" ) ]
227219impl < T > const From < legacy:: Range < T > > for Range < T > {
228220 #[ inline]
0 commit comments