@@ -1352,6 +1352,13 @@ fn test_try_reserve_exact() {
1352
1352
1353
1353
#[ test]
1354
1354
fn test_stable_pointers ( ) {
1355
+ /// Pull an element from the iterator, then drop it.
1356
+ /// Useful to cover both the `next` and `drop` paths of an iterator.
1357
+ fn next_then_drop < I : Iterator > ( mut i : I ) {
1358
+ i. next ( ) . unwrap ( ) ;
1359
+ drop ( i) ;
1360
+ }
1361
+
1355
1362
// Test that, if we reserved enough space, adding and removing elements does not
1356
1363
// invalidate references into the vector (such as `v0`). This test also
1357
1364
// runs in Miri, which would detect such problems.
@@ -1402,16 +1409,16 @@ fn test_stable_pointers() {
1402
1409
1403
1410
// Partial draining
1404
1411
v. resize_with ( 10 , || 42 ) ;
1405
- drop ( v. drain ( 5 ..) ) ;
1412
+ next_then_drop ( v. drain ( 5 ..) ) ;
1406
1413
assert_eq ! ( * v0, 13 ) ;
1407
1414
1408
1415
// Splicing
1409
1416
v. resize_with ( 10 , || 42 ) ;
1410
- drop ( v. splice ( 5 .., vec ! [ 1 , 2 , 3 , 4 , 5 ] ) ) ; // empty tail after range
1417
+ next_then_drop ( v. splice ( 5 .., vec ! [ 1 , 2 , 3 , 4 , 5 ] ) ) ; // empty tail after range
1411
1418
assert_eq ! ( * v0, 13 ) ;
1412
- drop ( v. splice ( 5 ..8 , vec ! [ 1 ] ) ) ; // replacement is smaller than original range
1419
+ next_then_drop ( v. splice ( 5 ..8 , vec ! [ 1 ] ) ) ; // replacement is smaller than original range
1413
1420
assert_eq ! ( * v0, 13 ) ;
1414
- drop ( v. splice ( 5 ..6 , vec ! [ 1 ; 10 ] . into_iter ( ) . filter ( |_| true ) ) ) ; // lower bound not exact
1421
+ next_then_drop ( v. splice ( 5 ..6 , vec ! [ 1 ; 10 ] . into_iter ( ) . filter ( |_| true ) ) ) ; // lower bound not exact
1415
1422
assert_eq ! ( * v0, 13 ) ;
1416
1423
}
1417
1424
0 commit comments