@@ -1968,6 +1968,14 @@ impl<T> RawIter<T> {
1968
1968
}
1969
1969
}
1970
1970
}
1971
+
1972
+ unsafe fn drop_elements ( & mut self ) {
1973
+ if mem:: needs_drop :: < T > ( ) && self . len ( ) != 0 {
1974
+ while let Some ( item) = self . next ( ) {
1975
+ item. drop ( ) ;
1976
+ }
1977
+ }
1978
+ }
1971
1979
}
1972
1980
1973
1981
impl < T > Clone for RawIter < T > {
@@ -2030,11 +2038,7 @@ unsafe impl<#[may_dangle] T, A: Allocator + Clone> Drop for RawIntoIter<T, A> {
2030
2038
fn drop ( & mut self ) {
2031
2039
unsafe {
2032
2040
// Drop all remaining elements
2033
- if mem:: needs_drop :: < T > ( ) && self . iter . len ( ) != 0 {
2034
- while let Some ( item) = self . iter . next ( ) {
2035
- item. drop ( ) ;
2036
- }
2037
- }
2041
+ self . iter . drop_elements ( ) ;
2038
2042
2039
2043
// Free the table
2040
2044
if let Some ( ( ptr, layout) ) = self . allocation {
@@ -2049,11 +2053,7 @@ impl<T, A: Allocator + Clone> Drop for RawIntoIter<T, A> {
2049
2053
fn drop ( & mut self ) {
2050
2054
unsafe {
2051
2055
// Drop all remaining elements
2052
- if mem:: needs_drop :: < T > ( ) && self . iter . len ( ) != 0 {
2053
- while let Some ( item) = self . iter . next ( ) {
2054
- item. drop ( ) ;
2055
- }
2056
- }
2056
+ self . iter . drop_elements ( ) ;
2057
2057
2058
2058
// Free the table
2059
2059
if let Some ( ( ptr, layout) ) = self . allocation {
@@ -2111,11 +2111,7 @@ impl<T, A: Allocator + Clone> Drop for RawDrain<'_, T, A> {
2111
2111
fn drop ( & mut self ) {
2112
2112
unsafe {
2113
2113
// Drop all remaining elements. Note that this may panic.
2114
- if mem:: needs_drop :: < T > ( ) && self . iter . len ( ) != 0 {
2115
- while let Some ( item) = self . iter . next ( ) {
2116
- item. drop ( ) ;
2117
- }
2118
- }
2114
+ self . iter . drop_elements ( ) ;
2119
2115
2120
2116
// Reset the contents of the table now that all elements have been
2121
2117
// dropped.
0 commit comments