diff options
| author | Tobias Bucher <tobiasbucher5991@gmail.com> | 2014-08-08 23:52:15 +0200 |
|---|---|---|
| committer | Tobias Bucher <tobiasbucher5991@gmail.com> | 2014-09-14 21:35:48 +0200 |
| commit | 5efa232160ff07de55cc0f62bfafdedb683789db (patch) | |
| tree | 3a2d7e8b9fb2cca80d2a48952d6dace24b792123 /src | |
| parent | 23f2c78d21440a8699cfa917b422795b5ec4adc7 (diff) | |
| download | rust-5efa232160ff07de55cc0f62bfafdedb683789db.tar.gz rust-5efa232160ff07de55cc0f62bfafdedb683789db.zip | |
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.
Diffstat (limited to 'src')
| -rw-r--r-- | src/libcollections/vec.rs | 8 |
1 files 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<T,U> { vec: Vec<T>, @@ -1773,12 +1775,14 @@ impl<T,U> PartialVec<T,U> { /// /// Fails if `T` and `U` have differing sizes or are zero-sized. pub fn from_vec(mut vec: Vec<T>) -> PartialVec<T,U> { - // 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::<T>() != 0); assert!(mem::size_of::<U>() != 0); assert!(mem::size_of::<T>() == mem::size_of::<U>()); + assert!(mem::min_align_of::<T>() == mem::min_align_of::<U>()); let start = vec.as_mut_ptr(); |
