diff --git a/glib/src/collections/ptr_slice.rs b/glib/src/collections/ptr_slice.rs index 5788e0e4b603..4c19b0655ad5 100644 --- a/glib/src/collections/ptr_slice.rs +++ b/glib/src/collections/ptr_slice.rs @@ -601,6 +601,11 @@ impl PtrSlice { /// Creates a new empty slice. #[inline] pub fn new() -> Self { + debug_assert_eq!( + mem::size_of::(), + mem::size_of::<::GlibType>() + ); + PtrSlice { ptr: ptr::NonNull::dangling(), len: 0, diff --git a/glib/src/collections/slice.rs b/glib/src/collections/slice.rs index 74c30a4f0938..eb674c342480 100644 --- a/glib/src/collections/slice.rs +++ b/glib/src/collections/slice.rs @@ -403,6 +403,7 @@ impl Slice { /// Borrows a C array. #[inline] pub unsafe fn from_glib_borrow_num<'a>(ptr: *const T::GlibType, len: usize) -> &'a [T] { + debug_assert_eq!(mem::size_of::(), mem::size_of::()); debug_assert!(!ptr.is_null() || len == 0); if len == 0 { @@ -416,6 +417,7 @@ impl Slice { /// Borrows a mutable C array. #[inline] pub unsafe fn from_glib_borrow_num_mut<'a>(ptr: *mut T::GlibType, len: usize) -> &'a mut [T] { + debug_assert_eq!(mem::size_of::(), mem::size_of::()); debug_assert!(!ptr.is_null() || len == 0); if len == 0 { @@ -432,6 +434,7 @@ impl Slice { ptr: *const *const T::GlibType, len: usize, ) -> &'a [&'a T] { + debug_assert_eq!(mem::size_of::(), mem::size_of::()); debug_assert!(!ptr.is_null() || len == 0); if len == 0 { @@ -448,6 +451,7 @@ impl Slice { ptr: *mut *mut T::GlibType, len: usize, ) -> &'a mut [&'a mut T] { + debug_assert_eq!(mem::size_of::(), mem::size_of::()); debug_assert!(!ptr.is_null() || len == 0); if len == 0 { @@ -522,6 +526,8 @@ impl Slice { /// Creates a new empty slice. #[inline] pub fn new() -> Self { + debug_assert_eq!(mem::size_of::(), mem::size_of::()); + Slice { ptr: ptr::NonNull::dangling(), len: 0,