@@ -636,7 +636,7 @@ impl<T> RawTable<T> {
636636 // Ensure that the table is reset even if one of the drops panic
637637 let self_ = guard ( self , |self_| self_. clear_no_drop ( ) ) ;
638638
639- if mem:: needs_drop :: < T > ( ) {
639+ if mem:: needs_drop :: < T > ( ) && self_ . len ( ) != 0 {
640640 unsafe {
641641 for item in self_. iter ( ) {
642642 item. drop ( ) ;
@@ -1108,7 +1108,7 @@ impl<T: Clone> Clone for RawTable<T> {
11081108 } else {
11091109 unsafe {
11101110 // 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 {
11121112 for item in self . iter ( ) {
11131113 item. drop ( ) ;
11141114 }
@@ -1176,7 +1176,7 @@ impl<T: Clone> RawTable<T> {
11761176 // to make sure we drop only the elements that have been
11771177 // cloned so far.
11781178 let mut guard = guard ( ( 0 , & mut * self ) , |( index, self_) | {
1179- if mem:: needs_drop :: < T > ( ) {
1179+ if mem:: needs_drop :: < T > ( ) && self_ . len ( ) != 0 {
11801180 for i in 0 ..=* index {
11811181 if is_full ( * self_. ctrl ( i) ) {
11821182 self_. bucket ( i) . drop ( ) ;
@@ -1258,7 +1258,7 @@ unsafe impl<#[may_dangle] T> Drop for RawTable<T> {
12581258 fn drop ( & mut self ) {
12591259 if !self . is_empty_singleton ( ) {
12601260 unsafe {
1261- if mem:: needs_drop :: < T > ( ) {
1261+ if mem:: needs_drop :: < T > ( ) && self . len ( ) != 0 {
12621262 for item in self . iter ( ) {
12631263 item. drop ( ) ;
12641264 }
@@ -1274,7 +1274,7 @@ impl<T> Drop for RawTable<T> {
12741274 fn drop ( & mut self ) {
12751275 if !self . is_empty_singleton ( ) {
12761276 unsafe {
1277- if mem:: needs_drop :: < T > ( ) {
1277+ if mem:: needs_drop :: < T > ( ) && self . len ( ) != 0 {
12781278 for item in self . iter ( ) {
12791279 item. drop ( ) ;
12801280 }
@@ -1623,7 +1623,7 @@ unsafe impl<#[may_dangle] T> Drop for RawIntoIter<T> {
16231623 fn drop ( & mut self ) {
16241624 unsafe {
16251625 // Drop all remaining elements
1626- if mem:: needs_drop :: < T > ( ) {
1626+ if mem:: needs_drop :: < T > ( ) && self . iter . len ( ) != 0 {
16271627 while let Some ( item) = self . iter . next ( ) {
16281628 item. drop ( ) ;
16291629 }
@@ -1642,7 +1642,7 @@ impl<T> Drop for RawIntoIter<T> {
16421642 fn drop ( & mut self ) {
16431643 unsafe {
16441644 // Drop all remaining elements
1645- if mem:: needs_drop :: < T > ( ) {
1645+ if mem:: needs_drop :: < T > ( ) && self . iter . len ( ) != 0 {
16461646 while let Some ( item) = self . iter . next ( ) {
16471647 item. drop ( ) ;
16481648 }
@@ -1703,7 +1703,7 @@ impl<T> Drop for RawDrain<'_, T> {
17031703 fn drop ( & mut self ) {
17041704 unsafe {
17051705 // 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 {
17071707 while let Some ( item) = self . iter . next ( ) {
17081708 item. drop ( ) ;
17091709 }
0 commit comments