Skip to content

Tracking Issue for raw slice getters (slice_ptr_get) #74265

Open

Description

@RalfJung

View all comments

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

Open questions

Activity

  1. added
    C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFC
    T-libs-api[DEPRECATED; DO NOT USE]
    on Jul 12, 2020
  2. added
    B-unstableBlocker: Implemented in the nightly compiler and unstable.
    on Jul 13, 2020
  3. RalfJung commented on Jul 23, 2020

    @RalfJung
    MemberAuthor

    #74679 is a potential blocker for this.

  4. added
    A-slice-vecArea: `[T]` and `Vec<T>`
    Libs-SmallLibs issues that are considered "small" or self-contained
    I-libs-radarLibs issues that are tracked on the team's radar.
    A-raw-pointersArea: raw pointers, MaybeUninit, NonNull
    on Jul 29, 2020
  5. RalfJung commented on Aug 5, 2020

    @RalfJung
    MemberAuthor

    With #75152, the allocator trait started making use of this.

  6. TimDiekmann commented on Aug 6, 2020

    @TimDiekmann
    Contributor

    Especially with AllocRef using it, it would come in handy if we could also add

    impl<T> NonNull<[T]> {
        #[inline]
        fn as_mut_ptr(self) -> *mut T {
            self.as_non_null_ptr().as_ptr()
        }
    }

    If we want this I'd make a PR.

  7. RalfJung commented on Aug 6, 2020

    @RalfJung
    MemberAuthor

    Seems reasonable to me -- @Amanieu what do you think?

  8. TimDiekmann commented on Aug 6, 2020

    @TimDiekmann
    Contributor

    An alternative name would be as_raw_ptr to avoid confusion with as_ptr, which already returns *mut T. This would also apply to *const [T] and *mut [T].

  9. Amanieu commented on Aug 6, 2020

    @Amanieu
    Member

    I don't particularly care for the name bikeshed but I agree that this method would be useful.

  10. TimDiekmann commented on Aug 8, 2020

    @TimDiekmann
  11. added a commit that references this issue on Aug 8, 2020
  12. 25 remaining items

  13. RalfJung commented on Jan 4, 2025

    @RalfJung
    MemberAuthor

    This feature gate currently does not contain any as_ptr that returns *mut T. Are you referring to NonNull::as_ptr? It's not clear from your comment. That one is already stable so its name is not up for dispute.

  14. nazar-pc commented on Jan 4, 2025

    @nazar-pc

    I was, but failed to see it was already stabilized long time ago

  15. WorldSEnder commented on Jan 23, 2026

    @WorldSEnder

    Is it expected that we would be able to write something like

        let arr = [1, 2, 3];
        let p: *const [u32] = &arr as *const _;
        let x: *const [u32] = &raw const p[1..];

    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?

  16. clarfonthey commented on Jan 28, 2026

    @clarfonthey
    Contributor

    Should split_at methods (#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_at is 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 *mut pointers, and missing for *const and NonNull), but wanted to ask this first since I can move the feature gate over in the same PR.

  17. added a commit that references this issue on Jul 6, 2026
  18. added a commit that references this issue on Jul 6, 2026
  19. added
    T-libsRelevant to the library team, which will review and decide on the PR/issue.
    and removed
    T-libs-api[DEPRECATED; DO NOT USE]
    on Aug 12, 2026
  20. added
    E-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.
    and removed
    Libs-SmallLibs issues that are considered "small" or self-contained
    on Oct 7, 2026
  21. removed
    I-libs-radarLibs issues that are tracked on the team's radar.
    on Oct 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-raw-pointersArea: raw pointers, MaybeUninit, NonNullA-slice-vecArea: `[T]` and `Vec<T>`B-unstableBlocker: Implemented in the nightly compiler and unstable.C-tracking-issueCategory: 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.T-libsRelevant to the library team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions