mirror of
https://github.com/vulkano-rs/vulkano.git
synced 2024-11-21 22:34:43 +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! {
|
ptr_from_slice = quote! {
|
||||||
debug_assert_eq!(slice.len(), ::std::mem::size_of::<Self>());
|
|
||||||
|
|
||||||
<*mut [u8]>::cast::<Self>(slice.as_ptr())
|
<*mut [u8]>::cast::<Self>(slice.as_ptr())
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -839,9 +839,7 @@ pub unsafe trait BufferContents: Send + Sync + 'static {
|
|||||||
///
|
///
|
||||||
/// # Safety
|
/// # Safety
|
||||||
///
|
///
|
||||||
/// - If `Self` is sized, then `slice.len()` must match the size exactly.
|
/// - `slice` must be a pointer that's valid for reads and writes of the entire slice.
|
||||||
/// - 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.
|
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
unsafe fn ptr_from_slice(slice: NonNull<[u8]>) -> *mut Self;
|
unsafe fn ptr_from_slice(slice: NonNull<[u8]>) -> *mut Self;
|
||||||
}
|
}
|
||||||
@ -854,8 +852,6 @@ where
|
|||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
unsafe fn ptr_from_slice(slice: NonNull<[u8]>) -> *mut Self {
|
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())
|
<*mut [u8]>::cast::<T>(slice.as_ptr())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,7 +8,7 @@ use std::{
|
|||||||
cmp::Ordering,
|
cmp::Ordering,
|
||||||
fmt::{Debug, Display, Formatter, Result as FmtResult},
|
fmt::{Debug, Display, Formatter, Result as FmtResult},
|
||||||
hash::{Hash, Hasher},
|
hash::{Hash, Hasher},
|
||||||
mem::{size_of, MaybeUninit},
|
mem::MaybeUninit,
|
||||||
ops::{Deref, DerefMut},
|
ops::{Deref, DerefMut},
|
||||||
ptr::NonNull,
|
ptr::NonNull,
|
||||||
};
|
};
|
||||||
@ -290,8 +290,6 @@ where
|
|||||||
const LAYOUT: BufferContentsLayout = BufferContentsLayout::from_sized(Layout::new::<Self>());
|
const LAYOUT: BufferContentsLayout = BufferContentsLayout::from_sized(Layout::new::<Self>());
|
||||||
|
|
||||||
unsafe fn ptr_from_slice(slice: NonNull<[u8]>) -> *mut 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())
|
<*mut [u8]>::cast::<Padded<T, N>>(slice.as_ptr())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user