File tree 1 file changed +23
-0
lines changed
1 file changed +23
-0
lines changed Original file line number Diff line number Diff line change @@ -71,6 +71,26 @@ fn vec_reallocate() -> Vec<u8> {
71
71
v
72
72
}
73
73
74
+ fn vec_push_ptr_stable ( ) {
75
+ let mut v = Vec :: with_capacity ( 10 ) ;
76
+ v. push ( 0 ) ;
77
+ let v0 = unsafe { & * ( & v[ 0 ] as * const _ ) } ; // laundering the lifetime -- we take care that `v` does not reallocate, so that's okay.
78
+ v. push ( 1 ) ;
79
+ let _val = * v0;
80
+ }
81
+
82
+ fn vec_extend_ptr_stable ( ) {
83
+ let mut v = Vec :: with_capacity ( 10 ) ;
84
+ v. push ( 0 ) ;
85
+ let v0 = unsafe { & * ( & v[ 0 ] as * const _ ) } ; // laundering the lifetime -- we take care that `v` does not reallocate, so that's okay.
86
+ v. extend ( & [ 1 ] ) ;
87
+ let _val = * v0;
88
+ v. extend ( vec ! [ 2 ] ) ;
89
+ let _val = * v0;
90
+ v. extend ( std:: iter:: once ( 3 ) ) ;
91
+ let _val = * v0;
92
+ }
93
+
74
94
fn main ( ) {
75
95
assert_eq ! ( vec_reallocate( ) . len( ) , 5 ) ;
76
96
@@ -89,4 +109,7 @@ fn main() {
89
109
// Test interesting empty slice comparison
90
110
// (one is a real pointer, one an integer pointer).
91
111
assert_eq ! ( ( 200 ..-5 ) . step_by( 1 ) . collect:: <Vec <isize >>( ) , [ ] ) ;
112
+
113
+ vec_push_ptr_stable ( ) ;
114
+ vec_extend_ptr_stable ( ) ;
92
115
}
You can’t perform that action at this time.
0 commit comments