Skip to content

stabilize new RangeToInclusive type#152304

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

stabilize new RangeToInclusive type#152304
rust-bors[bot] merged 1 commit intorust-lang:mainfrom
pitaj:stabilize-new_range_api

Conversation

@pitaj
Copy link
Contributor

@pitaj pitaj commented Feb 7, 2026

stabilizes core::range::RangeToInclusive

// in core::range

pub struct RangeToInclusive<Idx> {
    pub last: Idx,
}

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

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

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

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

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

Tracking issue: #125687

r? @tgross35

@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 Feb 7, 2026
@rustbot
Copy link
Collaborator

rustbot commented Feb 7, 2026

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

Copy link
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.

I think there is a small change needed here but otherwise LGTM. However, I noticed there are some trait implementations missing compared to ops::RangeToInclusive:

  • OneSidedRange<T>
  • RangeBounds<T> for RangeToInclusive<&T> (currently has for RangeToInclusive<T>
  • SliceIndex<ByteStr> for RangeToInclusive<usize> (unstable)
  • SliceIndex<str> for RangeToInclusive<usize>

Would you mind putting up a PR adding those? We can re-nominate this for libs-api after.

View changes since this review

@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 Feb 9, 2026
@rustbot
Copy link
Collaborator

rustbot commented Feb 9, 2026

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

@tgross35
Copy link
Contributor

tgross35 commented Feb 9, 2026

Index<RangeFrom<usize>> for CStr is also missing in the new RangeFrom

@pitaj
Copy link
Contributor Author

pitaj commented Feb 14, 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 Feb 14, 2026
Comment on lines +719 to +740
#[unstable(feature = "new_range_api", issue = "125687")]
impl ops::Index<range::RangeFrom<usize>> for CStr {
type Output = CStr;

#[inline]
fn index(&self, index: range::RangeFrom<usize>) -> &CStr {
let bytes = self.to_bytes_with_nul();
// we need to manually check the starting index to account for the null
// byte, since otherwise we could get an empty string that doesn't end
// in a null.
if index.start < bytes.len() {
// SAFETY: Non-empty tail of a valid `CStr` is still a valid `CStr`.
unsafe { CStr::from_bytes_with_nul_unchecked(&bytes[index.start..]) }
} else {
panic!(
"index out of bounds: the len is {} but the index is {}",
bytes.len(),
index.start
);
}
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

This impl can probably forward to ops::RangeFrom so we don't have the same thing twice, or vice versa

@tgross35
Copy link
Contributor

One note but otherwise the changes here LGTM. Nominating for libs-api to take a look because there are two new impls that weren't present for the FCP at #125687 (comment):

impl RangeBounds<T> for RangeToInclusive<&T> { /* ... */ }
impl SliceIndex<str> for RangeToInclusive<usize> { /* ... */ }

These match up with what is present on the existing RangeToInclusive.

@rustbot label +I-libs-api-nominated

@rustbot rustbot added the I-libs-api-nominated Nominated for discussion during a libs-api team meeting. label Feb 16, 2026
Copy link
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.

Everything here LGTM but it needs somebody from @rust-lang/libs-api to okay the above additions. I don't expect it to need a new FCP since they match the old RangeToInclusive.

Last two commits could be squashed.

View changes since this review

@Amanieu
Copy link
Member

Amanieu commented Feb 24, 2026

We discussed this in the @rust-lang/libs-api meeting and we are happy with the added trait impls.

@Amanieu Amanieu removed the I-libs-api-nominated Nominated for discussion during a libs-api team meeting. label Feb 24, 2026
stabilizes `core::range::RangeToInclusive`
add missing trait impls for new RangeToInclusive
add missing trait impls for new RangeFrom
@pitaj pitaj force-pushed the stabilize-new_range_api branch from 682fb44 to bc4cead Compare March 1, 2026 04:46
@rustbot
Copy link
Collaborator

rustbot commented Mar 1, 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
Contributor Author

pitaj commented Mar 1, 2026

@rustbot ready

Copy link
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.

@rust-bors
Copy link
Contributor

rust-bors bot commented Mar 2, 2026

📌 Commit bc4cead 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 2, 2026
Comment on lines +700 to 703
// #[stable(feature = "new_range_to_inclusive_api", since = "CURRENT_RUSTC_VERSION")]
#[unstable(feature = "range_into_bounds", issue = "136903")]
#[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.

Probably no need to have this comment, we can't have >1 #[stable] if range_into_bounds gets stabilized.

jhpratt added a commit to jhpratt/rust that referenced this pull request Mar 2, 2026
…gross35

stabilize new RangeToInclusive type

stabilizes `core::range::RangeToInclusive`

```rust
// in core::range

pub struct RangeToInclusive<Idx> {
    pub last: Idx,
}

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

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

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

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

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

Tracking issue: rust-lang#125687
rust-bors bot pushed a commit that referenced this pull request Mar 2, 2026
Rollup of 6 pull requests

Successful merges:

 - #153015 (core: make atomic primitives type aliases of `Atomic<T>`)
 - #153046 (Couple of cg_ssa refactorings)
 - #153169 (Various small query cleanups)
 - #152304 (stabilize new RangeToInclusive type)
 - #153225 (tests/ui/asm: add annotations for reference rules)
 - #153233 (test: add regression test for fuzzy_provenance_casts lint ICE)
jhpratt added a commit to jhpratt/rust that referenced this pull request Mar 2, 2026
…gross35

stabilize new RangeToInclusive type

stabilizes `core::range::RangeToInclusive`

```rust
// in core::range

pub struct RangeToInclusive<Idx> {
    pub last: Idx,
}

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

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

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

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

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

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

Rollup of 6 pull requests

Successful merges:

 - #153169 (Various small query cleanups)
 - #152304 (stabilize new RangeToInclusive type)
 - #153046 (Couple of cg_ssa refactorings)
 - #153090 (elf-raw-dylib: set type for functions)
 - #153225 (tests/ui/asm: add annotations for reference rules)
 - #153233 (test: add regression test for fuzzy_provenance_casts lint ICE)
@rust-bors rust-bors bot merged commit 44c7081 into rust-lang:main Mar 2, 2026
11 checks passed
@rustbot rustbot added this to the 1.96.0 milestone Mar 2, 2026
rust-timer added a commit that referenced this pull request Mar 2, 2026
Rollup merge of #152304 - pitaj:stabilize-new_range_api, r=tgross35

stabilize new RangeToInclusive type

stabilizes `core::range::RangeToInclusive`

```rust
// in core::range

pub struct RangeToInclusive<Idx> {
    pub last: Idx,
}

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

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

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

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

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

Tracking issue: #125687
@tgross35 tgross35 added the relnotes Marks issues that should be documented in the release notes of the next release. label Mar 2, 2026
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