@@ -636,7 +636,7 @@ impl<T> RawTable<T> {
636
636
// Ensure that the table is reset even if one of the drops panic
637
637
let self_ = guard ( self , |self_| self_. clear_no_drop ( ) ) ;
638
638
639
- if mem:: needs_drop :: < T > ( ) {
639
+ if mem:: needs_drop :: < T > ( ) && self_ . len ( ) != 0 {
640
640
unsafe {
641
641
for item in self_. iter ( ) {
642
642
item. drop ( ) ;
@@ -1108,7 +1108,7 @@ impl<T: Clone> Clone for RawTable<T> {
1108
1108
} else {
1109
1109
unsafe {
1110
1110
// First, drop all our elements without clearing the control bytes.
1111
- if mem:: needs_drop :: < T > ( ) {
1111
+ if mem:: needs_drop :: < T > ( ) && self . len ( ) != 0 {
1112
1112
for item in self . iter ( ) {
1113
1113
item. drop ( ) ;
1114
1114
}
@@ -1176,7 +1176,7 @@ impl<T: Clone> RawTable<T> {
1176
1176
// to make sure we drop only the elements that have been
1177
1177
// cloned so far.
1178
1178
let mut guard = guard ( ( 0 , & mut * self ) , |( index, self_) | {
1179
- if mem:: needs_drop :: < T > ( ) {
1179
+ if mem:: needs_drop :: < T > ( ) && self_ . len ( ) != 0 {
1180
1180
for i in 0 ..=* index {
1181
1181
if is_full ( * self_. ctrl ( i) ) {
1182
1182
self_. bucket ( i) . drop ( ) ;
@@ -1258,7 +1258,7 @@ unsafe impl<#[may_dangle] T> Drop for RawTable<T> {
1258
1258
fn drop ( & mut self ) {
1259
1259
if !self . is_empty_singleton ( ) {
1260
1260
unsafe {
1261
- if mem:: needs_drop :: < T > ( ) {
1261
+ if mem:: needs_drop :: < T > ( ) && self . len ( ) != 0 {
1262
1262
for item in self . iter ( ) {
1263
1263
item. drop ( ) ;
1264
1264
}
@@ -1274,7 +1274,7 @@ impl<T> Drop for RawTable<T> {
1274
1274
fn drop ( & mut self ) {
1275
1275
if !self . is_empty_singleton ( ) {
1276
1276
unsafe {
1277
- if mem:: needs_drop :: < T > ( ) {
1277
+ if mem:: needs_drop :: < T > ( ) && self . len ( ) != 0 {
1278
1278
for item in self . iter ( ) {
1279
1279
item. drop ( ) ;
1280
1280
}
@@ -1623,7 +1623,7 @@ unsafe impl<#[may_dangle] T> Drop for RawIntoIter<T> {
1623
1623
fn drop ( & mut self ) {
1624
1624
unsafe {
1625
1625
// Drop all remaining elements
1626
- if mem:: needs_drop :: < T > ( ) {
1626
+ if mem:: needs_drop :: < T > ( ) && self . iter . len ( ) != 0 {
1627
1627
while let Some ( item) = self . iter . next ( ) {
1628
1628
item. drop ( ) ;
1629
1629
}
@@ -1642,7 +1642,7 @@ impl<T> Drop for RawIntoIter<T> {
1642
1642
fn drop ( & mut self ) {
1643
1643
unsafe {
1644
1644
// Drop all remaining elements
1645
- if mem:: needs_drop :: < T > ( ) {
1645
+ if mem:: needs_drop :: < T > ( ) && self . iter . len ( ) != 0 {
1646
1646
while let Some ( item) = self . iter . next ( ) {
1647
1647
item. drop ( ) ;
1648
1648
}
@@ -1703,7 +1703,7 @@ impl<T> Drop for RawDrain<'_, T> {
1703
1703
fn drop ( & mut self ) {
1704
1704
unsafe {
1705
1705
// Drop all remaining elements. Note that this may panic.
1706
- if mem:: needs_drop :: < T > ( ) {
1706
+ if mem:: needs_drop :: < T > ( ) && self . iter . len ( ) != 0 {
1707
1707
while let Some ( item) = self . iter . next ( ) {
1708
1708
item. drop ( ) ;
1709
1709
}
0 commit comments