Open
Description
Is the following sound? In particular, is it sound to synthesize a 'static
reference to a local variable if we can prove that that variable will never go out of scope at runtime because the local scope will never finish executing?
fn with_static<T: 'static, F: FnOnce(&'static T)>(t: T, f: F) {
let tp: *const T = &t;
// SAFETY: The `loop {}` below ensures that `t` never goes
// out of scope.
let tr: &'static T = unsafe { &*tp };
f(tr);
loop {}
drop(t)
}
Metadata
Metadata
Assignees
Labels
No labels