From 0d1584507ba540becb6fc78dfc2d1f8d1fc60cc1 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Sun, 4 Aug 2019 14:12:11 +0200 Subject: [PATCH 1/3] fix UB in a test --- src/libcore/tests/ptr.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/libcore/tests/ptr.rs b/src/libcore/tests/ptr.rs index 569b3197d09..df5f4faa60e 100644 --- a/src/libcore/tests/ptr.rs +++ b/src/libcore/tests/ptr.rs @@ -145,7 +145,6 @@ fn test_as_ref() { } #[test] -#[cfg(not(miri))] // This test is UB according to Stacked Borrows fn test_as_mut() { unsafe { let p: *mut isize = null_mut(); @@ -164,7 +163,7 @@ fn test_as_mut() { // Pointers to unsized types -- slices let s: &mut [u8] = &mut [1, 2, 3]; let ms: *mut [u8] = s; - assert_eq!(ms.as_mut(), Some(s)); + assert_eq!(ms.as_mut().unwrap() as *mut _, s as *mut _); let mz: *mut [u8] = &mut []; assert_eq!(mz.as_mut(), Some(&mut [][..])); From 4e51ef7ccd9729b1f9074a44ef49778a3c53c3d4 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Mon, 5 Aug 2019 11:21:15 +0200 Subject: [PATCH 2/3] Test content, not value Co-Authored-By: Aleksey Kladov --- src/libcore/tests/ptr.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libcore/tests/ptr.rs b/src/libcore/tests/ptr.rs index df5f4faa60e..d5a079da989 100644 --- a/src/libcore/tests/ptr.rs +++ b/src/libcore/tests/ptr.rs @@ -163,7 +163,7 @@ fn test_as_mut() { // Pointers to unsized types -- slices let s: &mut [u8] = &mut [1, 2, 3]; let ms: *mut [u8] = s; - assert_eq!(ms.as_mut().unwrap() as *mut _, s as *mut _); + assert_eq!(ms.as_mut(), Some(&mut [1, 2, 3])); let mz: *mut [u8] = &mut []; assert_eq!(mz.as_mut(), Some(&mut [][..])); From 90b95cf53f68888812cd5683cf44161e070e7dbd Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Mon, 5 Aug 2019 15:30:08 +0200 Subject: [PATCH 3/3] fix slice comparison Co-Authored-By: Aleksey Kladov --- src/libcore/tests/ptr.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libcore/tests/ptr.rs b/src/libcore/tests/ptr.rs index d5a079da989..1a6be3a9bbd 100644 --- a/src/libcore/tests/ptr.rs +++ b/src/libcore/tests/ptr.rs @@ -163,7 +163,7 @@ fn test_as_mut() { // Pointers to unsized types -- slices let s: &mut [u8] = &mut [1, 2, 3]; let ms: *mut [u8] = s; - assert_eq!(ms.as_mut(), Some(&mut [1, 2, 3])); + assert_eq!(ms.as_mut(), Some(&mut [1, 2, 3][..])); let mz: *mut [u8] = &mut []; assert_eq!(mz.as_mut(), Some(&mut [][..]));