Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion compiler/rustc_index/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@
#![cfg_attr(all(feature = "nightly", test), feature(stmt_expr_attributes))]
#![cfg_attr(all(feature = "nightly", test), feature(test))]
#![cfg_attr(feature = "nightly", feature(extend_one, step_trait))]
#![cfg_attr(feature = "nightly", feature(new_range_api))]
// tidy-alphabetical-end

// FIXME(#125687): new_range_api recently stabilized
// Remove this when it hits stable. cfg(bootstrap)
#![allow(stable_features)]
#![cfg_attr(feature = "nightly", feature(new_range_api))]
Comment on lines +7 to +10
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Put cfg(bootstrap) in the comment here because (aiui) that's what the release team greps for when they do cfg cleanup with bootstrap bumps.


pub mod bit_set;
#[cfg(feature = "nightly")]
pub mod interval;
Expand Down
56 changes: 24 additions & 32 deletions library/core/src/range.rs
Original file line number Diff line number Diff line change
@@ -1,27 +1,26 @@
//! # Experimental replacement range types
//! # Replacement range types
//!
//! The types within this module are meant to replace the existing
//! `Range`, `RangeInclusive`, and `RangeFrom` types in a future edition.
//! The types within this module are meant to replace the legacy `Range`,
//! `RangeInclusive`, `RangeToInclusive` and `RangeFrom` types in a future edition.
//!
//! ```
//! #![feature(new_range_api)]
//! use core::range::{Range, RangeFrom, RangeInclusive};
//! use core::range::{Range, RangeFrom, RangeInclusive, RangeToInclusive};
//!
//! let arr = [0, 1, 2, 3, 4];
//! assert_eq!(arr[ .. ], [0, 1, 2, 3, 4]);
//! assert_eq!(arr[ .. 3 ], [0, 1, 2 ]);
//! assert_eq!(arr[ ..=3 ], [0, 1, 2, 3 ]);
//! assert_eq!(arr[ RangeFrom::from(1.. )], [ 1, 2, 3, 4]);
//! assert_eq!(arr[ Range::from(1..3 )], [ 1, 2 ]);
//! assert_eq!(arr[RangeInclusive::from(1..=3)], [ 1, 2, 3 ]);
//! assert_eq!(arr[ .. ], [0, 1, 2, 3, 4]);
//! assert_eq!(arr[ .. 3 ], [0, 1, 2 ]);
//! assert_eq!(arr[RangeToInclusive::from( ..=3)], [0, 1, 2, 3 ]);
//! assert_eq!(arr[ RangeFrom::from(1.. )], [ 1, 2, 3, 4]);
//! assert_eq!(arr[ Range::from(1..3 )], [ 1, 2 ]);
//! assert_eq!(arr[ RangeInclusive::from(1..=3)], [ 1, 2, 3 ]);
//! ```

use crate::fmt;
use crate::hash::Hash;

mod iter;

#[unstable(feature = "new_range_api", issue = "125687")]
#[unstable(feature = "new_range_api_legacy", issue = "125687")]
pub mod legacy;

#[doc(inline)]
Expand All @@ -31,7 +30,7 @@ pub use iter::RangeFromIter;
#[stable(feature = "new_range_inclusive_api", since = "1.95.0")]
pub use iter::RangeInclusiveIter;
#[doc(inline)]
#[unstable(feature = "new_range_api", issue = "125687")]
#[stable(feature = "new_range_api", since = "CURRENT_RUSTC_VERSION")]
pub use iter::RangeIter;

