code from https://github.com/rust-lang/rust/issues/70841.
My question is since NLL is born to be None lexical lifetime.
Then why NLL can't make p's lifetime to begin at p = pending(Inspector { value: &s });
, which will make the code compiled
And in this post: What is effect of the " forcing the lifetime to be invariant"? - #19 by zylthinking
Seems the compiler is smart enough and is willing to try its best to make codes compiled.
Then why it does not try harder this time?
use std::marker::PhantomData;
struct Pending<T> {
phantom: T,
}
fn pending<T>(value: T) -> Pending<T> {
Pending {
phantom: T,
}
}
struct Inspector<'a> {
value: &'a String,
}
impl Drop for Inspector<'_> {
fn drop(&mut self) {
eprintln!("drop inspector {}", self.value)
}
}
fn main() {
let p: Pending<Inspector>;
let s = "hello".to_string();
p = pending(Inspector { value: &s });
}