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() {
1351
1351
}
1352
1352
1353
1353
#[ test]
1354
- fn test_stable_push_pop ( ) {
1354
+ fn test_stable_pointers ( ) {
1355
1355
// Test that, if we reserved enough space, adding and removing elements does not
1356
1356
// invalidate references into the vector (such as `v0`). This test also
1357
1357
// runs in Miri, which would detect such problems.
1358
- let mut v = Vec :: with_capacity ( 10 ) ;
1358
+ let mut v = Vec :: with_capacity ( 128 ) ;
1359
1359
v. push ( 13 ) ;
1360
1360
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.
1362
1362
let v0 = unsafe { & * ( & v[ 0 ] as * const _ ) } ;
1363
-
1364
1363
// Now do a bunch of things and occasionally use `v0` again to assert it is still valid.
1364
+
1365
+ // Pushing/inserting and popping/removing
1365
1366
v. push ( 1 ) ;
1366
1367
v. push ( 2 ) ;
1367
1368
v. insert ( 1 , 1 ) ;
1368
1369
assert_eq ! ( * v0, 13 ) ;
1369
1370
v. remove ( 1 ) ;
1370
1371
v. pop ( ) . unwrap ( ) ;
1371
1372
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 ) ;
1372
1386
}
1373
1387
1374
1388
// https://github.com/rust-lang/rust/pull/49496 introduced specialization based on:
You can’t perform that action at this time.
0 commit comments