Skip to content

Tracking Issue for #![feature(ptr_cast_slice)] #149103

Description

@Paladynee

Feature gate: #![feature(ptr_cast_slice)]

This is a tracking issue for rust-lang/libs-team#693

This feature adds method calls on raw pointers that call into the respective ptr::slice_from_raw_parts{_mut} method for the types *const T, *mut T and NonNull<T> to make using raw pointers more ergonomic in Rust by supporting postfix method chain syntax while creating slices.

Public API

// core::ptr::const_ptr
impl<T> *const T {
    pub const fn cast_slice(self, len: usize) -> *const [T];
}

// core::ptr::mut_ptr
impl<T> *mut T {
    pub const fn cast_slice(self, len: usize) -> *mut [T];
}

// core::ptr::non_null
impl<T> NonNull<T> {
    pub const fn cast_slice(self, len: usize) -> NonNull<[T]>;
}

Steps / History

(Remember to update the S-tracking-* label when checking boxes.)

Unresolved Questions

Footnotes

  1. https://std-dev-guide.rust-lang.org/feature-lifecycle/stabilization.html ↩

Activity

  1. added
    T-libs-api[DEPRECATED; DO NOT USE]
    C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFC
    on Nov 19, 2025
  2. changed the title [-]Tracking Issue for `ptr_cast_slice` ACP 693[/-] [+]Tracking Issue for `#![feature(ptr_cast_slice)]`[/+] on Nov 19, 2025
  3. added a commit that references this issue on Jan 29, 2026
  4. added a commit that references this issue on Jan 29, 2026
  5. added
    S-tracking-ready-to-stabilizeStatus: This is ready to stabilize; it may need a stabilization report and a PR
    and removed on Feb 5, 2026
  6. added a commit that references this issue on May 7, 2026
  7. added a commit that references this issue on May 8, 2026
  8. added a commit that references this issue on May 30, 2026
  9. added a commit that references this issue on May 30, 2026
  10. added a commit that references this issue on May 31, 2026
  11. Paladynee commented on Jul 11, 2026

    @Paladynee
    ContributorAuthor

    status update:

    sorry for the late update on this feature, #156109 migrated std to use ptr.cast_slice on most places in std other than a few places i arbitrarily deemed "too dangerous to change" etc.

    i have a hunch that since this is just a "wrap another function" feature it'll be quite straightforward to push this slowly towards stabilization.

    a few questions that still remain are:

    • A) the inference problem
      • infers: let null10: *const [u8] = ptr::slice_from_raw_parts(ptr::null(), 10);
      • does not infer: let null10: *const [u8] = ptr::null().cast_slice(10);
    • B) whether the feature can be stabilized as const as it's stabilized normally
    • C) the impl block impl<T> vs impl<T: PointeeSized> (carried over from ptr::slice_from_raw_parts)
    • D) whether the docs should redirect to ptr::slice_from_raw_parts{_mut} instead of manually inlining them (like pointer::copy_from_nonoverlapping)

    libs-api: questions B, C, D
    @rustbot label +I-libs-api-nominated

  12. ds84182 commented on Jul 12, 2026

    @ds84182

    The inference failure is odd because this works.

    fn main() {
        struct Woof<T: ?Sized>(std::marker::PhantomData<T>);
        const fn null<T: ?Sized>() -> Woof<T> { Woof(std::marker::PhantomData) }
        impl<T> Woof<T> {
            const fn cast_slice(self, _len: usize) -> Woof<[T]> {
                null()
            }
        }
        
        let _: Woof<[u8]> = null().cast_slice(3);
    }
  13. ds84182 commented on Jul 12, 2026

    @ds84182

    This also infers correctly: let _: *const [u8] = <*const _>::cast_slice(std::ptr::null(), 3);

  14. programmerjake commented on Jul 12, 2026

    @programmerjake
    Member

    as mentioned on Zulip the inference failure when calling methods on a pointer to a deduced type is intentional: #46906

  15. nia-e commented on Jul 14, 2026

    @nia-e
    Member

    per today's libs-api meeting: (a) we're okay with the bad inference, (b) this should be const, (c) impl<T> since [T] requires T: Sized, (d) dealer's choice, we don't have strong opinions on this. thanks!

  16. 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
  17. malezjaa commented on Sep 17, 2026

    @malezjaa
  18. nia-e commented on Sep 17, 2026

    @nia-e
    Member

    recent policy is to do FCPs on implementation stabilisation PRs, so feel free to send one and ping me (or someone else on libs) there ^^

  19. added a commit that references this issue on Oct 12, 2026
    2d5a254
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

    C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCS-tracking-ready-to-stabilizeStatus: This is ready to stabilize; it may need a stabilization report and a PRT-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