]> git.lizzy.rs Git - rust.git/commitdiff
test some more vec ptr invalidation
authorRalf Jung <post@ralfj.de>
Mon, 30 Mar 2020 08:41:44 +0000 (10:41 +0200)
committerRalf Jung <post@ralfj.de>
Sun, 5 Apr 2020 16:26:51 +0000 (18:26 +0200)
tests/run-pass/vec.rs

index a2f448496fd9af92a8acebbd2c9ac730745420e9..5304e3ed71a8e2a5bb9b8717707bdcdd80daa13c 100644 (file)
@@ -83,12 +83,25 @@ 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.
+    // `slice::Iter` (with `T: Copy`) specialization
     v.extend(&[1]);
     let _val = *v0;
+    // `vec::IntoIter` specialization
     v.extend(vec![2]);
     let _val = *v0;
+    // `TrustedLen` specialization
     v.extend(std::iter::once(3));
     let _val = *v0;
+    // base case
+    v.extend(std::iter::once(3).filter(|_| true));
+    let _val = *v0;
+}
+
+fn vec_truncate_ptr_stable() {
+    let mut v = vec![0; 10];
+    let v0 = unsafe { &*(&v[0] as *const _) }; // laundering the lifetime -- we take care that `v` does not reallocate, so that's okay.
+    v.truncate(5);
+    let _val = *v0;
 }
 
 fn main() {
@@ -112,4 +125,5 @@ fn main() {
 
     vec_push_ptr_stable();
     vec_extend_ptr_stable();
+    vec_truncate_ptr_stable();
 }