Closed
Description
Consider this code:
use std::marker::PhantomData;
struct Pending<T> {
phantom: PhantomData<T>,
}
fn pending<T>(value: T) -> Pending<T> {
Pending {
phantom: PhantomData,
}
}
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 });
}
I believe it should not compile (by failing dropcheck). It, however, compiles and runs on 1.42 and 1.31. On 1.24 it indeed fails as I expect.
The equivalent code, where PhantomData<T>
is replaced with T
rightfully fails to compiles: Playground. So, dropchk somehow observes the difference between T
and PhantomData<T>
?
Either I misunderstand how PhantomData<T>
is supposed to work, or this is a stable-to-stable regression and a soundless hole.