From b8444deb64b1175152c98bd772a3fd445a77ac6e Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Mon, 23 Mar 2020 13:02:02 +0100 Subject: [PATCH] test Vec::extend --- tests/run-pass/{vecs.rs => vec.rs} | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) rename tests/run-pass/{vecs.rs => vec.rs} (73%) diff --git a/tests/run-pass/vecs.rs b/tests/run-pass/vec.rs similarity index 73% rename from tests/run-pass/vecs.rs rename to tests/run-pass/vec.rs index 739def804975..a2f448496fd9 100644 --- a/tests/run-pass/vecs.rs +++ b/tests/run-pass/vec.rs @@ -71,6 +71,26 @@ fn vec_reallocate() -> Vec { v } +fn vec_push_ptr_stable() { + let mut v = Vec::with_capacity(10); + v.push(0); + let v0 = unsafe { &*(&v[0] as *const _) }; // laundering the lifetime -- we take care that `v` does not reallocate, so that's okay. + v.push(1); + let _val = *v0; +} + +fn vec_extend_ptr_stable() { + let mut v = Vec::with_capacity(10); + v.push(0); + let v0 = unsafe { &*(&v[0] as *const _) }; // laundering the lifetime -- we take care that `v` does not reallocate, so that's okay. + v.extend(&[1]); + let _val = *v0; + v.extend(vec![2]); + let _val = *v0; + v.extend(std::iter::once(3)); + let _val = *v0; +} + fn main() { assert_eq!(vec_reallocate().len(), 5); @@ -89,4 +109,7 @@ fn main() { // Test interesting empty slice comparison // (one is a real pointer, one an integer pointer). assert_eq!((200..-5).step_by(1).collect::>(), []); + + vec_push_ptr_stable(); + vec_extend_ptr_stable(); }