Skip to content

Commit 689f52e

Browse files
authored
Unrolled build for #154620
Rollup merge of #154620 - pitaj:stabilize-new_range_api, r=tgross35 stabilize new Range type and iterator For #125687 Stabilizes `core::range::Range` and `core::range::RangeIter`, newly stable API: ```rust // in core::range pub struct Range<Idx> { pub start: Idx, pub end: Idx, } impl<Idx: fmt::Debug> fmt::Debug for Range<Idx> { /* ... */ } impl<Idx: PartialOrd<Idx>> Range<Idx> { pub const fn contains<U>(&self, item: &U) -> bool where Idx: [const] PartialOrd<U>, U: ?Sized + [const] PartialOrd<Idx>; pub const fn is_empty(&self) -> bool where Idx: [const] PartialOrd; } impl<Idx: Step> Range<Idx> { pub fn iter(&self) -> RangeIter<Idx>; } impl<T> const RangeBounds<T> for Range<T> { /* ... */ } impl<T> const RangeBounds<T> for Range<&T> { /* ... */ } impl<T> const From<Range<T>> for legacy::Range<T> { /* ... */ } impl<T> const From<legacy::Range<T>> for Range<T> { /* ... */ } pub struct RangeIter<A>(/* ... */); // `RangeIter::remainder` not stabilized impl<A: Step> Iterator for RangeIter<A> { type Item = A; /* ... */ } impl<A: Step> DoubleEndedIterator for RangeIter<A> { /* ... */ } impl<A: Step> FusedIterator for RangeIter<A> { } impl<A: Step> IntoIterator for Range<A> { type Item = A; type IntoIter = RangeIter<A>; /* ... */ } impl ExactSizeIterator for RangeIter<u8> { } impl ExactSizeIterator for RangeIter<i8> { } unsafe impl<T> const SliceIndex<[T]> for range::Range<usize> { type Output = [T]; /* ... */ } unsafe impl const SliceIndex<str> for range::Range<usize> { type Output = str; /* ... */ } ``` Updates docs to reflect stabilization (removed "experimental")
2 parents ba11b1e + 620e92f commit 689f52e

File tree

13 files changed

+72
-79
lines changed

13 files changed

+72
-79
lines changed

compiler/rustc_index/src/lib.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,13 @@
22
#![cfg_attr(all(feature = "nightly", test), feature(stmt_expr_attributes))]
33
#![cfg_attr(all(feature = "nightly", test), feature(test))]
44
#![cfg_attr(feature = "nightly", feature(extend_one, step_trait))]
5-
#![cfg_attr(feature = "nightly", feature(new_range_api))]
65
// tidy-alphabetical-end
76

7+
// FIXME(#125687): new_range_api recently stabilized
8+
// Remove this when it hits stable. cfg(bootstrap)
9+
#![allow(stable_features)]
10+
#![cfg_attr(feature = "nightly", feature(new_range_api))]
11+
812
pub mod bit_set;
913
#[cfg(feature = "nightly")]
1014
pub mod interval;

library/core/src/range.rs

Lines changed: 24 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,26 @@
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
1918
use crate::fmt;
2019
use crate::hash::Hash;
2120

2221
mod iter;
2322

