diff --git a/rust-version b/rust-version index 895cbb5fa9..6e980a4e22 100644 --- a/rust-version +++ b/rust-version @@ -1 +1 @@ -6050e523bae6de61de4e060facc43dc512adaccd +e6cef0445779724b469ab7b9a8d3c05d9e848ca8 diff --git a/tests/run-pass/floats.rs b/tests/run-pass/float.rs similarity index 100% rename from tests/run-pass/floats.rs rename to tests/run-pass/float.rs diff --git a/tests/run-pass/vecs.rs b/tests/run-pass/vec.rs similarity index 60% rename from tests/run-pass/vecs.rs rename to tests/run-pass/vec.rs index 739def8049..5c791e4db0 100644 --- a/tests/run-pass/vecs.rs +++ b/tests/run-pass/vec.rs @@ -71,6 +71,39 @@ fn vec_reallocate() -> Vec { v } +fn vec_push_ptr_stable() { + let mut v = Vec::with_capacity(10); + v.push(0); + let v0 = unsafe { &mut *(&mut v[0] as *mut _) }; // 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 { &mut *(&mut v[0] as *mut _) }; // 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 { &mut *(&mut v[0] as *mut _) }; // laundering the lifetime -- we take care that `v` does not reallocate, so that's okay. + v.truncate(5); + let _val = *v0; +} + fn main() { assert_eq!(vec_reallocate().len(), 5); @@ -89,4 +122,9 @@ fn main() { // Test interesting empty slice comparison // (one is a real pointer, one an integer pointer). assert_eq!((200..-5).step_by(1).collect::>(), []); + + // liballoc has a more extensive test of this, but let's at least do a smoke test here. + vec_push_ptr_stable(); + vec_extend_ptr_stable(); + vec_truncate_ptr_stable(); }