stabilize new RangeToInclusive type#152304
Conversation
|
|
There was a problem hiding this comment.
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 forRangeToInclusive<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.
|
Reminder, once the PR becomes ready for a review, use |
|
|
|
@rustbot ready |
| #[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 | ||
| ); | ||
| } | ||
| } | ||
| } |
There was a problem hiding this comment.
This impl can probably forward to ops::RangeFrom so we don't have the same thing twice, or vice versa
|
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 @rustbot label +I-libs-api-nominated |
|
We discussed this in the @rust-lang/libs-api meeting and we are happy with the added trait impls. |
stabilizes `core::range::RangeToInclusive` add missing trait impls for new RangeToInclusive add missing trait impls for new RangeFrom
682fb44 to
bc4cead
Compare
|
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. |
|
@rustbot ready |
| // #[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> { |
There was a problem hiding this comment.
Probably no need to have this comment, we can't have >1 #[stable] if range_into_bounds gets stabilized.
…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
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)
…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
…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)
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
stabilizes
core::range::RangeToInclusiveTracking issue: #125687
r? @tgross35