Repository navigation
Open
Labels
A-raw-pointersArea: raw pointers, MaybeUninit, NonNullArea: raw pointers, MaybeUninit, NonNullA-slice-vecArea: `[T]` and `Vec<T>`Area: `[T]` and `Vec<T>`B-unstableBlocker: Implemented in the nightly compiler and unstable.Blocker: Implemented in the nightly compiler and unstable.C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCCategory: An issue tracking the progress of sth. like the implementation of an RFCE-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.T-libsRelevant to the library team, which will review and decide on the PR/issue.Relevant to the library team, which will review and decide on the PR/issue.
Description
This is a tracking issue for indexing methods on raw slices: get_unchecked(_mut) and as_(mut_/non_null_)ptr on raw slices (mutable and const raw pointers and NonNull).
The feature gate for the issue is #![feature(slice_ptr_get)].
Public API
impl<T> *mut [T] {
pub const fn as_mut_ptr(self) -> *mut T {}
pub unsafe fn get_unchecked_mut<I>(self, index: I) -> *mut I::Output where I: SliceIndex<[T]>;
}
impl<T> *const [T] {
pub const fn as_ptr(self) -> *const T {}
pub unsafe fn get_unchecked<I>(self, index: I) -> *const I::Output where I: SliceIndex<[T]>;
}
impl<T> NonNull<[T]> {
pub const fn as_non_null_ptr(self) -> NonNull<T> {}
pub const fn as_mut_ptr(self) -> *mut T {}
pub unsafe fn get_unchecked_mut<I>(self, index: I) -> NonNull<I::Output> where I: SliceIndex<[T]>;
}History / Steps
- Initial PR: add (unchecked) indexing methods to raw (and NonNull) slices #73986
- Add
NonNull::as_mut_ptr: Addas_mut_ptrtoNonNull<[T]>#75248 - Final commenting period (FCP)
- Stabilization PR
Open questions
- Potential blockers: rustc performs auto-ref when a raw pointer would be enough #73987, Missing unsizing coercions for raw slice pointers #74679
- Should this use
arbitrary_self_types(Arbitrary self types v2 rfcs#3519)
Reacted by Stepan Koltsov, luketpeterson, Nazar Mokrynskyi, Gabriel Bjørnager Jensen, Guillaume E and Kuklík Radek
Reacted by Jake Goulding, CPerezz, Joe Richey, Luo Jia / Zhouqi Jiang, Tobias Menzi, Matthew House, luaneko, Jonathan Woollett-Light, Harald Hoyer, Gabriel Bjørnager Jensen and 7 more
Metadata
Metadata
Assignees
Labels
A-raw-pointersArea: raw pointers, MaybeUninit, NonNullArea: raw pointers, MaybeUninit, NonNullA-slice-vecArea: `[T]` and `Vec<T>`Area: `[T]` and `Vec<T>`B-unstableBlocker: Implemented in the nightly compiler and unstable.Blocker: Implemented in the nightly compiler and unstable.C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCCategory: An issue tracking the progress of sth. like the implementation of an RFCE-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.T-libsRelevant to the library team, which will review and decide on the PR/issue.Relevant to the library team, which will review and decide on the PR/issue.
Activity
RalfJung commentedon Jul 23, 2020
#74679 is a potential blocker for this.
RalfJung commentedon Aug 5, 2020
With #75152, the allocator trait started making use of this.
TimDiekmann commentedon Aug 6, 2020
Especially with
AllocRefusing it, it would come in handy if we could also addIf we want this I'd make a PR.
RalfJung commentedon Aug 6, 2020
Seems reasonable to me -- @Amanieu what do you think?
TimDiekmann commentedon Aug 6, 2020
An alternative name would be
as_raw_ptrto avoid confusion withas_ptr, which already returns*mut T. This would also apply to*const [T]and*mut [T].Amanieu commentedon Aug 6, 2020
I don't particularly care for the name bikeshed but I agree that this method would be useful.
TimDiekmann commentedon Aug 8, 2020
Rollup merge of rust-lang#75248 - TimDiekmann:NonNull-as_mut_ptr, r=R…
25 remaining items
RalfJung commentedon Jan 4, 2025
This feature gate currently does not contain any
as_ptrthat returns*mut T. Are you referring toNonNull::as_ptr? It's not clear from your comment. That one is already stable so its name is not up for dispute.nazar-pc commentedon Jan 4, 2025
I was, but failed to see it was already stabilized long time ago
WorldSEnder commentedon Jan 23, 2026
Is it expected that we would be able to write something like
with the usual (panicking) out of bounds checking from slice indexing with these getters, or are they strictly meant to allow an unsafe, manually checked, implementation of the above?
EDIT: Reading this comment it sounds like the latter, but this was written before we got Raw Borrow Operators in 1.82, so the opinion might have changed since then?
clarfonthey commentedon Jan 28, 2026
Should
split_atmethods (#95595) be lumped under this feature gate? It seems like the main blocker is the pointer method coercions, and otherwise those methods are just as useful as these. In particular,split_atis often used to do const slicing while const traits are still unstable.I was going to make a PR to flesh out those methods (since they're only for
*mutpointers, and missing for*constandNonNull), but wanted to ask this first since I can move the feature gate over in the same PR.Rollup merge of rust-lang#158810 - yilin0518:fix_get_unchecked, r=Dar…
Unrolled build for #158810
Rollup merge of #158810 - yilin0518:fix_get_unchecked, r=Darksonn
Rollup merge of #158810 - yilin0518:fix_get_unchecked, r=Darksonn
Implement stable core::alloc::Allocator behind alloc_trait
Implement stable core::alloc::Allocator behind alloc_trait