Repository navigation
Tracking Issue for #![feature(ptr_cast_slice)] #149103
Copy link
Copy link
Open
Labels
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 RFCS-tracking-ready-to-stabilizeStatus: This is ready to stabilize; it may need a stabilization report and a PRStatus: 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.Relevant to the library team, which will review and decide on the PR/issue.
Description
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.)
- ACP: rust-lang/libs-team#693
- Implementation: Implement
cast_slicefor raw pointer types #149110 - Final comment period (FCP)1
- Stabilization PR
Unresolved Questions
-
the inference probleminfers:let null10: *const [u8] = ptr::slice_from_raw_parts(ptr::null(), 10);does not infer:let null10: *const [u8] = ptr::null().cast_slice(10);- deemed okay to have Tracking Issue for
#![feature(ptr_cast_slice)]#149103 (comment)
Footnotes
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
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 RFCS-tracking-ready-to-stabilizeStatus: This is ready to stabilize; it may need a stabilization report and a PRStatus: 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.Relevant to the library team, which will review and decide on the PR/issue.
Activity
[-]Tracking Issue for `ptr_cast_slice` ACP 693[/-][+]Tracking Issue for `#![feature(ptr_cast_slice)]`[/+]Rollup merge of rust-lang#149110 - Paladynee:acp/ptr_cast_slice, r=jh…
Unrolled build for #149110
Rollup merge of rust-lang#156109 - Paladynee:lib/cast-slice-improveme…
Auto merge of #156109 - Paladynee:lib/cast-slice-improvements, r=jhpratt
Rollup merge of rust-lang#156109 - Paladynee:lib/cast-slice-improveme…
Rollup merge of rust-lang#156109 - Paladynee:lib/cast-slice-improveme…
Unrolled build for #156109
Rollup merge of #156109 - Paladynee:lib/cast-slice-improvements, r=jh…
Paladynee commentedon Jul 11, 2026
status update:
sorry for the late update on this feature, #156109 migrated std to use
ptr.cast_sliceon 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:
let null10: *const [u8] = ptr::slice_from_raw_parts(ptr::null(), 10);let null10: *const [u8] = ptr::null().cast_slice(10);impl<T>vsimpl<T: PointeeSized>(carried over from ptr::slice_from_raw_parts)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
ds84182 commentedon Jul 12, 2026
The inference failure is odd because this works.
ds84182 commentedon Jul 12, 2026
This also infers correctly:
let _: *const [u8] = <*const _>::cast_slice(std::ptr::null(), 3);programmerjake commentedon Jul 12, 2026
as mentioned on Zulip the inference failure when calling methods on a pointer to a deduced type is intentional: #46906
nia-e commentedon Jul 14, 2026
per today's libs-api meeting: (a) we're okay with the bad inference, (b) this should be const, (c)
impl<T>since[T]requiresT: Sized, (d) dealer's choice, we don't have strong opinions on this. thanks!malezjaa commentedon Sep 17, 2026
nia-e commentedon Sep 17, 2026
recent policy is to do FCPs on
implementationstabilisation PRs, so feel free to send one and ping me (or someone else on libs) there ^^Rollup merge of rust-lang#162927 - malezjaa:stabilize-ptr-cast-slice,…