about summary refs log tree commit diff
path: root/library/alloc/src
diff options
context:
space:
mode:
authorJustus K <justus.k@protonmail.com>2020-12-13 10:02:36 +0100
committerJustus K <justus.k@protonmail.com>2020-12-13 10:02:36 +0100
commit0f30b7dd87b8555698ca7e7de360b037230e1f23 (patch)
tree0a6cc53e76e38279afb1cc76b00415fd44e81ab4 /library/alloc/src
parent7efc097c4fe6e97f54a44cee91c56189e9ddb41c (diff)
downloadrust-0f30b7dd87b8555698ca7e7de360b037230e1f23.tar.gz
rust-0f30b7dd87b8555698ca7e7de360b037230e1f23.zip
fix panic if converting ZST Vec to VecDeque
Diffstat (limited to 'library/alloc/src')
-rw-r--r--library/alloc/src/collections/vec_deque/mod.rs8
1 files changed, 6 insertions, 2 deletions
diff --git a/library/alloc/src/collections/vec_deque/mod.rs b/library/alloc/src/collections/vec_deque/mod.rs
index 57807bc5453..1303b58e31c 100644
--- a/library/alloc/src/collections/vec_deque/mod.rs
+++ b/library/alloc/src/collections/vec_deque/mod.rs
@@ -2793,8 +2793,12 @@ impl<T> From<Vec<T>> for VecDeque<T> {
             let len = other.len();
 
             // We need to extend the buf if it's not a power of two, too small
-            // or doesn't have at least one free space
-            if !buf.capacity().is_power_of_two()
+            // or doesn't have at least one free space.
+            // We check if `T` is a ZST in the first condition,
+            // because `usize::MAX` (the capacity returned by `capacity()` for ZST)
+            // is not a power of zero and thus it'll always try
+            // to reserve more memory which will panic for ZST (rust-lang/rust#78532)
+            if (!buf.capacity().is_power_of_two() && mem::size_of::<T>() != 0)
                 || (buf.capacity() < (MINIMUM_CAPACITY + 1))
                 || (buf.capacity() == len)
             {