diff --git a/library/alloc/src/vec.rs b/library/alloc/src/vec.rs index 9b7f2af3ba9e..d2f92b7c0082 100644 --- a/library/alloc/src/vec.rs +++ b/library/alloc/src/vec.rs @@ -2086,11 +2086,8 @@ impl Extend for Vec { >::spec_extend(self, iter.into_iter()) } else { // if self has no allocation then use the more powerful from_iter specializations - let other = SpecFrom::from_iter(iter.into_iter()); - // replace self, don't run drop since self was empty - unsafe { - ptr::write(self, other); - } + // and overwrite self + *self = SpecFrom::from_iter(iter.into_iter()); } } @@ -2544,11 +2541,8 @@ impl<'a, T: 'a + Copy> Extend<&'a T> for Vec { self.spec_extend(iter.into_iter()) } else { // if self has no allocation then use the more powerful from_iter specializations - let other = SpecFrom::from_iter(iter.into_iter()); - // replace self, don't run drop since self was empty - unsafe { - ptr::write(self, other); - } + // and overwrite self + *self = SpecFrom::from_iter(iter.into_iter()); } }