Ok, here's a modified version that reveals the horrifying truth!
macro_rules! show {
($ptr:ident) => {
println!("{} at 0x{:016x} → 0x{:016x}",
stringify!($ptr),
(&$ptr) as *const _ as usize,
(&*$ptr) as *const _ as usize
);
};
}
fn bar() {
let d = Box::new(5);
show!(d);
let e = &d;
show!(e);
baz(e);
}
fn baz(f: &i32) {
show!(f);
}
fn main() {
bar();
}
Output:
d at 0x00007fffb35c10a8 → 0x00007fee14c23010
e at 0x00007fffb35c0fa8 → 0x00007fffb35c10a8
f at 0x00007fffb35c0e50 → 0x00007fee14c23010