@@ -1352,6 +1352,13 @@ fn test_try_reserve_exact() {
13521352
13531353#[ test]
13541354fn 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+
13551362 // Test that, if we reserved enough space, adding and removing elements does not
13561363 // invalidate references into the vector (such as `v0`). This test also
13571364 // runs in Miri, which would detect such problems.
@@ -1402,16 +1409,16 @@ fn test_stable_pointers() {
14021409
14031410 // Partial draining
14041411 v. resize_with ( 10 , || 42 ) ;
1405- drop ( v. drain ( 5 ..) ) ;
1412+ next_then_drop ( v. drain ( 5 ..) ) ;
14061413 assert_eq ! ( * v0, 13 ) ;
14071414
14081415 // Splicing
14091416 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
14111418 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
14131420 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
14151422 assert_eq ! ( * v0, 13 ) ;
14161423}
14171424
0 commit comments