Skip to content

Commit 055ec33

Browse files
authored
Unrolled build for #149113
Rollup merge of #149113 - RalfJung:sgx-less-unsafe, r=ChrisDenton sgx: avoid unnecessarily creating a slice Cc ``@jethrogb`` -- no idea why this created a slice only to directly convert it back to a raw pointer, but we can avoid this and in fact make the entire function safe. I didn't change the function signature (it's still an `unsafe fn`) as I know nothing about the surrounding code.
2 parents 53732d5 + 7ad3c5c commit 055ec33

File tree

1 file changed

+1
-8
lines changed
  • library/std/src/sys/pal/sgx/abi/usercalls

1 file changed

+1
-8
lines changed

library/std/src/sys/pal/sgx/abi/usercalls/alloc.rs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -143,12 +143,6 @@ unsafe impl<T: UserSafeSized> UserSafe for [T] {
143143
align_of::<T>()
144144
}
145145

146-
/// # Safety
147-
/// Behavior is undefined if any of these conditions are violated:
148-
/// * `ptr` must be [valid] for writes of `size` many bytes, and it must be
149-
/// properly aligned.
150-
///
151-
/// [valid]: core::ptr#safety
152146
/// # Panics
153147
///
154148
/// This function panics if:
@@ -158,8 +152,7 @@ unsafe impl<T: UserSafeSized> UserSafe for [T] {
158152
let elem_size = size_of::<T>();
159153
assert_eq!(size % elem_size, 0);
160154
let len = size / elem_size;
161-
// SAFETY: The caller must uphold the safety contract for `from_raw_sized_unchecked`
162-
unsafe { slice::from_raw_parts_mut(ptr as _, len) }
155+
ptr::slice_from_raw_parts_mut(ptr as _, len)
163156
}
164157
}
165158

0 commit comments

Comments
 (0)