rust/tests/compile-fail/ptr_eq_out_of_bounds.rs
2018-09-17 10:02:31 +02:00

10 lines
369 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 outside bounds
}