From 5efa232160ff07de55cc0f62bfafdedb683789db Mon Sep 17 00:00:00 2001 From: Tobias Bucher Date: Fri, 8 Aug 2014 23:52:15 +0200 Subject: [PATCH] Check that the `min_align_of` the both types in a `PartialVec` matches This is important because the underlying allocator of the `Vec` passes that information to the deallocator which needs the guarantee that it is the same parameters that were also passed to the allocation function. --- src/libcollections/vec.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/libcollections/vec.rs b/src/libcollections/vec.rs index e04eadb084f..1e08b3e1d19 100644 --- a/src/libcollections/vec.rs +++ b/src/libcollections/vec.rs @@ -1756,6 +1756,8 @@ pub mod raw { // of type `T`. // // (g) The size of `T` and `U` is equal and non-zero. +// +// (h) The `min_align_of` of `T` and `U` is equal. pub struct PartialVec { vec: Vec, @@ -1773,12 +1775,14 @@ impl PartialVec { /// /// Fails if `T` and `U` have differing sizes or are zero-sized. pub fn from_vec(mut vec: Vec) -> PartialVec { - // FIXME: Assert that the types `T` and `U` have the same size. + // FIXME: Assert statically that the types `T` and `U` have the same + // size. // - // These asserts make sure (g) is satisfied. + // These asserts make sure (g) and (h) are satisfied. assert!(mem::size_of::() != 0); assert!(mem::size_of::() != 0); assert!(mem::size_of::() == mem::size_of::()); + assert!(mem::min_align_of::() == mem::min_align_of::()); let start = vec.as_mut_ptr();