RS.CLIPPY.FROM_RAW_WITH_VOID_PTR
Creating a `Box` from a void raw pointer
This checker is a Clippy lint created by The Rust Project Contributors. The documentation shown here is a copy of the original documentation for: from_raw_with_void_ptr. Copyright ©2025 The Rust Team. All rights reserved.
What it does
Checks if we're passing a c_void raw pointer to {Box,Rc,Arc,Weak}::from_raw(_)
Why is this bad?
When dealing with c_void raw pointers in FFI, it is easy to run into the pitfall of calling from_raw with the c_void pointer.
The type signature of Box::from_raw is fn from_raw(raw: *mut T) -> Box<T>, so if you pass a *mut c_void you will get a Box<c_void> (and similarly for Rc, Arc and Weak).
For this to be safe, c_void would need to have the same memory layout as the original type, which is often not the case.
Example
let ptr = Box::into_raw(Box::new(42usize)) as *mut c_void;
let _ = unsafe { Box::from_raw(ptr) };
Use instead:
let _ = unsafe { Box::from_raw(ptr as *mut usize) };