about summary refs log tree commit diff
path: root/library/alloc/src/raw_vec.rs
diff options
context:
space:
mode:
authorTim Diekmann <tim.diekmann@3dvision.de>2020-08-18 22:39:33 +0200
committerTim Diekmann <tim.diekmann@3dvision.de>2020-08-19 06:46:47 +0200
commit438c40efa109d7a4d83efa066c19cb95dad9ed94 (patch)
tree264f37242cd348f83cf3f1b6573b6c561b179672 /library/alloc/src/raw_vec.rs
parentbe97d13ffc41961c018c313e909f76ba3bbdc958 (diff)
downloadrust-438c40efa109d7a4d83efa066c19cb95dad9ed94.tar.gz
rust-438c40efa109d7a4d83efa066c19cb95dad9ed94.zip
Allow reallocation to different alignment
Diffstat (limited to 'library/alloc/src/raw_vec.rs')
-rw-r--r--library/alloc/src/raw_vec.rs13
1 files changed, 6 insertions, 7 deletions
diff --git a/library/alloc/src/raw_vec.rs b/library/alloc/src/raw_vec.rs
index 247b636c808..e00cb361c00 100644
--- a/library/alloc/src/raw_vec.rs
+++ b/library/alloc/src/raw_vec.rs
@@ -465,8 +465,9 @@ impl<T, A: AllocRef> RawVec<T, A> {
         let new_size = amount * mem::size_of::<T>();
 
         let ptr = unsafe {
-            self.alloc.shrink(ptr, layout, new_size).map_err(|_| TryReserveError::AllocError {
-                layout: Layout::from_size_align_unchecked(new_size, layout.align()),
+            let new_layout = Layout::from_size_align_unchecked(new_size, layout.align());
+            self.alloc.shrink(ptr, layout, new_layout).map_err(|_| TryReserveError::AllocError {
+                layout: new_layout,
                 non_exhaustive: (),
             })?
         };
@@ -493,14 +494,12 @@ where
     alloc_guard(new_layout.size())?;
 
     let memory = if let Some((ptr, old_layout)) = current_memory {
-        debug_assert_eq!(old_layout.align(), new_layout.align());
-        unsafe { alloc.grow(ptr, old_layout, new_layout.size()) }
+        unsafe { alloc.grow(ptr, old_layout, new_layout) }
     } else {
         alloc.alloc(new_layout)
-    }
-    .map_err(|_| AllocError { layout: new_layout, non_exhaustive: () })?;
+    };
 
-    Ok(memory)
+    memory.map_err(|_| AllocError { layout: new_layout, non_exhaustive: () })
 }
 
 unsafe impl<#[may_dangle] T, A: AllocRef> Drop for RawVec<T, A> {