Closed
Description
I tried this code:
use core::cell::Cell;
use core::marker::PhantomData as PDOrBox;
//use std::boxed::Box as PDOrBox;
struct Foo<'a> {
selfref: Cell<Option<&'a Foo<'a>>>,
}
impl<'a> Drop for Foo<'a> {
fn drop(&mut self) {
}
}
fn make_selfref<'a>(x: &'a PDOrBox<Foo<'a>>) {}
fn make_pdorbox<'a>() -> PDOrBox<Foo<'a>> {
unimplemented!()
}
fn main() {
let x = make_pdorbox();
make_selfref(&x);
}
I expected to see this happen: since a PhantomData
claims to act like a T
including for the purposes of borrowck/dropck then this should absolutely compile-fail. just as it does if you use a Box
, or T
directly!
Instead, this happened: it doesn't!
this is clearly unsound.
Meta
rustc --version --verbose
:
playground
Backtrace
<backtrace>