// FIXME(#125687): re-exports temporarily removed
Expand All @@ -57,7 +56,6 @@ use crate::ops::{IntoBounds, OneSidedRange, OneSidedRangeBound, RangeBounds};
/// # Examples
///
/// ```
/// #![feature(new_range_api)]
/// use core::range::Range;
///
/// assert_eq!(Range::from(3..5), Range { start: 3, end: 5 });
Expand All @@ -66,17 +64,17 @@ use crate::ops::{IntoBounds, OneSidedRange, OneSidedRangeBound, RangeBounds};
#[lang = "RangeCopy"]
#[derive(Copy, Hash)]
#[derive_const(Clone, Default, PartialEq, Eq)]
#[unstable(feature = "new_range_api", issue = "125687")]
#[stable(feature = "new_range_api", since = "CURRENT_RUSTC_VERSION")]
pub struct Range<Idx> {
/// The lower bound of the range (inclusive).
#[unstable(feature = "new_range_api", issue = "125687")]
#[stable(feature = "new_range_api", since = "CURRENT_RUSTC_VERSION")]
pub start: Idx,
/// The upper bound of the range (exclusive).
#[unstable(feature = "new_range_api", issue = "125687")]
#[stable(feature = "new_range_api", since = "CURRENT_RUSTC_VERSION")]
pub end: Idx,
}

