Skip to content

stabilize ptr_cast_slice - #162927

Open
malezjaa wants to merge 1 commit into
rust-lang:mainfrom
malezjaa:stabilize-ptr-cast-slice
Open

malezjaa wants to merge 1 commit into
rust-lang:mainfrom
malezjaa:stabilize-ptr-cast-slice

Conversation

@malezjaa

@malezjaa malezjaa commented Sep 17, 2026

Copy link
Copy Markdown
Contributor

Stabilization report

Closes #149103

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.

Implementation

  1. Implementation PR: Implement cast_slice for raw pointer types #149110
  2. Migrated std to use ptr.cast_slice: Migrate libraries from ptr::slice_from_raw_parts to .cast_slice #156109

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]>;
}

r? @nia-e

@rustbot modify labels: +T-libs

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Sep 17, 2026
@rustbot rustbot added the T-libs Relevant to the library team, which will review and decide on the PR/issue. label Sep 17, 2026
@rustbot

rustbot commented Sep 17, 2026

Copy link
Copy Markdown
Collaborator

nia-e is currently at their maximum review capacity.
They may take a while to respond.

@nia-e

nia-e commented Sep 17, 2026

Copy link
Copy Markdown
Member

seems fine. i think it's small enough that we can const-stabilise it too yeah.

@rfcbot merge libs

@rust-rfcbot

rust-rfcbot commented Sep 17, 2026

Copy link
Copy Markdown
Collaborator

@nia-e has proposed to merge this. The next step is review by the rest of the tagged team members:

No concerns currently listed.

Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up!

See this document for info about what commands tagged team members can give me.

@rust-rfcbot rust-rfcbot added proposed-final-comment-period Proposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off. disposition-merge This issue / PR is in PFCP or FCP with a disposition to merge it. labels Sep 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

disposition-merge This issue / PR is in PFCP or FCP with a disposition to merge it. proposed-final-comment-period Proposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off. S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. 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.

Tracking Issue for #![feature(ptr_cast_slice)]

4 participants