Skip to content

Commit 19ae86b

Browse files
committed
Auto merge of rust-lang#124795 - scottmcm:simplify-slice-from-raw-parts, r=joboet
Avoid a cast in `ptr::slice_from_raw_parts(_mut)` Casting to `*const ()` or `*mut ()` is no longer needed after rust-lang#123840 so let's make the MIR smaller (and more inline-able, as seen in the tests). If [ACP#362](rust-lang/libs-team#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.
2 parents c567ea1 + c9041b7 commit 19ae86b

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)