mirror of
https://github.com/vulkano-rs/vulkano.git
synced 2024-11-21 14:24:18 +00:00
Fix panic in BufferContents
derive expansion and wrong safety docs (#2587)
This commit is contained in:
parent
82acabc0fb
commit
ba278ac193
@ -95,8 +95,6 @@ pub fn derive_buffer_contents(crate_ident: &Ident, mut ast: DeriveInput) -> Resu
|
||||
};
|
||||
|
||||
ptr_from_slice = quote! {
|
||||
debug_assert_eq!(slice.len(), ::std::mem::size_of::<Self>());
|
||||
|
||||
<*mut [u8]>::cast::<Self>(slice.as_ptr())
|
||||
};
|
||||
}
|
||||
|
@ -839,9 +839,7 @@ pub unsafe trait BufferContents: Send + Sync + 'static {
|
||||
///
|
||||
/// # Safety
|
||||
///
|
||||
/// - If `Self` is sized, then `slice.len()` must match the size exactly.
|
||||
/// - If `Self` is unsized, then `slice.len()` minus the size of the head (sized part) of the
|
||||
/// DST must be evenly divisible by the size of the element type.
|
||||
/// - `slice` must be a pointer that's valid for reads and writes of the entire slice.
|
||||
#[doc(hidden)]
|
||||
unsafe fn ptr_from_slice(slice: NonNull<[u8]>) -> *mut Self;
|
||||
}
|
||||
@ -854,8 +852,6 @@ where
|
||||
|
||||
#[inline(always)]
|
||||
unsafe fn ptr_from_slice(slice: NonNull<[u8]>) -> *mut Self {
|
||||
debug_assert_eq!(slice.len(), size_of::<T>());
|
||||
|
||||
<*mut [u8]>::cast::<T>(slice.as_ptr())
|
||||
}
|
||||
}
|
||||
|
@ -8,7 +8,7 @@ use std::{
|
||||
cmp::Ordering,
|
||||
fmt::{Debug, Display, Formatter, Result as FmtResult},
|
||||
hash::{Hash, Hasher},
|
||||
mem::{size_of, MaybeUninit},
|
||||
mem::MaybeUninit,
|
||||
ops::{Deref, DerefMut},
|
||||
ptr::NonNull,
|
||||
};
|
||||
@ -290,8 +290,6 @@ where
|
||||
const LAYOUT: BufferContentsLayout = BufferContentsLayout::from_sized(Layout::new::<Self>());
|
||||
|
||||
unsafe fn ptr_from_slice(slice: NonNull<[u8]>) -> *mut Self {
|
||||
debug_assert_eq!(slice.len(), size_of::<Padded<T, N>>());
|
||||
|
||||
<*mut [u8]>::cast::<Padded<T, N>>(slice.as_ptr())
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user