@@ -1281,20 +1281,28 @@ where
1281
1281
table : & ' a mut RawTable < ( K , V ) > ,
1282
1282
}
1283
1283
1284
- impl < K , V , F > Drop for DrainFilter < ' _ , K , V , F >
1284
+ impl < ' a , K , V , F > Drop for DrainFilter < ' a , K , V , F >
1285
1285
where
1286
1286
F : FnMut ( & K , & mut V ) -> bool ,
1287
1287
{
1288
1288
fn drop ( & mut self ) {
1289
- unsafe {
1290
- while let Some ( item) = self . iter . next ( ) {
1291
- let & mut ( ref key, ref mut value) = item. as_mut ( ) ;
1292
- if !( self . f ) ( key, value) {
1293
- self . table . erase_no_drop ( & item) ;
1294
- item. drop ( ) ;
1295
- }
1289
+ struct DropGuard < ' r , ' a , K , V , F > ( & ' r mut DrainFilter < ' a , K , V , F > )
1290
+ where
1291
+ F : FnMut ( & K , & mut V ) -> bool ;
1292
+
1293
+ impl < ' r , ' a , K , V , F > Drop for DropGuard < ' r , ' a , K , V , F >
1294
+ where
1295
+ F : FnMut ( & K , & mut V ) -> bool ,
1296
+ {
1297
+ fn drop ( & mut self ) {
1298
+ while let Some ( _) = self . 0 . next ( ) { }
1296
1299
}
1297
1300
}
1301
+ while let Some ( item) = self . next ( ) {
1302
+ let guard = DropGuard ( self ) ;
1303
+ drop ( item) ;
1304
+ mem:: forget ( guard) ;
1305
+ }
1298
1306
}
1299
1307
}
1300
1308
0 commit comments