RS.CLIPPY.CAST_SLICE_FROM_RAW_PARTS
Casting a slice created from a pointer and length to a slice pointer
This checker is a Clippy lint created by The Rust Project Contributors. The documentation shown here is a copy of the original documentation for: cast_slice_from_raw_parts. Copyright ©2025 The Rust Team. All rights reserved.
What it does
Checks for a raw slice being cast to a slice pointer
Why is this bad?
This can result in multiple &mut references to the same location when only a pointer is
required.
ptr::slice_from_raw_parts is a safe alternative that doesn't require
the same safety requirements to be upheld.
Example
let _: *const [u8] = std::slice::from_raw_parts(ptr, len) as *const _;
let _: *mut [u8] = std::slice::from_raw_parts_mut(ptr, len) as *mut _;
Use instead:
let _: *const [u8] = std::ptr::slice_from_raw_parts(ptr, len);
let _: *mut [u8] = std::ptr::slice_from_raw_parts_mut(ptr, len);