Skip to content

Commit 79e60b5

Browse files
authored
Merge pull request #248 from JohnTitor/allocator
Rename `AllocRef` to `Allocator` and `(de)alloc` to `(de)allocate`
2 parents d8383b6 + 3fd89d6 commit 79e60b5

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

src/destructors.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ For instance, a custom implementation of `Box` might write `Drop` like this:
2828
```rust
2929
#![feature(ptr_internals, allocator_api)]
3030

31-
use std::alloc::{AllocRef, Global, GlobalAlloc, Layout};
31+
use std::alloc::{Allocator, Global, GlobalAlloc, Layout};
3232
use std::mem;
3333
use std::ptr::{drop_in_place, NonNull, Unique};
3434

@@ -39,7 +39,7 @@ impl<T> Drop for Box<T> {
3939
unsafe {
4040
drop_in_place(self.ptr.as_ptr());
4141
let c: NonNull<T> = self.ptr.into();
42-
Global.dealloc(c.cast(), Layout::new::<T>())
42+
Global.deallocate(c.cast(), Layout::new::<T>())
4343
}
4444
}
4545
}
@@ -55,7 +55,7 @@ However this wouldn't work:
5555
```rust
5656
#![feature(allocator_api, ptr_internals)]
5757

58-
use std::alloc::{AllocRef, Global, GlobalAlloc, Layout};
58+
use std::alloc::{Allocator, Global, GlobalAlloc, Layout};
5959
use std::ptr::{drop_in_place, Unique, NonNull};
6060
use std::mem;
6161

@@ -66,7 +66,7 @@ impl<T> Drop for Box<T> {
6666
unsafe {
6767
drop_in_place(self.ptr.as_ptr());
6868
let c: NonNull<T> = self.ptr.into();
69-
Global.dealloc(c.cast(), Layout::new::<T>());
69+
Global.deallocate(c.cast(), Layout::new::<T>());
7070
}
7171
}
7272
}
@@ -79,7 +79,7 @@ impl<T> Drop for SuperBox<T> {
7979
// Hyper-optimized: deallocate the box's contents for it
8080
// without `drop`ing the contents
8181
let c: NonNull<T> = self.my_box.ptr.into();
82-
Global.dealloc(c.cast::<u8>(), Layout::new::<T>());
82+
Global.deallocate(c.cast::<u8>(), Layout::new::<T>());
8383
}
8484
}
8585
}
@@ -128,7 +128,7 @@ of Self during `drop` is to use an Option:
128128
```rust
129129
#![feature(allocator_api, ptr_internals)]
130130

131-
use std::alloc::{AllocRef, GlobalAlloc, Global, Layout};
131+
use std::alloc::{Allocator, GlobalAlloc, Global, Layout};
132132
use std::ptr::{drop_in_place, Unique, NonNull};
133133
use std::mem;
134134

@@ -139,7 +139,7 @@ impl<T> Drop for Box<T> {
139139
unsafe {
140140
drop_in_place(self.ptr.as_ptr());
141141
let c: NonNull<T> = self.ptr.into();
142-
Global.dealloc(c.cast(), Layout::new::<T>());
142+
Global.deallocate(c.cast(), Layout::new::<T>());
143143
}
144144
}
145145
}
@@ -154,7 +154,7 @@ impl<T> Drop for SuperBox<T> {
154154
// field as `None` to prevent Rust from trying to Drop it.
155155
let my_box = self.my_box.take().unwrap();
156156
let c: NonNull<T> = my_box.ptr.into();
157-
Global.dealloc(c.cast(), Layout::new::<T>());
157+
Global.deallocate(c.cast(), Layout::new::<T>());
158158
mem::forget(my_box);
159159
}
160160
}

src/vec-final.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use std::mem;
1010
use std::ops::{Deref, DerefMut};
1111
use std::marker::PhantomData;
1212
use std::alloc::{
13-
AllocRef,
13+
Allocator,
1414
Global,
1515
GlobalAlloc,
1616
Layout,
@@ -40,7 +40,7 @@ impl<T> RawVec<T> {
4040
assert!(elem_size != 0, "capacity overflow");
4141

4242
let (new_cap, ptr) = if self.cap == 0 {
43-
let ptr = Global.alloc(Layout::array::<T>(1).unwrap());
43+
let ptr = Global.allocate(Layout::array::<T>(1).unwrap());
4444
(1, ptr)
4545
} else {
4646
let new_cap = 2 * self.cap;
@@ -72,7 +72,7 @@ impl<T> Drop for RawVec<T> {
7272
if self.cap != 0 && elem_size != 0 {
7373
unsafe {
7474
let c: NonNull<T> = self.ptr.into();
75-
Global.dealloc(c.cast(),
75+
Global.deallocate(c.cast(),
7676
Layout::array::<T>(self.cap).unwrap());
7777
}
7878
}

0 commit comments

Comments
 (0)