Skip to content

Commit c9041b7

Browse files
committed
Avoid a cast in ptr::slice_from_raw_parts(_mut)
Casting to `*const ()` or `*mut ()` just bloats the MIR, so let's not. If ACP#362 goes through we can keep calling `ptr::from_raw_parts(_mut)` in these also without the cast, but that hasn't had any libs-api attention yet, so I'm not waiting on it.
1 parent 1704687 commit c9041b7

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

Diff for: core/src/ptr/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -812,7 +812,7 @@ pub const fn from_mut<T: ?Sized>(r: &mut T) -> *mut T {
812812
#[rustc_allow_const_fn_unstable(ptr_metadata)]
813813
#[rustc_diagnostic_item = "ptr_slice_from_raw_parts"]
814814
pub const fn slice_from_raw_parts<T>(data: *const T, len: usize) -> *const [T] {
815-
from_raw_parts(data.cast(), len)
815+
intrinsics::aggregate_raw_ptr(data, len)
816816
}
817817

818818
/// Forms a raw mutable slice from a pointer and a length.
@@ -858,7 +858,7 @@ pub const fn slice_from_raw_parts<T>(data: *const T, len: usize) -> *const [T] {
858858
#[rustc_const_unstable(feature = "const_slice_from_raw_parts_mut", issue = "67456")]
859859
#[rustc_diagnostic_item = "ptr_slice_from_raw_parts_mut"]
860860
pub const fn slice_from_raw_parts_mut<T>(data: *mut T, len: usize) -> *mut [T] {
861-
from_raw_parts_mut(data.cast(), len)
861+
intrinsics::aggregate_raw_ptr(data, len)
862862
}
863863

864864
/// Swaps the values at two mutable locations of the same type, without

0 commit comments

Comments
 (0)