@@ -26,15 +26,11 @@ this is totally fine.
26
26
For instance, a custom implementation of ` Box ` might write ` Drop ` like this:
27
27
28
28
``` rust
29
- #![feature(alloc, heap_api, unique, allocator_api)]
29
+ #![feature(unique, allocator_api)]
30
30
31
- extern crate alloc;
32
-
33
- use std :: ptr :: {drop_in_place, Unique };
31
+ use std :: heap :: {Heap , Alloc , Layout };
34
32
use std :: mem;
35
-
36
- use alloc :: allocator :: {Layout , Alloc };
37
- use alloc :: heap :: Heap ;
33
+ use std :: ptr :: {drop_in_place, Unique };
38
34
39
35
struct Box <T >{ ptr : Unique <T > }
40
36
@@ -56,16 +52,12 @@ use-after-free the `ptr` because when drop exits, it becomes inaccessible.
56
52
However this wouldn't work:
57
53
58
54
``` rust
59
- #![feature(alloc, allocator_api, heap_api, unique)]
60
-
61
- extern crate alloc;
55
+ #![feature(allocator_api, unique)]
62
56
57
+ use std :: heap :: {Heap , Alloc , Layout };
63
58
use std :: ptr :: {drop_in_place, Unique };
64
59
use std :: mem;
65
60
66
- use alloc :: allocator :: {Layout , Alloc };
67
- use alloc :: heap :: Heap ;
68
-
69
61
struct Box <T >{ ptr : Unique <T > }
70
62
71
63
impl <T > Drop for Box <T > {
@@ -131,16 +123,12 @@ The classic safe solution to overriding recursive drop and allowing moving out
131
123
of Self during ` drop ` is to use an Option:
132
124
133
125
``` rust
134
- #![feature(alloc, allocator_api, heap_api, unique)]
135
-
136
- extern crate alloc;
126
+ #![feature(allocator_api, unique)]
137
127
128
+ use std :: heap :: {Alloc , Heap , Layout };
138
129
use std :: ptr :: {drop_in_place, Unique };
139
130
use std :: mem;
140
131
141
- use alloc :: allocator :: {Layout , Alloc };
142
- use alloc :: heap :: Heap ;
143
-
144
132
struct Box <T >{ ptr : Unique <T > }
145
133
146
134
impl <T > Drop for Box <T > {
0 commit comments