Skip to content

stabilize new Range type and iterator#154620

Merged
rust-bors[bot] merged 1 commit intorust-lang:mainfrom
pitaj:stabilize-new_range_api
Mar 31, 2026
Merged

stabilize new Range type and iterator#154620
rust-bors[bot] merged 1 commit intorust-lang:mainfrom
pitaj:stabilize-new_range_api

Conversation

@pitaj
Copy link
Copy Markdown
Contributor

@pitaj pitaj commented Mar 31, 2026

For #125687
Stabilizes core::range::Range and core::range::RangeIter, newly stable API:

// 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")

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Mar 31, 2026
@rustbot

This comment was marked as outdated.

@pitaj
Copy link
Copy Markdown
Contributor Author

pitaj commented Mar 31, 2026

r? @tgross35

@rustbot rustbot assigned tgross35 and unassigned Mark-Simulacrum Mar 31, 2026
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Mar 31, 2026

tgross35 is currently at their maximum review capacity.
They may take a while to respond.

Copy link
Copy Markdown
Contributor

@tgross35 tgross35 left a comment

Choose a reason for hiding this comment

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

Woohoo, last one!

Double checked that API matches the existing Range. One nit on the comment then r=me

View changes since this review

Comment on lines +7 to +10
// FIXME(#125687): new_range_api recently stabilized
// Remove this when it hits stable.
#![allow(stable_features)]
#![cfg_attr(feature = "nightly", feature(new_range_api))]
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.

Comment on lines +76 to +77
+ _7 = const Layout {{ size: Indirect { alloc_id: ALLOC0, offset: Size(8 bytes) }: usize, align: std::mem::Alignment {{ _inner_repr_trick: Scalar(0x0000000000000000): std::ptr::alignment::AlignmentEnum }} }};
+ _6 = std::alloc::Global::alloc_impl_runtime(const Layout {{ size: Indirect { alloc_id: ALLOC0, offset: Size(8 bytes) }: usize, align: std::mem::Alignment {{ _inner_repr_trick: Scalar(0x0000000000000000): std::ptr::alignment::AlignmentEnum }} }}, const false) -> [return: bb4, unwind unreachable];
+ _7 = const Layout {{ size: Indirect { alloc_id: ALLOC0, offset: Size(8 bytes) }: usize, align: std::mem::Alignment {{ _inner_repr_trick: Scalar(0x0000000000000000): mem::alignment::AlignmentEnum }} }};
+ _6 = std::alloc::Global::alloc_impl_runtime(const Layout {{ size: Indirect { alloc_id: ALLOC0, offset: Size(8 bytes) }: usize, align: std::mem::Alignment {{ _inner_repr_trick: Scalar(0x0000000000000000): mem::alignment::AlignmentEnum }} }}, const false) -> [return: bb4, unwind unreachable];
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.

huh 🤔

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.

Ah this comes from #154577, I assume you did --bless locally. Could you drop changes to these files? Otherwise this will conflict once that one merges.

I assume tests will still pass given that PR says we're not testing this bit.

@tgross35 tgross35 added the relnotes Marks issues that should be documented in the release notes of the next release. label Mar 31, 2026
@pitaj pitaj force-pushed the stabilize-new_range_api branch from 72ebeb7 to c623772 Compare March 31, 2026 04:12
stabilizes `core::range::Range`
stabilizes `core::range::RangeIter`
stabilizes `std::range` which was missed in prior PRs

Updates docs to reflect stabilization (removed "experimental")

`RangeIter::remainder` is excluded from stabilization
@pitaj pitaj force-pushed the stabilize-new_range_api branch from c623772 to 620e92f Compare March 31, 2026 04:17
@tgross35
Copy link
Copy Markdown
Contributor

Thanks!

@bors r+

@rust-bors
Copy link
Copy Markdown
Contributor

rust-bors bot commented Mar 31, 2026

📌 Commit 620e92f has been approved by tgross35

It is now in the queue for this repository.

@rust-bors rust-bors bot added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Mar 31, 2026
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Mar 31, 2026
…gross35

stabilize new Range type and iterator

For rust-lang#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")
rust-bors bot pushed a commit that referenced this pull request Mar 31, 2026
…uwer

Rollup of 12 pull requests

Successful merges:

 - #154419 (Take first task group for further execution)
 - #154569 (Fix  type alias where clause suggestion spacing issue)
 - #154617 (Update flate2 users to use zlib-rs)
 - #154618 (Fix AtomicPtr::update's cfg gate)
 - #154620 (stabilize new Range type and iterator)
 - #151932 (refactor: remove `Adjust::ReborrowPin`)
 - #153980 (refactor: move doc(rust_logo) check to parser)
 - #154134 (fix: guard paren-sugar pretty-printing on short trait args)
 - #154270 (Create `Ty` type alias in `rustc_type_ir`)
 - #154580 (Split AttributeParserError Diagnostic implementation into subfunctions)
 - #154606 (misc test cleanups)
 - #154612 (Add a test for a now fixed ICE with `offset_of!()`)
@rust-bors rust-bors bot merged commit 028a626 into rust-lang:main Mar 31, 2026
11 checks passed
@rustbot rustbot added this to the 1.96.0 milestone Mar 31, 2026
rust-timer added a commit that referenced this pull request Mar 31, 2026
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")
github-actions bot pushed a commit to rust-lang/compiler-builtins that referenced this pull request Mar 31, 2026
…uwer

Rollup of 12 pull requests

Successful merges:

 - rust-lang/rust#154419 (Take first task group for further execution)
 - rust-lang/rust#154569 (Fix  type alias where clause suggestion spacing issue)
 - rust-lang/rust#154617 (Update flate2 users to use zlib-rs)
 - rust-lang/rust#154618 (Fix AtomicPtr::update's cfg gate)
 - rust-lang/rust#154620 (stabilize new Range type and iterator)
 - rust-lang/rust#151932 (refactor: remove `Adjust::ReborrowPin`)
 - rust-lang/rust#153980 (refactor: move doc(rust_logo) check to parser)
 - rust-lang/rust#154134 (fix: guard paren-sugar pretty-printing on short trait args)
 - rust-lang/rust#154270 (Create `Ty` type alias in `rustc_type_ir`)
 - rust-lang/rust#154580 (Split AttributeParserError Diagnostic implementation into subfunctions)
 - rust-lang/rust#154606 (misc test cleanups)
 - rust-lang/rust#154612 (Add a test for a now fixed ICE with `offset_of!()`)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

relnotes Marks issues that should be documented in the release notes of the next release. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-libs Relevant to the library team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants