Skip to content

stabilize new RangeFrom type and iterator#153380

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

stabilize new RangeFrom type and iterator#153380
rust-bors[bot] merged 1 commit intorust-lang:mainfrom
pitaj:stabilize-new_range_from_api

Conversation

@pitaj
Copy link
Copy Markdown
Contributor

@pitaj pitaj commented Mar 4, 2026

View all comments

// in core and std
pub mod range;

// in core::range

pub struct RangeFrom<Idx> {
    pub start: Idx,
}

impl<Idx: fmt::Debug> fmt::Debug for RangeFrom<Idx> { /* ... */ }

impl<Idx: PartialOrd<Idx>> RangeFrom<Idx> {
    pub const fn contains<U>(&self, item: &U) -> bool
    where
        Idx: [const] PartialOrd<U>,
        U: ?Sized + [const] PartialOrd<Idx>;
}

impl<Idx: Step> RangeFrom<Idx> {
    pub fn iter(&self) -> RangeFromIter<Idx>;
}

impl<T> const RangeBounds<T> for RangeFrom<T> { /* ... */ }
impl<T> const RangeBounds<T> for RangeFrom<&T> { /* ... */ }

impl<T> const From<RangeFrom<T>> for legacy::RangeFrom<T> { /* ... */ }
impl<T> const From<legacy::RangeFrom<T>> for RangeFrom<T> { /* ... */ }

pub struct RangeFromIter<A>(/* ... */);

// `RangeFromIter::remainder` left unstable

impl<A: Step> Iterator for RangeFromIter<A> {
    type Item = A;
    /* ... */
}

impl<A: Step> FusedIterator for RangeFromIter<A> { }
impl<A: Step> IntoIterator for RangeFrom<A> {
    type Item = A;
    type IntoIter = RangeFromIter<A>;
    /* ... */
}

unsafe impl<T> const SliceIndex<[T]> for range::RangeFrom<usize> {
    type Output = [T];
    /* ... */
}
unsafe impl const SliceIndex<str> for range::RangeFrom<usize> {
    type Output = str;
    /* ... */
}

impl ops::Index<range::RangeFrom<usize>> for CStr {
    type Output = CStr;
    /* ... */
}

Tracking issue: #125687

r? tgross

@rustbot

This comment was marked as resolved.

@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 4, 2026
Comment on lines -419 to +428
/// *Note*: Overflow in the [`Iterator`] implementation (when the contained
/// *Note*: Overflow in the [`IntoIterator`] implementation (when the contained
/// data type reaches its numerical limit) is allowed to panic, wrap, or
/// saturate. This behavior is defined by the implementation of the [`Step`]
/// trait. For primitive integers, this follows the normal rules, and respects
/// the overflow checks profile (panic in debug, wrap in release). Note also
/// that overflow happens earlier than you might assume: the overflow happens
/// in the call to `next` that yields the maximum value, as the range must be
/// set to a state to yield the next value.
/// the overflow checks profile (panic in debug, wrap in release). Unlike
/// its legacy counterpart, the iterator will only panic after yielding the
/// maximum value when overflow checks are enabled.
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.

