File tree Expand file tree Collapse file tree 1 file changed +18
-4
lines changed Expand file tree Collapse file tree 1 file changed +18
-4
lines changed Original file line number Diff line number Diff line change @@ -1351,24 +1351,38 @@ fn test_try_reserve_exact() {
13511351}
13521352
13531353#[ test]
1354- fn test_stable_push_pop ( ) {
1354+ fn test_stable_pointers ( ) {
13551355 // Test that, if we reserved enough space, adding and removing elements does not
13561356 // invalidate references into the vector (such as `v0`). This test also
13571357 // runs in Miri, which would detect such problems.
1358- let mut v = Vec :: with_capacity ( 10 ) ;
1358+ let mut v = Vec :: with_capacity ( 128 ) ;
13591359 v. push ( 13 ) ;
13601360
1361- // laundering the lifetime -- we take care that `v` does not reallocate, so that's okay.
1361+ // Laundering the lifetime -- we take care that `v` does not reallocate, so that's okay.
13621362 let v0 = unsafe { & * ( & v[ 0 ] as * const _ ) } ;
1363-
13641363 // Now do a bunch of things and occasionally use `v0` again to assert it is still valid.
1364+
1365+ // Pushing/inserting and popping/removing
13651366 v. push ( 1 ) ;
13661367 v. push ( 2 ) ;
13671368 v. insert ( 1 , 1 ) ;
13681369 assert_eq ! ( * v0, 13 ) ;
13691370 v. remove ( 1 ) ;
13701371 v. pop ( ) . unwrap ( ) ;
13711372 assert_eq ! ( * v0, 13 ) ;
1373+
1374+ // Extending
1375+ v. extend ( & [ 1 , 2 ] ) ; // `slice::Iter` (with `T: Copy`) specialization
1376+ v. extend ( vec ! [ 2 , 3 ] ) ; // `vec::IntoIter` specialization
1377+ v. extend ( std:: iter:: once ( 3 ) ) ; // `TrustedLen` specialization
1378+ v. extend ( std:: iter:: empty :: < i32 > ( ) ) ; // `TrustedLen` specialization with empty iterator
1379+ v. extend ( std:: iter:: once ( 3 ) . filter ( |_| true ) ) ; // base case
1380+ v. extend ( std:: iter:: once ( & 3 ) ) ; // `cloned` specialization
1381+ assert_eq ! ( * v0, 13 ) ;
1382+
1383+ // Truncation
1384+ v. truncate ( 2 ) ;
1385+ assert_eq ! ( * v0, 13 ) ;
13721386}
13731387
13741388// https://github.com/rust-lang/rust/pull/49496 introduced specialization based on:
You can’t perform that action at this time.
0 commit comments