about summary refs log tree commit diff
path: root/src/liballoc
diff options
context:
space:
mode:
authorTim Diekmann <tim.diekmann@3dvision.de>2020-03-25 18:36:03 +0100
committerTim Diekmann <tim.diekmann@3dvision.de>2020-03-26 17:12:27 +0100
commitc1fa02331ad60e73569f8351401f183089ff89bf (patch)
tree4b402401a59356b3dec52e9a2b68178dd5de0e7a /src/liballoc
parentd9d35cc6967501818863adcb556991357098557d (diff)
downloadrust-c1fa02331ad60e73569f8351401f183089ff89bf.tar.gz
rust-c1fa02331ad60e73569f8351401f183089ff89bf.zip
Fix ZST handling for `RawVec`
Diffstat (limited to 'src/liballoc')
-rw-r--r--src/liballoc/raw_vec.rs12
1 files changed, 6 insertions, 6 deletions
diff --git a/src/liballoc/raw_vec.rs b/src/liballoc/raw_vec.rs
index aee2367bd95..a51d30448d1 100644
--- a/src/liballoc/raw_vec.rs
+++ b/src/liballoc/raw_vec.rs
@@ -483,14 +483,14 @@ impl<T, A: AllocRef> RawVec<T, A> {
         placement: ReallocPlacement,
         init: AllocInit,
     ) -> Result<(), TryReserveError> {
+        let elem_size = mem::size_of::<T>();
+        if elem_size == 0 {
+            // Since we return a capacity of `usize::MAX` when `elem_size` is
+            // 0, getting to here necessarily means the `RawVec` is overfull.
+            return Err(CapacityOverflow);
+        }
         let layout = match strategy {
             Double => unsafe {
-                let elem_size = mem::size_of::<T>();
-                if elem_size == 0 {
-                    // Since we return a capacity of `usize::MAX` when `elem_size` is
-                    // 0, getting to here necessarily means the `RawVec` is overfull.
-                    return Err(CapacityOverflow);
-                }
                 // Since we guarantee that we never allocate more than `isize::MAX` bytes,
                 // `elem_size * self.cap <= isize::MAX` as a precondition, so this can't overflow.
                 // Additionally the alignment will never be too large as to "not be satisfiable",