#[unstable(feature = "new_range_api", issue = "125687")]
#[stable(feature = "new_range_api", since = "CURRENT_RUSTC_VERSION")]
impl<Idx: fmt::Debug> fmt::Debug for Range<Idx> {
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
self.start.fmt(fmt)?;
Expand All @@ -94,15 +92,14 @@ impl<Idx: Step> Range<Idx> {
/// # Examples
///
/// ```
/// #![feature(new_range_api)]
/// use core::range::Range;
///
/// let mut i = Range::from(3..9).iter().map(|n| n*n);
/// assert_eq!(i.next(), Some(9));
/// assert_eq!(i.next(), Some(16));
/// assert_eq!(i.next(), Some(25));
/// ```
#[unstable(feature = "new_range_api", issue = "125687")]
#[stable(feature = "new_range_api", since = "CURRENT_RUSTC_VERSION")]
#[inline]
pub fn iter(&self) -> RangeIter<Idx> {
self.clone().into_iter()
Expand All @@ -115,7 +112,6 @@ impl<Idx: PartialOrd<Idx>> Range<Idx> {
/// # Examples
///
/// ```
/// #![feature(new_range_api)]
/// use core::range::Range;
///
/// assert!(!Range::from(3..5).contains(&2));
Expand All @@ -132,7 +128,7 @@ impl<Idx: PartialOrd<Idx>> Range<Idx> {
/// assert!(!Range::from(f32::NAN..1.0).contains(&0.5));
/// ```
#[inline]
#[unstable(feature = "new_range_api", issue = "125687")]
#[stable(feature = "new_range_api", since = "CURRENT_RUSTC_VERSION")]
#[rustc_const_unstable(feature = "const_range", issue = "none")]
pub const fn contains<U>(&self, item: &U) -> bool
where
Expand All @@ -147,7 +143,6 @@ impl<Idx: PartialOrd<Idx>> Range<Idx> {
/// # Examples
///
/// ```
/// #![feature(new_range_api)]
/// use core::range::Range;
///
/// assert!(!Range::from(3..5).is_empty());
Expand All @@ -158,15 +153,14 @@ impl<Idx: PartialOrd<Idx>> Range<Idx> {
/// The range is empty if either side is incomparable:
///
/// ```
/// #![feature(new_range_api)]
/// use core::range::Range;
///
/// assert!(!Range::from(3.0..5.0).is_empty());
/// assert!( Range::from(3.0..f32::NAN).is_empty());
/// assert!( Range::from(f32::NAN..5.0).is_empty());
/// ```
#[inline]
#[unstable(feature = "new_range_api", issue = "125687")]
#[stable(feature = "new_range_api", since = "CURRENT_RUSTC_VERSION")]
#[rustc_const_unstable(feature = "const_range", issue = "none")]
pub const fn is_empty(&self) -> bool
where
Expand All @@ -176,7 +170,7 @@ impl<Idx: PartialOrd<Idx>> Range<Idx> {
}
}

#[unstable(feature = "new_range_api", issue = "125687")]
#[stable(feature = "new_range_api", since = "CURRENT_RUSTC_VERSION")]
#[rustc_const_unstable(feature = "const_range", issue = "none")]
impl<T> const RangeBounds<T> for Range<T> {
fn start_bound(&self) -> Bound<&T> {
Expand All @@ -193,7 +187,7 @@ impl<T> const RangeBounds<T> for Range<T> {
/// If you need to use this implementation where `T` is unsized,
/// consider using the `RangeBounds` impl for a 2-tuple of [`Bound<&T>`][Bound],
/// i.e. replace `start..end` with `(Bound::Included(start), Bound::Excluded(end))`.
#[unstable(feature = "new_range_api", issue = "125687")]
#[stable(feature = "new_range_api", since = "CURRENT_RUSTC_VERSION")]
#[rustc_const_unstable(feature = "const_range", issue = "none")]
impl<T> const RangeBounds<T> for Range<&T> {
fn start_bound(&self) -> Bound<&T> {
Expand All @@ -204,25 +198,23 @@ impl<T> const RangeBounds<T> for Range<&T> {
}
}

// #[unstable(feature = "range_into_bounds", issue = "136903")]
#[unstable(feature = "new_range_api", issue = "125687")]
#[unstable(feature = "range_into_bounds", issue = "136903")]
#[rustc_const_unstable(feature = "const_range", issue = "none")]
impl<T> const IntoBounds<T> for Range<T> {
fn into_bounds(self) -> (Bound<T>, Bound<T>) {
(Included(self.start), Excluded(self.end))
}
}

#[unstable(feature = "new_range_api", issue = "125687")]
#[stable(feature = "new_range_api", since = "CURRENT_RUSTC_VERSION")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl<T> const From<Range<T>> for legacy::Range<T> {
#[inline]
fn from(value: Range<T>) -> Self {
Self { start: value.start, end: value.end }
}
}

#[unstable(feature = "new_range_api", issue = "125687")]
#[stable(feature = "new_range_api", since = "CURRENT_RUSTC_VERSION")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl<T> const From<legacy::Range<T>> for Range<T> {
#[inline]
Expand Down
13 changes: 6 additions & 7 deletions library/core/src/range/iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::range::{Range, RangeFrom, RangeInclusive, legacy};
use crate::{intrinsics, mem};

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

Expand All @@ -17,7 +17,6 @@ impl<A> RangeIter<A> {
/// # Examples
///
/// ```
/// #![feature(new_range_api)]
/// #![feature(new_range_remainder)]
///
/// let range = core::range::Range::from(3..11);
Expand Down Expand Up @@ -65,7 +64,7 @@ unsafe_range_trusted_random_access_impl! {
u64 i64
}

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

Expand Down Expand Up @@ -133,7 +132,7 @@ impl<A: Step> Iterator for RangeIter<A> {
}
}

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

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

#[unstable(feature = "new_range_api", issue = "125687")]
#[stable(feature = "new_range_api", since = "CURRENT_RUSTC_VERSION")]
impl<A: Step> IntoIterator for Range<A> {
type Item = A;
type IntoIter = RangeIter<A>;
Expand Down Expand Up @@ -300,7 +299,7 @@ impl<A: Step> IntoIterator for RangeInclusive<A> {
// since e.g. `(0..=u64::MAX).len()` would be `u64::MAX + 1`.
macro_rules! range_exact_iter_impl {
($($t:ty)*) => ($(
#[unstable(feature = "new_range_api", issue = "125687")]
#[stable(feature = "new_range_api", since = "CURRENT_RUSTC_VERSION")]
impl ExactSizeIterator for RangeIter<$t> { }
)*)
}
Expand Down
4 changes: 2 additions & 2 deletions library/core/src/slice/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ mod private_slice_index {
#[stable(feature = "slice_index_with_ops_bound_pair", since = "1.53.0")]
impl Sealed for (ops::Bound<usize>, ops::Bound<usize>) {}

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

#[unstable(feature = "new_range_api", issue = "125687")]
#[stable(feature = "new_range_api", since = "CURRENT_RUSTC_VERSION")]
#[rustc_const_unstable(feature = "const_index", issue = "143775")]
unsafe impl<T> const SliceIndex<[T]> for range::Range<usize> {
type Output = [T];
Expand Down
2 changes: 1 addition & 1 deletion library/core/src/str/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ unsafe impl const SliceIndex<str> for ops::Range<usize> {
}
}

#[unstable(feature = "new_range_api", issue = "125687")]
#[stable(feature = "new_range_api", since = "CURRENT_RUSTC_VERSION")]
#[rustc_const_unstable(feature = "const_index", issue = "143775")]
unsafe impl const SliceIndex<str> for range::Range<usize> {
type Output = str;
Expand Down
1 change: 0 additions & 1 deletion library/coretests/tests/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@
#![feature(maybe_uninit_uninit_array_transpose)]
#![feature(min_specialization)]
#![feature(never_type)]
#![feature(new_range_api)]
#![feature(next_index)]
#![feature(non_exhaustive_omitted_patterns_lint)]
#![feature(nonzero_from_str_radix)]
Expand Down
2 changes: 1 addition & 1 deletion library/std/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,7 @@ pub use core::option;
pub use core::pin;
#[stable(feature = "rust1", since = "1.0.0")]
pub use core::ptr;
#[unstable(feature = "new_range_api", issue = "125687")]
#[stable(feature = "new_range_api", since = "CURRENT_RUSTC_VERSION")]
pub use core::range;
#[stable(feature = "rust1", since = "1.0.0")]
pub use core::result;
Expand Down
2 changes: 0 additions & 2 deletions tests/ui/feature-gates/feature-gate-new_range.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#![feature(new_range_api)]

fn main() {
let a: core::range::RangeFrom<u8> = 1..;
//~^ ERROR mismatched types
Expand Down
6 changes: 3 additions & 3 deletions tests/ui/feature-gates/feature-gate-new_range.stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error[E0308]: mismatched types
--> $DIR/feature-gate-new_range.rs:4:41
--> $DIR/feature-gate-new_range.rs:2:41
|
LL | let a: core::range::RangeFrom<u8> = 1..;
| -------------------------- ^^^ expected `RangeFrom<u8>`, found `RangeFrom<{integer}>`
Expand All @@ -14,7 +14,7 @@ LL | let a: core::range::RangeFrom<u8> = (1..).into();
| + ++++++++

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

error[E0308]: mismatched types
--> $DIR/feature-gate-new_range.rs:8:46
--> $DIR/feature-gate-new_range.rs:6:46
|
LL | let c: core::range::RangeInclusive<u8> = 4..=5;
| ------------------------------- ^^^^^ expected `RangeInclusive<u8>`, found `RangeInclusive<{integer}>`
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/new-range/disabled.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//@ check-pass

#![feature(new_range_api)]
#![feature(new_range_api_legacy)]

fn main() {
// Unchanged
Expand Down
1 change: 0 additions & 1 deletion tests/ui/new-range/enabled.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
//@ check-pass

#![feature(new_range_api)]
#![feature(new_range)]

fn main() {
Expand Down
22 changes: 17 additions & 5 deletions tests/ui/range/new_range_stability.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use std::range::{
RangeToInclusive,
RangeFrom,
RangeFromIter,
Range,
};

fn range_inclusive(mut r: RangeInclusive<usize>) {
Expand Down Expand Up @@ -43,13 +44,24 @@ fn range_from(mut r: RangeFrom<usize>) {
i.remainder(); //~ ERROR unstable
}

// Unstable module
fn range(mut r: Range<usize>) {
&[1, 2, 3][r];

use std::range::legacy; //~ ERROR unstable
r.start;
r.end;
r.contains(&5);
r.is_empty();
r.iter();

// Unstable types
let mut i = r.into_iter();
i.next();

use std::range::Range; //~ ERROR unstable
use std::range::RangeIter; //~ ERROR unstable
// Left unstable
i.remainder(); //~ ERROR unstable
}

// Unstable module

use std::range::legacy; //~ ERROR unstable

fn main() {}
Loading
Loading