Skip to content
Open
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
19 changes: 9 additions & 10 deletions library/core/src/range.rs
Original file line number Diff line number Diff line change
Expand Up @@ -582,9 +582,8 @@ impl<T> const From<legacy::RangeFrom<T>> for RangeFrom<T> {
/// The `..=last` syntax is a `RangeToInclusive`:
///
/// ```
/// #![feature(new_range_api)]
/// #![feature(new_range)]
/// assert_eq!((..=5), std::range::RangeToInclusive{ last: 5 });
/// assert_eq!((..=5), std::range::RangeToInclusive { last: 5 });
/// ```
///
/// It does not have an [`IntoIterator`] implementation, so you can't use it in a
Expand Down Expand Up @@ -615,14 +614,14 @@ impl<T> const From<legacy::RangeFrom<T>> for RangeFrom<T> {
#[lang = "RangeToInclusiveCopy"]
#[doc(alias = "..=")]
#[derive(Copy, Clone, PartialEq, Eq, Hash)]
#[unstable(feature = "new_range_api", issue = "125687")]
#[stable(feature = "new_range_to_inclusive_api", since = "CURRENT_RUSTC_VERSION")]
pub struct RangeToInclusive<Idx> {
/// The upper bound of the range (inclusive)
#[unstable(feature = "new_range_api", issue = "125687")]
#[stable(feature = "new_range_to_inclusive_api", since = "CURRENT_RUSTC_VERSION")]
pub last: Idx,
}

#[unstable(feature = "new_range_api", issue = "125687")]
#[stable(feature = "new_range_to_inclusive_api", since = "CURRENT_RUSTC_VERSION")]
impl<Idx: fmt::Debug> fmt::Debug for RangeToInclusive<Idx> {
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(fmt, "..=")?;
Expand All @@ -646,7 +645,7 @@ impl<Idx: PartialOrd<Idx>> RangeToInclusive<Idx> {
/// assert!(!(..=f32::NAN).contains(&0.5));
/// ```
#[inline]
#[unstable(feature = "new_range_api", issue = "125687")]
#[stable(feature = "new_range_to_inclusive_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 @@ -657,13 +656,13 @@ impl<Idx: PartialOrd<Idx>> RangeToInclusive<Idx> {
}
}

#[unstable(feature = "new_range_api", issue = "125687")]
#[stable(feature = "new_range_to_inclusive_api", since = "CURRENT_RUSTC_VERSION")]
impl<T> From<legacy::RangeToInclusive<T>> for RangeToInclusive<T> {
fn from(value: legacy::RangeToInclusive<T>) -> Self {
Self { last: value.end }
}
}
#[unstable(feature = "new_range_api", issue = "125687")]
#[stable(feature = "new_range_to_inclusive_api", since = "CURRENT_RUSTC_VERSION")]
impl<T> From<RangeToInclusive<T>> for legacy::RangeToInclusive<T> {
fn from(value: RangeToInclusive<T>) -> Self {
Self { end: value.last }
Expand All @@ -673,7 +672,7 @@ impl<T> From<RangeToInclusive<T>> for legacy::RangeToInclusive<T> {
// RangeToInclusive<Idx> cannot impl From<RangeTo<Idx>>
// because underflow would be possible with (..0).into()

#[unstable(feature = "new_range_api", issue = "125687")]
#[stable(feature = "new_range_to_inclusive_api", since = "CURRENT_RUSTC_VERSION")]
#[rustc_const_unstable(feature = "const_range", issue = "none")]
impl<T> const RangeBounds<T> for RangeToInclusive<T> {
fn start_bound(&self) -> Bound<&T> {
Expand All @@ -684,7 +683,7 @@ impl<T> const RangeBounds<T> for RangeToInclusive<T> {
}
}

#[unstable(feature = "range_into_bounds", issue = "136903")]
#[stable(feature = "new_range_to_inclusive_api", since = "CURRENT_RUSTC_VERSION")]
#[rustc_const_unstable(feature = "const_range", issue = "none")]
impl<T> const IntoBounds<T> for RangeToInclusive<T> {
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't this remain unstable under range_into_bounds?

fn into_bounds(self) -> (Bound<T>, Bound<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 @@ -129,7 +129,7 @@ mod private_slice_index {
impl Sealed for range::Range<usize> {}
#[stable(feature = "new_range_inclusive_api", since = "CURRENT_RUSTC_VERSION")]
impl Sealed for range::RangeInclusive<usize> {}
#[unstable(feature = "new_range_api", issue = "125687")]
#[stable(feature = "new_range_to_inclusive_api", since = "CURRENT_RUSTC_VERSION")]
impl Sealed for range::RangeToInclusive<usize> {}
#[unstable(feature = "new_range_api", issue = "125687")]
impl Sealed for range::RangeFrom<usize> {}
Expand Down Expand Up @@ -802,7 +802,7 @@ unsafe impl<T> const SliceIndex<[T]> for ops::RangeToInclusive<usize> {
}

/// The methods `index` and `index_mut` panic if the end of the range is out of bounds.
#[stable(feature = "inclusive_range", since = "1.26.0")]
#[stable(feature = "new_range_to_inclusive_api", since = "CURRENT_RUSTC_VERSION")]
#[rustc_const_unstable(feature = "const_index", issue = "143775")]
unsafe impl<T> const SliceIndex<[T]> for range::RangeToInclusive<usize> {
type Output = [T];
Expand Down
11 changes: 10 additions & 1 deletion tests/ui/range/new_range_stability.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
// Stable

use std::range::{RangeInclusive, RangeInclusiveIter};
use std::range::{RangeInclusive, RangeInclusiveIter, RangeToInclusive};

fn range_inclusive(mut r: RangeInclusive<usize>) {
&[1, 2, 3][r]; // Indexing

r.start;
r.last;
r.contains(&5);
Expand All @@ -14,6 +16,13 @@ fn range_inclusive(mut r: RangeInclusive<usize>) {
i.remainder();
}

fn range_to_inclusive(mut r: RangeToInclusive<usize>) {
&[1, 2, 3][r]; // Indexing

r.last;
r.contains(&5);
}

// Unstable module

use std::range::legacy; //~ ERROR unstable
Expand Down
10 changes: 5 additions & 5 deletions tests/ui/range/new_range_stability.stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error[E0658]: use of unstable library feature `new_range_api`
--> $DIR/new_range_stability.rs:19:5
--> $DIR/new_range_stability.rs:28:5
|
LL | use std::range::legacy;
| ^^^^^^^^^^^^^^^^^^
Expand All @@ -9,7 +9,7 @@ LL | use std::range::legacy;
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date

error[E0658]: use of unstable library feature `new_range_api`
--> $DIR/new_range_stability.rs:23:5
--> $DIR/new_range_stability.rs:32:5
|
LL | use std::range::RangeFrom;
| ^^^^^^^^^^^^^^^^^^^^^
Expand All @@ -19,7 +19,7 @@ LL | use std::range::RangeFrom;
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date

error[E0658]: use of unstable library feature `new_range_api`
--> $DIR/new_range_stability.rs:24:5
--> $DIR/new_range_stability.rs:33:5
|
LL | use std::range::Range;
| ^^^^^^^^^^^^^^^^^
Expand All @@ -29,7 +29,7 @@ LL | use std::range::Range;
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date

error[E0658]: use of unstable library feature `new_range_api`
--> $DIR/new_range_stability.rs:25:5
--> $DIR/new_range_stability.rs:34:5
|
LL | use std::range::RangeFromIter;
| ^^^^^^^^^^^^^^^^^^^^^^^^^
Expand All @@ -39,7 +39,7 @@ LL | use std::range::RangeFromIter;
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date

error[E0658]: use of unstable library feature `new_range_api`
--> $DIR/new_range_stability.rs:26:5
--> $DIR/new_range_stability.rs:35:5
|
LL | use std::range::RangeIter;
| ^^^^^^^^^^^^^^^^^^^^^
Expand Down
Loading