There are UB in the code, but rustc allows it, so there are errors in in my code
I think phantomdata may help, turns out it does not, at least used like here
use std::marker::PhantomData;
use std::fmt::Display;
use std::ptr::NonNull;
struct A<'a, T: Display> {
a: NonNull<T>,
b: PhantomData<&'a mut T>
}
impl<'a, T: Display> Drop for A<'a, T> {
fn drop(&mut self) {
println!("{}", unsafe {self.a.as_ref()});
}
}
fn main() {
let x: A<String>;
let mut s = "string".into();
x = A {
a: NonNull::new(&mut s).unwrap(),
b: PhantomData
};
}