Skip to content

Commit aba2282

Browse files
committed
test Vec::extend
1 parent aaa16a5 commit aba2282

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

Diff for: tests/run-pass/vecs.rs renamed to tests/run-pass/vec.rs

+23
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,26 @@ fn vec_reallocate() -> Vec<u8> {
7171
v
7272
}
7373

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+
7494
fn main() {
7595
assert_eq!(vec_reallocate().len(), 5);
7696

@@ -89,4 +109,7 @@ fn main() {
89109
// Test interesting empty slice comparison
90110
// (one is a real pointer, one an integer pointer).
91111
assert_eq!((200..-5).step_by(1).collect::<Vec<isize>>(), []);
112+
113+
vec_push_ptr_stable();
114+
vec_extend_ptr_stable();
92115
}

0 commit comments

Comments
 (0)