Tracking Issue for raw slice len() method (slice_ptr_len, const_slice_ptr_len) · Issue #71146 · rust-lang/rust (original) (raw)
This is a tracking issue for the len() method on raw slice pointers, which allows to get the length of a raw slice pointer when conversion to a slice reference would be UB (because the pointer is null or unaligned).
It covers the feature gates #![feature(slice_ptr_len)]
and #![feature(const_slice_ptr_len)]
(for const fn).
Public API
impl *mut [T] { pub const fn len(self) -> usize; pub const fn is_empty(self) -> bool; }
impl *const [T] { pub const fn len(self) -> usize; pub const fn is_empty(self) -> bool; }
impl NonNull<[T]> { pub const fn len(self) -> usize; // Already stable pub const fn is_empty(self) -> bool; }
History / Steps
- ptr: introduce len() method on raw slices #71082
- Add len and slice_from_raw_parts to NonNull<[T]> #71940
- Additional *mut [T] methods #95594
- also add is_empty to const raw slices #118231
- Add NonNull::<[T]>::is_empty. #122800
- Final commenting period (FCP)
- Stabilization PR
Open questions
- Potential blocker: rustc performs auto-ref when a raw pointer would be enough #73987