SOLVED: more alignment fun

This commit is contained in:
nora 2021-12-21 13:22:51 +01:00
parent e9965ca40f
commit 338b7cc1ef
2 changed files with 3 additions and 2 deletions

View file

@ -117,7 +117,7 @@ impl<T: ?Sized> Vechonk<T> {
pub fn push(&mut self, element: Box<T>) {
let elem_size = mem::size_of_val(element.as_ref());
let elem_align = mem::align_of_val(&element);
let elem_align = mem::align_of_val(element.as_ref());
let elem_ptr = Box::into_raw(element);
let meta = ptr::metadata(elem_ptr);
@ -155,6 +155,7 @@ impl<T: ?Sized> Vechonk<T> {
// SAFETY: `elem_ptr` comes from `Box`, and is therefore valid to read from for the size
// We have made sure above that we have more than `elem_size` bytes free
// The two allocations cannot overlap, since the `Box` owned its contents, and so do we
// `dest_ptr` has been aligned above
unsafe {
ptr::copy_nonoverlapping::<u8>(elem_ptr as _, dest_ptr, elem_size);
}