diff --git a/src/libcore/slice/mod.rs b/src/libcore/slice/mod.rs index a4dde38cb7bb6..eeb171ebb9b46 100644 --- a/src/libcore/slice/mod.rs +++ b/src/libcore/slice/mod.rs @@ -3878,6 +3878,7 @@ unsafe impl<'a, T> TrustedRandomAccess for ExactChunksMut<'a, T> { #[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::() == 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::() == 0, "attempt to create unaligned slice"); Repr { raw: FatPtr { data, len} }.rust_mut }