From 03fe3772a8a6859b2aa890f5a002e7cc3707e326 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Sat, 20 Jun 2020 14:31:47 +0200 Subject: [PATCH] make sure the raw_ptr macros also avoid UB --- tests/run-pass/packed_struct.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/run-pass/packed_struct.rs b/tests/run-pass/packed_struct.rs index 5582caaf37e..43419695ba0 100644 --- a/tests/run-pass/packed_struct.rs +++ b/tests/run-pass/packed_struct.rs @@ -1,7 +1,8 @@ -#![feature(unsize, coerce_unsized, raw_ref_op)] +#![feature(unsize, coerce_unsized, raw_ref_op, raw_ref_macros)] use std::collections::hash_map::DefaultHasher; use std::hash::Hash; +use std::ptr; fn test_basic() { #[repr(packed)] @@ -45,7 +46,9 @@ fn test_basic() { assert_eq!({x.b}, 99); // but we *can* take a raw pointer! assert_eq!(unsafe { (&raw const x.a).read_unaligned() }, 42); + assert_eq!(unsafe { ptr::raw_const!(x.a).read_unaligned() }, 42); assert_eq!(unsafe { (&raw const x.b).read_unaligned() }, 99); + assert_eq!(unsafe { ptr::raw_const!(x.b).read_unaligned() }, 99); x.b = 77; assert_eq!({x.b}, 77);