]> git.lizzy.rs Git - rust.git/blobdiff - library/alloc/src/raw_vec.rs
Rollup merge of #96757 - jyn514:fewer-clippy-rebuilds, r=Mark-Simulacrum
[rust.git] / library / alloc / src / raw_vec.rs
index 5cf190423e3993d589fa6483ad7c0b309301d59c..9dbac3c36ffb2871ce5e93f30dc3aef1fa94b9c3 100644 (file)
@@ -168,15 +168,9 @@ pub unsafe fn into_box(self, len: usize) -> Box<[MaybeUninit<T>], A> {
 
     #[cfg(not(no_global_oom_handling))]
     fn allocate_in(capacity: usize, init: AllocInit, alloc: A) -> Self {
-        if mem::size_of::<T>() == 0 {
+        // Don't allocate here because `Drop` will not deallocate when `capacity` is 0.
+        if mem::size_of::<T>() == 0 || capacity == 0 {
             Self::new_in(alloc)
-        } else if capacity == 0 {
-            // Don't allocate here because `Drop` will not deallocate when `capacity` is 0.
-            Self {
-                ptr: unsafe { Unique::new_unchecked(NonNull::dangling().as_ptr()) },
-                cap: capacity,
-                alloc,
-            }
         } else {
             // We avoid `unwrap_or_else` here because it bloats the amount of
             // LLVM IR generated.