Why can't I make a 'static reference to a value that never goes out of scope?
If it never goes out of scope, like when a function call never returns in the main thread, then the data stays valid as long as the scope owns it, which would be for the life of the program. In that case, I should be able to reference it for the duration of the life of the program too since it stays valid for that duration, right? Here's an example of what my issue is:
fn noreturn() -> ! {
loop {}
}
fn main() {
// This value is never dropped or moved, and so it should last
// for 'static, right?
let not_dropped = 0usize;
// So I should be able to borrow it for 'static here, right?
let permanent_ref: &'static usize = ¬_dropped;
// This never returns, and so the value is never dropped
// and the data stays valid,
noreturn()
// .. but the compiler complains that not_dropped is dropped
// here even though it's never dropped. Why?
}
If the end of the scope with this value is guaranteed to never be reached, then I should be able to hold a reference to the valid values owned by the scope forever, right? Am I conceptually missing something here?