Skip to content

Commit 483203a

Browse files
committed
test some more vec ptr invalidation
1 parent 9f93ec3 commit 483203a

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

tests/run-pass/vec.rs

+14
Original file line numberDiff line numberDiff line change
@@ -83,12 +83,25 @@ fn vec_extend_ptr_stable() {
8383
let mut v = Vec::with_capacity(10);
8484
v.push(0);
8585
let v0 = unsafe { &*(&v[0] as *const _) }; // laundering the lifetime -- we take care that `v` does not reallocate, so that's okay.
86+
// `slice::Iter` (with `T: Copy`) specialization
8687
v.extend(&[1]);
8788
let _val = *v0;
89+
// `vec::IntoIter` specialization
8890
v.extend(vec![2]);
8991
let _val = *v0;
92+
// `TrustedLen` specialization
9093
v.extend(std::iter::once(3));
9194
let _val = *v0;
95+
// base case
96+
v.extend(std::iter::once(3).filter(|_| true));
97+
let _val = *v0;
98+
}
99+
100+
fn vec_truncate_ptr_stable() {
101+
let mut v = vec![0; 10];
102+
let v0 = unsafe { &*(&v[0] as *const _) }; // laundering the lifetime -- we take care that `v` does not reallocate, so that's okay.
103+
v.truncate(5);
104+
let _val = *v0;
92105
}
93106

94107
fn main() {
@@ -112,4 +125,5 @@ fn main() {
112125

113126
vec_push_ptr_stable();
114127
vec_extend_ptr_stable();
128+
vec_truncate_ptr_stable();
115129
}

0 commit comments

Comments
 (0)