Do we have a test for this?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Comment on lines 307 to 311
/// Returns the remainder of the range being iterated over.
#[inline]
#[rustc_inherit_overflow_checks]
#[unstable(feature = "new_range_api", issue = "125687")]
#[stable(feature = "new_range_from_api", since = "CURRENT_RUSTC_VERSION")]
pub fn remainder(self) -> RangeFrom<A> {
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.

This could probably use an example

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Added examples for RangeInclusive::remainder, RangeFrom::remainder, and Range::remainder

@tgross35
Copy link
Copy Markdown
Contributor

tgross35 commented Mar 4, 2026

It doesn't look like RangeFromIter::remainder was listed on the tracking issue and that's new compared to the existing RangeFrom, so nominating for @rust-lang/libs-api. If you'd prefer to drop it here then I'm happy to approve.

@rustbot label +I-libs-api-nominated

The current RangeFrom has Index<RangeFrom<usize>> for ByteString and IndexMut<RangeFrom<usize>> for ByteString which should get added, those are unstable so it can happen here or later.

@rustbot rustbot added the I-libs-api-nominated Nominated for discussion during a libs-api team meeting. label Mar 4, 2026
@tgross35
Copy link
Copy Markdown
Contributor

tgross35 commented Mar 4, 2026

Noticing that RangeInclusiveIter::remainder is in the same boat, and is stable on nightly since #150522.

@pitaj
Copy link
Copy Markdown
Contributor Author

pitaj commented Mar 7, 2026

remainder was in the original RFC: https://github.com/rust-lang/rfcs/blob/master/text/3550-new-range.md#iterator-types
So I don't think this need further discussion by T-libs-api?

@rust-bors

This comment has been minimized.

@tgross35
Copy link
Copy Markdown
Contributor

tgross35 commented Mar 8, 2026

remainder was in the original RFC: https://github.com/rust-lang/rfcs/blob/master/text/3550-new-range.md#iterator-types So I don't think this need further discussion by T-libs-api?

Accepted in an RFC doesn’t mean we don’t want to adjust or defer it at stabilization time. It’s probably fine here, but worth confirming since it wasn’t explicitly mentioned anywhere.

@nia-e
Copy link
Copy Markdown
Member

nia-e commented Mar 10, 2026

This was discussed in today's @rust-lang/libs-api meeting and we approved the stabilization, including remainder. Thanks ^^

@rustbot label -I-libs-api-nominated

@rustbot rustbot removed the I-libs-api-nominated Nominated for discussion during a libs-api team meeting. label Mar 10, 2026
@tgross35
Copy link
Copy Markdown
Contributor

@rustbot author

Just needs a rebase

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Mar 13, 2026
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Mar 13, 2026

Reminder, once the PR becomes ready for a review, use @rustbot ready.

@pitaj pitaj force-pushed the stabilize-new_range_from_api branch from 8a511b5 to d404c58 Compare March 20, 2026 02:23
@rustbot

This comment has been minimized.

@theemathas

This comment has been minimized.

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.

r=me after #154191 merges (I think there will be a small conflict)

View changes since this review

@theemathas
Copy link
Copy Markdown
Contributor

I think the remainder method needs documentation saying that it can panic due to an overflow check? Or should it return Option?

@rust-bors

This comment has been minimized.

@pitaj pitaj force-pushed the stabilize-new_range_from_api branch from d404c58 to abd853d Compare March 24, 2026 03:25
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Mar 24, 2026

This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

@pitaj
Copy link
Copy Markdown
Contributor Author

pitaj commented Mar 24, 2026

@bors r=tgross35

@rust-bors
Copy link
Copy Markdown
Contributor

rust-bors bot commented Mar 24, 2026

@pitaj: 🔑 Insufficient privileges: not in review users

@pitaj
Copy link
Copy Markdown
Contributor Author

pitaj commented Mar 24, 2026

@rustbot ready

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Mar 24, 2026
@tgross35
Copy link
Copy Markdown
Contributor

I think the remainder method needs documentation saying that it can panic due to an overflow check? Or should it return Option?

Seems worth checking, asked about this on Zulip #t-libs-api/api-changes > `RangeFrom::remainder` possible panic

@nia-e
Copy link
Copy Markdown
Member

nia-e commented Mar 27, 2026

Seems like the Zulip thread brought up some previously unmentioned concerns, so renominating this. This is only about remainder, everything else should be fine still ^^

@rustbot label +I-libs-api-nominated

@rustbot rustbot added the I-libs-api-nominated Nominated for discussion during a libs-api team meeting. label Mar 27, 2026
@tgross35
Copy link
Copy Markdown
Contributor

If you'd prefer to drop it here then I'm happy to approve.

Still applies, if you can drop remainder for now there's nothing stopping the rest from merging 🙂

@pitaj pitaj force-pushed the stabilize-new_range_from_api branch from abd853d to 6209a93 Compare March 28, 2026 17:16
@pitaj
Copy link
Copy Markdown
Contributor Author

pitaj commented Mar 28, 2026

Removed remainder from the stabilization

@pitaj pitaj removed the I-libs-api-nominated Nominated for discussion during a libs-api team meeting. label Mar 28, 2026
@rust-log-analyzer

This comment has been minimized.

stabilizes `core::range::RangeFrom`
stabilizes `core::range::RangeFromIter`

add examples for `remainder` method on range iterators
`RangeFromIter::remainder` was not stabilized (see issue 154458)
@pitaj pitaj force-pushed the stabilize-new_range_from_api branch from 6209a93 to 085dff4 Compare March 28, 2026 18:00
@tgross35
Copy link
Copy Markdown
Contributor

@bors r+

@rust-bors
Copy link
Copy Markdown
Contributor

rust-bors bot commented Mar 28, 2026

📌 Commit 085dff4 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 28, 2026
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Mar 28, 2026
…, r=tgross35

stabilize new RangeFrom type and iterator

```rust
// in core and std
pub mod range;

// in core::range

pub struct RangeFrom<Idx> {
    pub start: Idx,
}

impl<Idx: fmt::Debug> fmt::Debug for RangeFrom<Idx> { /* ... */ }

impl<Idx: PartialOrd<Idx>> RangeFrom<Idx> {
    pub const fn contains<U>(&self, item: &U) -> bool
    where
        Idx: [const] PartialOrd<U>,
        U: ?Sized + [const] PartialOrd<Idx>;
}

impl<Idx: Step> RangeFrom<Idx> {
    pub fn iter(&self) -> RangeFromIter<Idx>;
}

impl<T> const RangeBounds<T> for RangeFrom<T> { /* ... */ }
impl<T> const RangeBounds<T> for RangeFrom<&T> { /* ... */ }

impl<T> const From<RangeFrom<T>> for legacy::RangeFrom<T> { /* ... */ }
impl<T> const From<legacy::RangeFrom<T>> for RangeFrom<T> { /* ... */ }

pub struct RangeFromIter<A>(/* ... */);

// `RangeFromIter::remainder` left unstable

impl<A: Step> Iterator for RangeFromIter<A> {
    type Item = A;
    /* ... */
}

impl<A: Step> FusedIterator for RangeFromIter<A> { }
impl<A: Step> IntoIterator for RangeFrom<A> {
    type Item = A;
    type IntoIter = RangeFromIter<A>;
    /* ... */
}

unsafe impl<T> const SliceIndex<[T]> for range::RangeFrom<usize> {
    type Output = [T];
    /* ... */
}
unsafe impl const SliceIndex<str> for range::RangeFrom<usize> {
    type Output = str;
    /* ... */
}

impl ops::Index<range::RangeFrom<usize>> for CStr {
    type Output = CStr;
    /* ... */
}
```

Tracking issue: rust-lang#125687
rust-bors bot pushed a commit that referenced this pull request Mar 28, 2026
…uwer

Rollup of 9 pull requests

Successful merges:

 - #150752 (Update libc to v0.2.183)
 - #153380 (stabilize new RangeFrom type and iterator)
 - #153834 (Merge `fabsf16/32/64/128` into `fabs::<F>`)
 - #154043 (simd_fmin/fmax: make semantics and name consistent with scalar intrinsics)
 - #154494 (triagebot: add reminder for bumping CI LLVM stamp)
 - #153374 (Fix LegacyKeyValueFormat report from docker build: dist-x86_64)
 - #154320 (`trim_prefix` for paths)
 - #154453 (Fix ice in rustdoc of private reexport)
 - #154515 (Notify stdarch maintainers on changes in std_detect)
rust-bors bot pushed a commit that referenced this pull request Mar 29, 2026
Rollup of 9 pull requests

Successful merges:

 - #153380 (stabilize new RangeFrom type and iterator)
 - #153834 (Merge `fabsf16/32/64/128` into `fabs::<F>`)
 - #154043 (simd_fmin/fmax: make semantics and name consistent with scalar intrinsics)
 - #154494 (triagebot: add reminder for bumping CI LLVM stamp)
 - #153374 (Fix LegacyKeyValueFormat report from docker build: dist-x86_64)
 - #154320 (`trim_prefix` for paths)
 - #154453 (Fix ice in rustdoc of private reexport)
 - #154504 (move many tests from `structs-enums` to `structs` or `enum`)
 - #154515 (Notify stdarch maintainers on changes in std_detect)
@rust-bors rust-bors bot merged commit aad3710 into rust-lang:main Mar 29, 2026
11 checks passed
@rustbot rustbot added this to the 1.96.0 milestone Mar 29, 2026
rust-timer added a commit that referenced this pull request Mar 29, 2026
Rollup merge of #153380 - pitaj:stabilize-new_range_from_api, r=tgross35

stabilize new RangeFrom type and iterator

```rust
// in core and std
pub mod range;

// in core::range

pub struct RangeFrom<Idx> {
    pub start: Idx,
}

impl<Idx: fmt::Debug> fmt::Debug for RangeFrom<Idx> { /* ... */ }

impl<Idx: PartialOrd<Idx>> RangeFrom<Idx> {
    pub const fn contains<U>(&self, item: &U) -> bool
    where
        Idx: [const] PartialOrd<U>,
        U: ?Sized + [const] PartialOrd<Idx>;
}

impl<Idx: Step> RangeFrom<Idx> {
    pub fn iter(&self) -> RangeFromIter<Idx>;
}

impl<T> const RangeBounds<T> for RangeFrom<T> { /* ... */ }
impl<T> const RangeBounds<T> for RangeFrom<&T> { /* ... */ }

impl<T> const From<RangeFrom<T>> for legacy::RangeFrom<T> { /* ... */ }
impl<T> const From<legacy::RangeFrom<T>> for RangeFrom<T> { /* ... */ }

pub struct RangeFromIter<A>(/* ... */);

// `RangeFromIter::remainder` left unstable

impl<A: Step> Iterator for RangeFromIter<A> {
    type Item = A;
    /* ... */
}

impl<A: Step> FusedIterator for RangeFromIter<A> { }
impl<A: Step> IntoIterator for RangeFrom<A> {
    type Item = A;
    type IntoIter = RangeFromIter<A>;
    /* ... */
}

unsafe impl<T> const SliceIndex<[T]> for range::RangeFrom<usize> {
    type Output = [T];
    /* ... */
}
unsafe impl const SliceIndex<str> for range::RangeFrom<usize> {
    type Output = str;
    /* ... */
}

impl ops::Index<range::RangeFrom<usize>> for CStr {
    type Output = CStr;
    /* ... */
}
```

Tracking issue: #125687
github-actions bot pushed a commit to rust-lang/miri that referenced this pull request Mar 29, 2026
Rollup of 9 pull requests

Successful merges:

 - rust-lang/rust#153380 (stabilize new RangeFrom type and iterator)
 - rust-lang/rust#153834 (Merge `fabsf16/32/64/128` into `fabs::<F>`)
 - rust-lang/rust#154043 (simd_fmin/fmax: make semantics and name consistent with scalar intrinsics)
 - rust-lang/rust#154494 (triagebot: add reminder for bumping CI LLVM stamp)
 - rust-lang/rust#153374 (Fix LegacyKeyValueFormat report from docker build: dist-x86_64)
 - rust-lang/rust#154320 (`trim_prefix` for paths)
 - rust-lang/rust#154453 (Fix ice in rustdoc of private reexport)
 - rust-lang/rust#154504 (move many tests from `structs-enums` to `structs` or `enum`)
 - rust-lang/rust#154515 (Notify stdarch maintainers on changes in std_detect)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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.

6 participants