-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Description
If I have a field that implements DerefMut
(e.g. a Box
), what stops .a.b
from going through the (uninitialized) DerefMut
?
A quick test suggests this is just allowed:
fn main() {
let mut x = std::mem::MaybeUninit::<((), Box<(u32, u32)>)>::uninit();
let p = x.as_mut_ptr();
let _ = unsafe { std::ptr::addr_of_mut!((*p).1.0); };
}
I suspect this crate would need to either change its API to require a "struct name" to use in a pattern (in the "check if accesses are safe" part of the code, since there's sadly no ref mut
pattern equivalent for raw pointers).
Or maybe try to find something that is only possible on direct fields, and DerefMut
blocks it (and it can't be something that would be bypassed by a Copy
field or if we got more features like DerefMove
or DerefGet
).
I can't come up with anything. Partial initialization could theoretically work, but it's an error in Rust today.
Metadata
Metadata
Assignees
Labels
No labels