Example in README.md does not compile
Created by: rnestler
In the README there are a few examples showing debug checks of ralloc. One of them doesn't compile for me:
extern crate ralloc;
fn main() {
// We start by allocating some stuff.
let a = Box::new(500u32);
// Then we memcpy the pointer (this is UB).
let b = Box::from_raw(&a as *mut u32);
// Now both destructors are called. First a, then b, which is a double
// free. Luckily, ralloc provides a nice message for you, when in debug
// tools mode:
// Assertion failed: Double free.
// Setting RUST_BACKTRACE allows you to get a stack backtrace, so that you
// can find where the double free occurs.
}
Leads to the following error:
src/main.rs:5:27: 5:41 error: casting `&Box<u32>` as `*mut u32` is invalid
src/main.rs:5 let b = Box::from_raw(&a as *mut u32);
^~~~~~~~~~~~~~
I somehow expected this not to compile because there was no unsafe
block. Is this intended?