You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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)]structInner(isize);implDropforInner{fndrop(&mutself){println!("drop inner {:?}", selfas *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 moveprintln!("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)};
The text was updated successfully, but these errors were encountered:
gftea
changed the title
is it UB or not if using cell as ptr as below
is it UB or not if using cell's underlying data raw ptr after cell is moved
Feb 22, 2023
So the answer to "is this UB" is - maybe. It hasn't been decided yet, and it is not clear how to best make Miri detect these csses.
@oli-obk, that would be possible (thougj not easy) with stacked borrows but with the plans we have for raw pointers in tree borrows it becomes a lot harder at best.
rust playground
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.
The text was updated successfully, but these errors were encountered: