From e63874fa7ad9e3cf05e0249020d7b885c28be5aa Mon Sep 17 00:00:00 2001 From: Simon Sapin Date: Mon, 21 Sep 2015 16:34:25 +0200 Subject: [PATCH] Skip the drop_in_place loop in Vec::drop based on needs_drop. Fix #24280 This should help unoptimized builds, according to https://github.com/rust-lang/rust/issues/24280#issuecomment-141756975 --- src/libcollections/vec.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libcollections/vec.rs b/src/libcollections/vec.rs index c99460a55c952..d1b9018da9494 100644 --- a/src/libcollections/vec.rs +++ b/src/libcollections/vec.rs @@ -65,7 +65,7 @@ use alloc::heap::EMPTY; use core::cmp::Ordering; use core::fmt; use core::hash::{self, Hash}; -use core::intrinsics::{arith_offset, assume, drop_in_place}; +use core::intrinsics::{arith_offset, assume, drop_in_place, needs_drop}; use core::iter::FromIterator; use core::mem; use core::ops::{Index, IndexMut, Deref}; @@ -1321,7 +1321,7 @@ impl Drop for Vec { // Or rather, that impl'ing Drop makes them not zero-sized. This is // OK because exactly when this stops being a valid assumption, we // don't need unsafe_no_drop_flag shenanigans anymore. - if self.buf.unsafe_no_drop_flag_needs_drop() { + if unsafe { needs_drop::() } && self.buf.unsafe_no_drop_flag_needs_drop() { for x in self.iter_mut() { unsafe { drop_in_place(x); } }