File tree 2 files changed +8
-5
lines changed
2 files changed +8
-5
lines changed Original file line number Diff line number Diff line change @@ -1366,7 +1366,8 @@ fn test_stable_pointers() {
1366
1366
v. push ( 13 ) ;
1367
1367
1368
1368
// Laundering the lifetime -- we take care that `v` does not reallocate, so that's okay.
1369
- let v0 = unsafe { & * ( & v[ 0 ] as * const _ ) } ;
1369
+ let v0 = & mut v[ 0 ] ;
1370
+ let v0 = unsafe { & mut * ( v0 as * mut _ ) } ;
1370
1371
// Now do a bunch of things and occasionally use `v0` again to assert it is still valid.
1371
1372
1372
1373
// Pushing/inserting and popping/removing
@@ -1420,6 +1421,10 @@ fn test_stable_pointers() {
1420
1421
assert_eq ! ( * v0, 13 ) ;
1421
1422
next_then_drop ( v. splice ( 5 ..6 , vec ! [ 1 ; 10 ] . into_iter ( ) . filter ( |_| true ) ) ) ; // lower bound not exact
1422
1423
assert_eq ! ( * v0, 13 ) ;
1424
+
1425
+ // Smoke test that would fire even outside Miri if an actual relocation happened.
1426
+ * v0 -= 13 ;
1427
+ assert_eq ! ( v[ 0 ] , 0 ) ;
1423
1428
}
1424
1429
1425
1430
// https://github.com/rust-lang/rust/pull/49496 introduced specialization based on:
Original file line number Diff line number Diff line change @@ -1200,7 +1200,7 @@ impl<T> Vec<T> {
1200
1200
} else {
1201
1201
unsafe {
1202
1202
self . len -= 1 ;
1203
- Some ( ptr:: read ( self . get_unchecked ( self . len ( ) ) ) )
1203
+ Some ( ptr:: read ( self . as_ptr ( ) . add ( self . len ( ) ) ) )
1204
1204
}
1205
1205
}
1206
1206
}
@@ -2020,9 +2020,7 @@ where
2020
2020
let ( lower, _) = iterator. size_hint ( ) ;
2021
2021
let mut vector = Vec :: with_capacity ( lower. saturating_add ( 1 ) ) ;
2022
2022
unsafe {
2023
- // `vector` is new, cannot have aliases, so us getting exclusive references
2024
- // here is okay.
2025
- ptr:: write ( vector. get_unchecked_mut ( 0 ) , element) ;
2023
+ ptr:: write ( vector. as_mut_ptr ( ) , element) ;
2026
2024
vector. set_len ( 1 ) ;
2027
2025
}
2028
2026
vector
You can’t perform that action at this time.
0 commit comments