mirror of https://github.com/rust-lang/nomicon
Moving a `#[may_dangle]` type in `Drop::drop` asserts the validity of references stored in that type, which is unsound. For example, the following code is UB according to Miri:
```rust
#![feature(dropck_eyepatch)]
#![allow(unused)]
struct Thing<T>(Option<T>);
unsafe impl<#[may_dangle] T> Drop for Thing<T> {
fn drop(&mut self) {
let _ = self.0.take();
}
}
fn main() {
let thing;
{
let a = 1;
thing = Thing(Some(&a));
}
// thing is dropped here
}
```
pull/496/head
parent
3ff3843205
commit
8fe08f6e3e
Loading…
Reference in new issue