1
 2
 3
 4
 5
 6
 7
 8
 9
10
use std::mem;

pub(super) fn leak<T>(v: T) -> &'static T {
    unsafe {
        let b = Box::new(v);
        let p: *const T = &*b;
        mem::forget(b); // leak our reference, so that `b` is never freed
        &*p
    }
}