about summary refs log tree commit diff
path: root/src/libcore/tests
diff options
context:
space:
mode:
authorDylan DPC <dylan.dpc@gmail.com>2020-02-29 18:54:02 +0100
committerGitHub <noreply@github.com>2020-02-29 18:54:02 +0100
commit02381db8e0cd4412bec4254fd78e140e7b036fa7 (patch)
tree297c8e798f66c0e210e9463ba3f15473986b01dc /src/libcore/tests
parent7d43997053f940d3aa656a5054995a08edf5f3d4 (diff)
parentc34451ffb78e0a0851c7aa97897a1621beed8c82 (diff)
downloadrust-02381db8e0cd4412bec4254fd78e140e7b036fa7.tar.gz
rust-02381db8e0cd4412bec4254fd78e140e7b036fa7.zip
Rollup merge of #69581 - RalfJung:align_to_mut, r=Centril
fix aliasing violation in align_to_mut

Fixes https://github.com/rust-lang/rust/issues/68549

I decided to add the testcase here to make it all one PR, but if you prefer I can also add that test case in the Miri repo instead.
Diffstat (limited to 'src/libcore/tests')
-rw-r--r--src/libcore/tests/slice.rs12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/libcore/tests/slice.rs b/src/libcore/tests/slice.rs
index cc274b4aecf..dbab433e33f 100644
--- a/src/libcore/tests/slice.rs
+++ b/src/libcore/tests/slice.rs
@@ -1571,6 +1571,18 @@ fn test_align_to_empty_mid() {
 }
 
 #[test]
+fn test_align_to_mut_aliasing() {
+    let mut val = [1u8, 2, 3, 4, 5];
+    // `align_to_mut` used to create `mid` in a way that there was some intermediate
+    // incorrect aliasing, invalidating the resulting `mid` slice.
+    let (begin, mid, end) = unsafe { val.align_to_mut::<[u8; 2]>() };
+    assert!(begin.len() == 0);
+    assert!(end.len() == 1);
+    mid[0] = mid[1];
+    assert_eq!(val, [3, 4, 3, 4, 5])
+}
+
+#[test]
 fn test_slice_partition_dedup_by() {
     let mut slice: [i32; 9] = [1, -1, 2, 3, 1, -5, 5, -2, 2];