Closed
Description
I am a bit confused about the "Cell::as_ptr()", user can escape the compiler check, and may still use the raw pointer after the cell is moved.
#[derive(Debug)]
struct Inner(isize);
impl Drop for Inner {
fn drop(&mut self) {
println!("drop inner {:?}", self as *const _);
}
}
let m = Cell::new(Inner(0));
let m_ptr = m.as_ptr();
println!("before move: {:?}", m.as_ptr());
let h = thread::spawn(move || {
// the `m` cell underlying data has different address after move
println!("after move: {:?}", m.as_ptr());
// `m` drop
});
// we can still read/write the original address after moving `m`
// should it be UB?
// if yes, miri does not report it
// If not, what does the address really means?
unsafe {println!("m_ptr: {:?}, value: {:?}", m_ptr, *m_ptr)};
Metadata
Metadata
Assignees
Labels
No labels