24-
#[unstable(feature = "new_range_api", issue = "125687")]
23+
#[unstable(feature = "new_range_api_legacy", issue = "125687")]
2524
pub 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")]
3231
pub use iter::RangeInclusiveIter;
3332
#[doc(inline)]
34-
#[unstable(feature = "new_range_api", issue = "125687")]
33+
#[stable(feature = "new_range_api", since = "CURRENT_RUSTC_VERSION")]
3534
pub 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")]
7068
pub 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")]
8078
impl<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")]
181175
impl<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")]
198192
impl<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")]
210203
impl<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")]
218211
impl<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")]
227219
impl<T> const From<legacy::Range<T>> for Range<T> {
228220
#[inline]

library/core/src/range/iter.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use crate::range::{Range, RangeFrom, RangeInclusive, legacy};
66
use crate::{intrinsics, mem};
77

88
/// By-value [`Range`] iterator.
9-
#[unstable(feature = "new_range_api", issue = "125687")]
9+
#[stable(feature = "new_range_api", since = "CURRENT_RUSTC_VERSION")]
1010
#[derive(Debug, Clone)]
1111
pub struct RangeIter<A>(legacy::Range<A>);
1212

@@ -17,7 +17,6 @@ impl<A> RangeIter<A> {
1717
/// # Examples
1818
///
1919
/// ```
20-
/// #![feature(new_range_api)]
2120
/// #![feature(new_range_remainder)]
2221
///
2322
/// let range = core::range::Range::from(3..11);
@@ -65,7 +64,7 @@ unsafe_range_trusted_random_access_impl! {
6564
u64 i64
6665
}
6766

68-
#[unstable(feature = "new_range_api", issue = "125687")]
67+
#[stable(feature = "new_range_api", since = "CURRENT_RUSTC_VERSION")]
6968
impl<A: Step> Iterator for RangeIter<A> {
7069
type Item = A;
7170

@@ -133,7 +132,7 @@ impl<A: Step> Iterator for RangeIter<A> {
133132
}
134133
}
135134

136-
#[unstable(feature = "new_range_api", issue = "125687")]
135+
#[stable(feature = "new_range_api", since = "CURRENT_RUSTC_VERSION")]
137136
impl<A: Step> DoubleEndedIterator for RangeIter<A> {
138137
#[inline]
139138
fn next_back(&mut self) -> Option<A> {
@@ -154,10 +153,10 @@ impl<A: Step> DoubleEndedIterator for RangeIter<A> {
154153
#[unstable(feature = "trusted_len", issue = "37572")]
155154
unsafe impl<A: TrustedStep> TrustedLen for RangeIter<A> {}
156155

157-
#[unstable(feature = "new_range_api", issue = "125687")]
156+
#[stable(feature = "new_range_api", since = "CURRENT_RUSTC_VERSION")]
158157
impl<A: Step> FusedIterator for RangeIter<A> {}
159158

160-
#[unstable(feature = "new_range_api", issue = "125687")]
159+
#[stable(feature = "new_range_api", since = "CURRENT_RUSTC_VERSION")]
161160
impl<A: Step> IntoIterator for Range<A> {
162161
type Item = A;
163162
type IntoIter = RangeIter<A>;
@@ -300,7 +299,7 @@ impl<A: Step> IntoIterator for RangeInclusive<A> {
300299
// since e.g. `(0..=u64::MAX).len()` would be `u64::MAX + 1`.
301300
macro_rules! range_exact_iter_impl {
302301
($($t:ty)*) => ($(
303-
#[unstable(feature = "new_range_api", issue = "125687")]
302+
#[stable(feature = "new_range_api", since = "CURRENT_RUSTC_VERSION")]
304303
impl ExactSizeIterator for RangeIter<$t> { }
305304
)*)
306305
}

library/core/src/slice/index.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ mod private_slice_index {
125125
#[stable(feature = "slice_index_with_ops_bound_pair", since = "1.53.0")]
126126
impl Sealed for (ops::Bound<usize>, ops::Bound<usize>) {}
127127

128-
#[unstable(feature = "new_range_api", issue = "125687")]
128+
#[stable(feature = "new_range_api", since = "CURRENT_RUSTC_VERSION")]
129129
impl Sealed for range::Range<usize> {}
130130
#[stable(feature = "new_range_inclusive_api", since = "1.95.0")]
131131
impl Sealed for range::RangeInclusive<usize> {}
@@ -458,7 +458,7 @@ unsafe impl<T> const SliceIndex<[T]> for ops::Range<usize> {
458458
}
459459
}
460460

461-
#[unstable(feature = "new_range_api", issue = "125687")]
461+
#[stable(feature = "new_range_api", since = "CURRENT_RUSTC_VERSION")]
462462
#[rustc_const_unstable(feature = "const_index", issue = "143775")]
463463
unsafe impl<T> const SliceIndex<[T]> for range::Range<usize> {
464464
type Output = [T];

library/core/src/str/traits.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ unsafe impl const SliceIndex<str> for ops::Range<usize> {
258258
}
259259
}
260260

261-
#[unstable(feature = "new_range_api", issue = "125687")]
261+
#[stable(feature = "new_range_api", since = "CURRENT_RUSTC_VERSION")]
262262
#[rustc_const_unstable(feature = "const_index", issue = "143775")]
263263
unsafe impl const SliceIndex<str> for range::Range<usize> {
264264
type Output = str;

library/coretests/tests/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@
8585
#![feature(maybe_uninit_uninit_array_transpose)]
8686
#![feature(min_specialization)]
8787
#![feature(never_type)]
88-
#![feature(new_range_api)]
8988
#![feature(next_index)]
9089
#![feature(non_exhaustive_omitted_patterns_lint)]
9190
#![feature(nonzero_from_str_radix)]

library/std/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -537,7 +537,7 @@ pub use core::option;
537537
pub use core::pin;
538538
#[stable(feature = "rust1", since = "1.0.0")]
539539
pub use core::ptr;
540-
#[unstable(feature = "new_range_api", issue = "125687")]
540+
#[stable(feature = "new_range_api", since = "CURRENT_RUSTC_VERSION")]
541541
pub use core::range;
542542
#[stable(feature = "rust1", since = "1.0.0")]
543543
pub use core::result;

tests/ui/feature-gates/feature-gate-new_range.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#![feature(new_range_api)]
2-
31
fn main() {
42
let a: core::range::RangeFrom<u8> = 1..;
53
//~^ ERROR mismatched types

tests/ui/feature-gates/feature-gate-new_range.stderr

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0308]: mismatched types
2-
--> $DIR/feature-gate-new_range.rs:4:41
2+
--> $DIR/feature-gate-new_range.rs:2:41
33
|
44
LL | let a: core::range::RangeFrom<u8> = 1..;
55
| -------------------------- ^^^ expected `RangeFrom<u8>`, found `RangeFrom<{integer}>`
@@ -14,7 +14,7 @@ LL | let a: core::range::RangeFrom<u8> = (1..).into();
1414
| + ++++++++
1515

1616
error[E0308]: mismatched types
17-
--> $DIR/feature-gate-new_range.rs:6:37
17+
--> $DIR/feature-gate-new_range.rs:4:37
1818
|
1919
LL | let b: core::range::Range<u8> = 2..3;
2020
| ---------------------- ^^^^ expected `Range<u8>`, found `Range<{integer}>`
@@ -29,7 +29,7 @@ LL | let b: core::range::Range<u8> = (2..3).into();
2929
| + ++++++++
3030

3131
error[E0308]: mismatched types
32-
--> $DIR/feature-gate-new_range.rs:8:46
32+
--> $DIR/feature-gate-new_range.rs:6:46
3333
|
3434
LL | let c: core::range::RangeInclusive<u8> = 4..=5;
3535
| ------------------------------- ^^^^^ expected `RangeInclusive<u8>`, found `RangeInclusive<{integer}>`

tests/ui/new-range/disabled.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//@ check-pass
22

3-
#![feature(new_range_api)]
3+
#![feature(new_range_api_legacy)]
44

55
fn main() {
66
// Unchanged

0 commit comments

Comments
 (0)