How can I make the code refused

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
    };
}

Make a constructor and use privacy to ensure you use it.

The constructor function signature ties the borrow of the String to the lifetime in the A value.

Please note when you cross post so you don't make people waste time answering a question that has already been answered elsewhere: How can I make the code refused : rust

Sorry for that, will keep in mind