debug_assert to ensure that from_raw_parts is only used properly aligned
This commit is contained in:
parent
db5476571d
commit
7b24d2bb35
@ -3878,6 +3878,7 @@ fn may_have_side_effect() -> bool { false }
|
||||
#[inline]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
pub unsafe fn from_raw_parts<'a, T>(data: *const T, len: usize) -> &'a [T] {
|
||||
debug_assert!(data as usize % mem::align_of::<T>() == 0, "attempt to create unaligned slice");
|
||||
Repr { raw: FatPtr { data, len } }.rust
|
||||
}
|
||||
|
||||
@ -3891,6 +3892,7 @@ pub unsafe fn from_raw_parts<'a, T>(data: *const T, len: usize) -> &'a [T] {
|
||||
#[inline]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
pub unsafe fn from_raw_parts_mut<'a, T>(data: *mut T, len: usize) -> &'a mut [T] {
|
||||
debug_assert!(data as usize % mem::align_of::<T>() == 0, "attempt to create unaligned slice");
|
||||
Repr { raw: FatPtr { data, len} }.rust_mut
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user