rust/tests/compile-fail/ptr_eq_out_of_bounds.rs
2019-06-23 20:19:26 +02:00

10 lines
385 B
Rust

fn main() {
let b = Box::new(0);
let x = (&*b as *const i32).wrapping_sub(0x800); // out-of-bounds
let b = Box::new(0);
let y = &*b as *const i32; // different allocation
// We cannot compare these even though both allocations are live -- they *could* be
// equal (with the right base addresses).
assert!(x != y); //~ ERROR invalid arithmetic on pointers
}