We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 03fe377 commit 8d1d572Copy full SHA for 8d1d572
tests/compile-fail/unaligned_pointers/unaligned_ptr_addr_of.rs
@@ -0,0 +1,12 @@
1
+// This should fail even without validation or Stacked Borrows.
2
+// compile-flags: -Zmiri-disable-validation -Zmiri-disable-stacked-borrows
3
+#![feature(raw_ref_macros)]
4
+use std::ptr;
5
+
6
+fn main() {
7
+ let x = [2u16, 3, 4]; // Make it big enough so we don't get an out-of-bounds error.
8
+ let x = &x[0] as *const _ as *const u32;
9
+ // This must fail because alignment is violated: the allocation's base is not sufficiently aligned.
10
+ // The deref is UB even if we just put the result into a raw pointer.
11
+ let _x = unsafe { ptr::raw_const!(*x) }; //~ ERROR memory with alignment 2, but alignment 4 is required
12
+}
0 commit comments