Skip to content

Commit 03fe377

Browse files
committed
make sure the raw_ptr macros also avoid UB
1 parent a29f86b commit 03fe377

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

tests/run-pass/packed_struct.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
#![feature(unsize, coerce_unsized, raw_ref_op)]
1+
#![feature(unsize, coerce_unsized, raw_ref_op, raw_ref_macros)]
22

33
use std::collections::hash_map::DefaultHasher;
44
use std::hash::Hash;
5+
use std::ptr;
56

67
fn test_basic() {
78
#[repr(packed)]
@@ -45,7 +46,9 @@ fn test_basic() {
4546
assert_eq!({x.b}, 99);
4647
// but we *can* take a raw pointer!
4748
assert_eq!(unsafe { (&raw const x.a).read_unaligned() }, 42);
49+
assert_eq!(unsafe { ptr::raw_const!(x.a).read_unaligned() }, 42);
4850
assert_eq!(unsafe { (&raw const x.b).read_unaligned() }, 99);
51+
assert_eq!(unsafe { ptr::raw_const!(x.b).read_unaligned() }, 99);
4952

5053
x.b = 77;
5154
assert_eq!({x.b}, 77);

0 commit comments

Comments
 (0)