Closed
Description
e.g. Box<T>
potentially has a validity requirement of being dereferencable. <Box<T> as Drop>::drop
obviously breaks this requirement, and at the end of the function, the Box<T>
still exists, but the pointer is now dangling.
That one is probably directly handled by #[may_dangle]
, so what about this minimal example:
struct Weird(NonZeroU8);
impl Drop for Weird {
fn drop(&mut self) {
unsafe { ptr::write(self as *mut Weird as *mut u8, 0u8) }; // <--- HERE
}
}
fn main() {
let w = Some(Weird(NonZeroU8::new(1).unwrap()));
drop(w);
}
Does the indicated line invoke UB? When the allocated place is Weird
? When the allocated place is Option<Weird>
(#204 IIRC)?
Metadata
Metadata
Assignees
Labels
No labels