std::ffi::c_void
ptr in from_raw
RS-W1118Passing a c_void
raw pointer to {Box,Rc,Arc,Weak}::from_raw(_)
results in a
Box<c_void>
or Rc<c_void>
or Weak<c_void>
, which would need to have
the same memory layout as the expected type T
. This is often not the case
and can lead to undefined behaviour, creating hard-to-track bugs.
fn foo() {
let ptr = Box::into_raw(Box::new(42usize)) as *mut c_void;
let _ = unsafe { Box::from_raw(ptr) };
}
fn foo() {
let _ = unsafe { Box::from_raw(ptr as *mut usize) };
}