Skip to content

Commit 5efa232

Browse files
committed
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.
1 parent 23f2c78 commit 5efa232

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/libcollections/vec.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1756,6 +1756,8 @@ pub mod raw {
17561756
// of type `T`.
17571757
//
17581758
// (g) The size of `T` and `U` is equal and non-zero.
1759+
//
1760+
// (h) The `min_align_of` of `T` and `U` is equal.
17591761

17601762
pub struct PartialVec<T,U> {
17611763
vec: Vec<T>,
@@ -1773,12 +1775,14 @@ impl<T,U> PartialVec<T,U> {
17731775
///
17741776
/// Fails if `T` and `U` have differing sizes or are zero-sized.
17751777
pub fn from_vec(mut vec: Vec<T>) -> PartialVec<T,U> {
1776-
// FIXME: Assert that the types `T` and `U` have the same size.
1778+
// FIXME: Assert statically that the types `T` and `U` have the same
1779+
// size.
17771780
//
1778-
// These asserts make sure (g) is satisfied.
1781+
// These asserts make sure (g) and (h) are satisfied.
17791782
assert!(mem::size_of::<T>() != 0);
17801783
assert!(mem::size_of::<U>() != 0);
17811784
assert!(mem::size_of::<T>() == mem::size_of::<U>());
1785+
assert!(mem::min_align_of::<T>() == mem::min_align_of::<U>());
17821786

17831787
let start = vec.as_mut_ptr();
17841788

0 commit comments

Comments
 (0)