|
|
@ -26,12 +26,11 @@ this is totally fine.
|
|
|
|
For instance, a custom implementation of `Box` might write `Drop` like this:
|
|
|
|
For instance, a custom implementation of `Box` might write `Drop` like this:
|
|
|
|
|
|
|
|
|
|
|
|
```rust
|
|
|
|
```rust
|
|
|
|
#![feature(alloc, heap_api, core_intrinsics, unique)]
|
|
|
|
#![feature(alloc, heap_api, drop_in_place, unique)]
|
|
|
|
|
|
|
|
|
|
|
|
extern crate alloc;
|
|
|
|
extern crate alloc;
|
|
|
|
|
|
|
|
|
|
|
|
use std::ptr::Unique;
|
|
|
|
use std::ptr::{drop_in_place, Unique};
|
|
|
|
use std::intrinsics::drop_in_place;
|
|
|
|
|
|
|
|
use std::mem;
|
|
|
|
use std::mem;
|
|
|
|
|
|
|
|
|
|
|
|
use alloc::heap;
|
|
|
|
use alloc::heap;
|
|
|
@ -58,12 +57,11 @@ use-after-free the `ptr` because when drop exits, it becomes inaccessible.
|
|
|
|
However this wouldn't work:
|
|
|
|
However this wouldn't work:
|
|
|
|
|
|
|
|
|
|
|
|
```rust
|
|
|
|
```rust
|
|
|
|
#![feature(alloc, heap_api, core_intrinsics, unique)]
|
|
|
|
#![feature(alloc, heap_api, drop_in_place, unique)]
|
|
|
|
|
|
|
|
|
|
|
|
extern crate alloc;
|
|
|
|
extern crate alloc;
|
|
|
|
|
|
|
|
|
|
|
|
use std::ptr::Unique;
|
|
|
|
use std::ptr::{drop_in_place, Unique};
|
|
|
|
use std::intrinsics::drop_in_place;
|
|
|
|
|
|
|
|
use std::mem;
|
|
|
|
use std::mem;
|
|
|
|
|
|
|
|
|
|
|
|
use alloc::heap;
|
|
|
|
use alloc::heap;
|
|
|
@ -137,12 +135,11 @@ The classic safe solution to overriding recursive drop and allowing moving out
|
|
|
|
of Self during `drop` is to use an Option:
|
|
|
|
of Self during `drop` is to use an Option:
|
|
|
|
|
|
|
|
|
|
|
|
```rust
|
|
|
|
```rust
|
|
|
|
#![feature(alloc, heap_api, core_intrinsics, unique)]
|
|
|
|
#![feature(alloc, heap_api, drop_in_place, unique)]
|
|
|
|
|
|
|
|
|
|
|
|
extern crate alloc;
|
|
|
|
extern crate alloc;
|
|
|
|
|
|
|
|
|
|
|
|
use std::ptr::Unique;
|
|
|
|
use std::ptr::{drop_in_place, Unique};
|
|
|
|
use std::intrinsics::drop_in_place;
|
|
|
|
|
|
|
|
use std::mem;
|
|
|
|
use std::mem;
|
|
|
|
|
|
|
|
|
|
|
|
use alloc::heap;
|
|
|
|
use alloc::heap;
|
|
|
|