Skip to content

Commit 56d90fa

Browse files
committed
Touch up where Alloc is imported from
1 parent 2e67cfe commit 56d90fa

File tree

2 files changed

+11
-30
lines changed

2 files changed

+11
-30
lines changed

src/destructors.md

+7-19
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,11 @@ this is totally fine.
2626
For instance, a custom implementation of `Box` might write `Drop` like this:
2727

2828
```rust
29-
#![feature(alloc, heap_api, unique, allocator_api)]
29+
#![feature(unique, allocator_api)]
3030

31-
extern crate alloc;
32-
33-
use std::ptr::{drop_in_place, Unique};
31+
use std::heap::{Heap, Alloc, Layout};
3432
use std::mem;
35-
36-
use alloc::allocator::{Layout, Alloc};
37-
use alloc::heap::Heap;
33+
use std::ptr::{drop_in_place, Unique};
3834

3935
struct Box<T>{ ptr: Unique<T> }
4036

@@ -56,16 +52,12 @@ use-after-free the `ptr` because when drop exits, it becomes inaccessible.
5652
However this wouldn't work:
5753

5854
```rust
59-
#![feature(alloc, allocator_api, heap_api, unique)]
60-
61-
extern crate alloc;
55+
#![feature(allocator_api, unique)]
6256

57+
use std::heap::{Heap, Alloc, Layout};
6358
use std::ptr::{drop_in_place, Unique};
6459
use std::mem;
6560

66-
use alloc::allocator::{Layout, Alloc};
67-
use alloc::heap::Heap;
68-
6961
struct Box<T>{ ptr: Unique<T> }
7062

7163
impl<T> Drop for Box<T> {
@@ -131,16 +123,12 @@ The classic safe solution to overriding recursive drop and allowing moving out
131123
of Self during `drop` is to use an Option:
132124

133125
```rust
134-
#![feature(alloc, allocator_api, heap_api, unique)]
135-
136-
extern crate alloc;
126+
#![feature(allocator_api, unique)]
137127

128+
use std::heap::{Alloc, Heap, Layout};
138129
use std::ptr::{drop_in_place, Unique};
139130
use std::mem;
140131

141-
use alloc::allocator::{Layout, Alloc};
142-
use alloc::heap::Heap;
143-
144132
struct Box<T>{ ptr: Unique<T> }
145133

146134
impl<T> Drop for Box<T> {

src/vec-final.md

+4-11
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,13 @@
22

33
```rust
44
#![feature(unique)]
5-
#![feature(alloc, allocator_api, heap_api)]
6-
7-
extern crate alloc;
5+
#![feature(allocator_api)]
86

97
use std::ptr::{Unique, self};
108
use std::mem;
119
use std::ops::{Deref, DerefMut};
1210
use std::marker::PhantomData;
13-
14-
use alloc::allocator::{Layout, Alloc};
15-
use alloc::heap::Heap;
11+
use std::heap::{Alloc, Layout, Heap};
1612

1713
struct RawVec<T> {
1814
ptr: Unique<T>,
@@ -64,16 +60,13 @@ impl<T> Drop for RawVec<T> {
6460
let elem_size = mem::size_of::<T>();
6561
if self.cap != 0 && elem_size != 0 {
6662
unsafe {
67-
Heap.dealloc(self.ptr.as_ptr() as *mut _, Layout::array::<T>(self.cap).unwrap());
63+
Heap.dealloc(self.ptr.as_ptr() as *mut _,
64+
Layout::array::<T>(self.cap).unwrap());
6865
}
6966
}
7067
}
7168
}
7269

73-
74-
75-
76-
7770
pub struct Vec<T> {
7871
buf: RawVec<T>,
7972
len: usize,

0 commit comments

Comments
 (0)