Skip to content

Commit f607a38

Browse files
committed
Rename alloc::Void to alloc::Opaque
1 parent ed29777 commit f607a38

File tree

18 files changed

+139
-140
lines changed

18 files changed

+139
-140
lines changed

src/doc/nomicon

src/doc/unstable-book/src/language-features/global-allocator.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,17 @@ looks like:
2929
```rust
3030
#![feature(global_allocator, allocator_api, heap_api)]
3131

32-
use std::alloc::{GlobalAlloc, System, Layout, Void};
32+
use std::alloc::{GlobalAlloc, System, Layout, Opaque};
3333
use std::ptr::NonNull;
3434

3535
struct MyAllocator;
3636

3737
unsafe impl GlobalAlloc for MyAllocator {
38-
unsafe fn alloc(&self, layout: Layout) -> *mut Void {
38+
unsafe fn alloc(&self, layout: Layout) -> *mut Opaque {
3939
System.alloc(layout)
4040
}
4141

42-
unsafe fn dealloc(&self, ptr: *mut Void, layout: Layout) {
42+
unsafe fn dealloc(&self, ptr: *mut Opaque, layout: Layout) {
4343
System.dealloc(ptr, layout)
4444
}
4545
}

src/liballoc/alloc.rs

+13-13
Original file line numberDiff line numberDiff line change
@@ -76,36 +76,36 @@ pub const Heap: Global = Global;
7676

7777
unsafe impl GlobalAlloc for Global {
7878
#[inline]
79-
unsafe fn alloc(&self, layout: Layout) -> *mut Void {
79+
unsafe fn alloc(&self, layout: Layout) -> *mut Opaque {
8080
#[cfg(not(stage0))]
8181
let ptr = __rust_alloc(layout.size(), layout.align());
8282
#[cfg(stage0)]
8383
let ptr = __rust_alloc(layout.size(), layout.align(), &mut 0);
84-
ptr as *mut Void
84+
ptr as *mut Opaque
8585
}
8686

8787
#[inline]
88-
unsafe fn dealloc(&self, ptr: *mut Void, layout: Layout) {
88+
unsafe fn dealloc(&self, ptr: *mut Opaque, layout: Layout) {
8989
__rust_dealloc(ptr as *mut u8, layout.size(), layout.align())
9090
}
9191

9292
#[inline]
93-
unsafe fn realloc(&self, ptr: *mut Void, layout: Layout, new_size: usize) -> *mut Void {
93+
unsafe fn realloc(&self, ptr: *mut Opaque, layout: Layout, new_size: usize) -> *mut Opaque {
9494
#[cfg(not(stage0))]
9595
let ptr = __rust_realloc(ptr as *mut u8, layout.size(), layout.align(), new_size);
9696
#[cfg(stage0)]
9797
let ptr = __rust_realloc(ptr as *mut u8, layout.size(), layout.align(),
9898
new_size, layout.align(), &mut 0);
99-
ptr as *mut Void
99+
ptr as *mut Opaque
100100
}
101101

102102
#[inline]
103-
unsafe fn alloc_zeroed(&self, layout: Layout) -> *mut Void {
103+
unsafe fn alloc_zeroed(&self, layout: Layout) -> *mut Opaque {
104104
#[cfg(not(stage0))]
105105
let ptr = __rust_alloc_zeroed(layout.size(), layout.align());
106106
#[cfg(stage0)]
107107
let ptr = __rust_alloc_zeroed(layout.size(), layout.align(), &mut 0);
108-
ptr as *mut Void
108+
ptr as *mut Opaque
109109
}
110110

111111
#[inline]
@@ -121,27 +121,27 @@ unsafe impl GlobalAlloc for Global {
121121

122122
unsafe impl Alloc for Global {
123123
#[inline]
124-
unsafe fn alloc(&mut self, layout: Layout) -> Result<NonNull<Void>, AllocErr> {
124+
unsafe fn alloc(&mut self, layout: Layout) -> Result<NonNull<Opaque>, AllocErr> {
125125
NonNull::new(GlobalAlloc::alloc(self, layout)).ok_or(AllocErr)
126126
}
127127

128128
#[inline]
129-
unsafe fn dealloc(&mut self, ptr: NonNull<Void>, layout: Layout) {
129+
unsafe fn dealloc(&mut self, ptr: NonNull<Opaque>, layout: Layout) {
130130
GlobalAlloc::dealloc(self, ptr.as_ptr(), layout)
131131
}
132132

133133
#[inline]
134134
unsafe fn realloc(&mut self,
135-
ptr: NonNull<Void>,
135+
ptr: NonNull<Opaque>,
136136
layout: Layout,
137137
new_size: usize)
138-
-> Result<NonNull<Void>, AllocErr>
138+
-> Result<NonNull<Opaque>, AllocErr>
139139
{
140140
NonNull::new(GlobalAlloc::realloc(self, ptr.as_ptr(), layout, new_size)).ok_or(AllocErr)
141141
}
142142

143143
#[inline]
144-
unsafe fn alloc_zeroed(&mut self, layout: Layout) -> Result<NonNull<Void>, AllocErr> {
144+
unsafe fn alloc_zeroed(&mut self, layout: Layout) -> Result<NonNull<Opaque>, AllocErr> {
145145
NonNull::new(GlobalAlloc::alloc_zeroed(self, layout)).ok_or(AllocErr)
146146
}
147147

@@ -178,7 +178,7 @@ pub(crate) unsafe fn box_free<T: ?Sized>(ptr: *mut T) {
178178
// We do not allocate for Box<T> when T is ZST, so deallocation is also not necessary.
179179
if size != 0 {
180180
let layout = Layout::from_size_align_unchecked(size, align);
181-
Global.dealloc(ptr as *mut Void, layout);
181+
Global.dealloc(ptr as *mut Opaque, layout);
182182
}
183183
}
184184

src/liballoc/arc.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -518,7 +518,7 @@ impl<T: ?Sized> Arc<T> {
518518

519519
if self.inner().weak.fetch_sub(1, Release) == 1 {
520520
atomic::fence(Acquire);
521-
Global.dealloc(self.ptr.as_void(), Layout::for_value(self.ptr.as_ref()))
521+
Global.dealloc(self.ptr.as_opaque(), Layout::for_value(self.ptr.as_ref()))
522522
}
523523
}
524524

@@ -637,7 +637,7 @@ impl<T: Clone> ArcFromSlice<T> for Arc<[T]> {
637637
let slice = from_raw_parts_mut(self.elems, self.n_elems);
638638
ptr::drop_in_place(slice);
639639

640-
Global.dealloc(self.mem.as_void(), self.layout.clone());
640+
Global.dealloc(self.mem.as_opaque(), self.layout.clone());
641641
}
642642
}
643643
}
@@ -1156,7 +1156,7 @@ impl<T: ?Sized> Drop for Weak<T> {
11561156
if self.inner().weak.fetch_sub(1, Release) == 1 {
11571157
atomic::fence(Acquire);
11581158
unsafe {
1159-
Global.dealloc(self.ptr.as_void(), Layout::for_value(self.ptr.as_ref()))
1159+
Global.dealloc(self.ptr.as_opaque(), Layout::for_value(self.ptr.as_ref()))
11601160
}
11611161
}
11621162
}

src/liballoc/btree/node.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ impl<K, V> Root<K, V> {
249249
self.as_mut().as_leaf_mut().parent = ptr::null();
250250

251251
unsafe {
252-
Global.dealloc(NonNull::from(top).as_void(), Layout::new::<InternalNode<K, V>>());
252+
Global.dealloc(NonNull::from(top).as_opaque(), Layout::new::<InternalNode<K, V>>());
253253
}
254254
}
255255
}
@@ -435,7 +435,7 @@ impl<K, V> NodeRef<marker::Owned, K, V, marker::Leaf> {
435435
> {
436436
let node = self.node;
437437
let ret = self.ascend().ok();
438-
Global.dealloc(node.as_void(), Layout::new::<LeafNode<K, V>>());
438+
Global.dealloc(node.as_opaque(), Layout::new::<LeafNode<K, V>>());
439439
ret
440440
}
441441
}
@@ -456,7 +456,7 @@ impl<K, V> NodeRef<marker::Owned, K, V, marker::Internal> {
456456
> {
457457
let node = self.node;
458458
let ret = self.ascend().ok();
459-
Global.dealloc(node.as_void(), Layout::new::<InternalNode<K, V>>());
459+
Global.dealloc(node.as_opaque(), Layout::new::<InternalNode<K, V>>());
460460
ret
461461
}
462462
}
@@ -1239,12 +1239,12 @@ impl<'a, K, V> Handle<NodeRef<marker::Mut<'a>, K, V, marker::Internal>, marker::
12391239
}
12401240

12411241
Global.dealloc(
1242-
right_node.node.as_void(),
1242+
right_node.node.as_opaque(),
12431243
Layout::new::<InternalNode<K, V>>(),
12441244
);
12451245
} else {
12461246
Global.dealloc(
1247-
right_node.node.as_void(),
1247+
right_node.node.as_opaque(),
12481248
Layout::new::<LeafNode<K, V>>(),
12491249
);
12501250
}

src/liballoc/heap.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
#![allow(deprecated)]
1212

13-
pub use alloc::{Layout, AllocErr, CannotReallocInPlace, Void};
13+
pub use alloc::{Layout, AllocErr, CannotReallocInPlace, Opaque};
1414
use core::alloc::Alloc as CoreAlloc;
1515
use core::ptr::NonNull;
1616

@@ -54,7 +54,7 @@ unsafe impl<T> Alloc for T where T: CoreAlloc {
5454
}
5555

5656
unsafe fn dealloc(&mut self, ptr: *mut u8, layout: Layout) {
57-
let ptr = NonNull::new_unchecked(ptr as *mut Void);
57+
let ptr = NonNull::new_unchecked(ptr as *mut Opaque);
5858
CoreAlloc::dealloc(self, ptr, layout)
5959
}
6060

@@ -70,7 +70,7 @@ unsafe impl<T> Alloc for T where T: CoreAlloc {
7070
ptr: *mut u8,
7171
layout: Layout,
7272
new_layout: Layout) -> Result<*mut u8, AllocErr> {
73-
let ptr = NonNull::new_unchecked(ptr as *mut Void);
73+
let ptr = NonNull::new_unchecked(ptr as *mut Opaque);
7474
CoreAlloc::realloc(self, ptr, layout, new_layout.size()).map(|ptr| ptr.cast().as_ptr())
7575
}
7676

@@ -87,7 +87,7 @@ unsafe impl<T> Alloc for T where T: CoreAlloc {
8787
ptr: *mut u8,
8888
layout: Layout,
8989
new_layout: Layout) -> Result<Excess, AllocErr> {
90-
let ptr = NonNull::new_unchecked(ptr as *mut Void);
90+
let ptr = NonNull::new_unchecked(ptr as *mut Opaque);
9191
CoreAlloc::realloc_excess(self, ptr, layout, new_layout.size())
9292
.map(|e| Excess(e.0 .cast().as_ptr(), e.1))
9393
}
@@ -96,15 +96,15 @@ unsafe impl<T> Alloc for T where T: CoreAlloc {
9696
ptr: *mut u8,
9797
layout: Layout,
9898
new_layout: Layout) -> Result<(), CannotReallocInPlace> {
99-
let ptr = NonNull::new_unchecked(ptr as *mut Void);
99+
let ptr = NonNull::new_unchecked(ptr as *mut Opaque);
100100
CoreAlloc::grow_in_place(self, ptr, layout, new_layout.size())
101101
}
102102

103103
unsafe fn shrink_in_place(&mut self,
104104
ptr: *mut u8,
105105
layout: Layout,
106106
new_layout: Layout) -> Result<(), CannotReallocInPlace> {
107-
let ptr = NonNull::new_unchecked(ptr as *mut Void);
107+
let ptr = NonNull::new_unchecked(ptr as *mut Opaque);
108108
CoreAlloc::shrink_in_place(self, ptr, layout, new_layout.size())
109109
}
110110
}

src/liballoc/raw_vec.rs

+11-11
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ impl<T, A: Alloc> RawVec<T, A> {
9090

9191
// handles ZSTs and `cap = 0` alike
9292
let ptr = if alloc_size == 0 {
93-
NonNull::<T>::dangling().as_void()
93+
NonNull::<T>::dangling().as_opaque()
9494
} else {
9595
let align = mem::align_of::<T>();
9696
let result = if zeroed {
@@ -310,7 +310,7 @@ impl<T, A: Alloc> RawVec<T, A> {
310310
let new_cap = 2 * self.cap;
311311
let new_size = new_cap * elem_size;
312312
alloc_guard(new_size).expect("capacity overflow");
313-
let ptr_res = self.a.realloc(NonNull::from(self.ptr).as_void(),
313+
let ptr_res = self.a.realloc(NonNull::from(self.ptr).as_opaque(),
314314
cur,
315315
new_size);
316316
match ptr_res {
@@ -369,7 +369,7 @@ impl<T, A: Alloc> RawVec<T, A> {
369369
let new_cap = 2 * self.cap;
370370
let new_size = new_cap * elem_size;
371371
alloc_guard(new_size).expect("capacity overflow");
372-
match self.a.grow_in_place(NonNull::from(self.ptr).as_void(), old_layout, new_size) {
372+
match self.a.grow_in_place(NonNull::from(self.ptr).as_opaque(), old_layout, new_size) {
373373
Ok(_) => {
374374
// We can't directly divide `size`.
375375
self.cap = new_cap;
@@ -426,7 +426,7 @@ impl<T, A: Alloc> RawVec<T, A> {
426426
let res = match self.current_layout() {
427427
Some(layout) => {
428428
debug_assert!(new_layout.align() == layout.align());
429-
self.a.realloc(NonNull::from(self.ptr).as_void(), layout, new_layout.size())
429+
self.a.realloc(NonNull::from(self.ptr).as_opaque(), layout, new_layout.size())
430430
}
431431
None => self.a.alloc(new_layout),
432432
};
@@ -535,7 +535,7 @@ impl<T, A: Alloc> RawVec<T, A> {
535535
let res = match self.current_layout() {
536536
Some(layout) => {
537537
debug_assert!(new_layout.align() == layout.align());
538-
self.a.realloc(NonNull::from(self.ptr).as_void(), layout, new_layout.size())
538+
self.a.realloc(NonNull::from(self.ptr).as_opaque(), layout, new_layout.size())
539539
}
540540
None => self.a.alloc(new_layout),
541541
};
@@ -601,7 +601,7 @@ impl<T, A: Alloc> RawVec<T, A> {
601601
// FIXME: may crash and burn on over-reserve
602602
alloc_guard(new_layout.size()).expect("capacity overflow");
603603
match self.a.grow_in_place(
604-
NonNull::from(self.ptr).as_void(), old_layout, new_layout.size(),
604+
NonNull::from(self.ptr).as_opaque(), old_layout, new_layout.size(),
605605
) {
606606
Ok(_) => {
607607
self.cap = new_cap;
@@ -662,7 +662,7 @@ impl<T, A: Alloc> RawVec<T, A> {
662662
let new_size = elem_size * amount;
663663
let align = mem::align_of::<T>();
664664
let old_layout = Layout::from_size_align_unchecked(old_size, align);
665-
match self.a.realloc(NonNull::from(self.ptr).as_void(),
665+
match self.a.realloc(NonNull::from(self.ptr).as_opaque(),
666666
old_layout,
667667
new_size) {
668668
Ok(p) => self.ptr = p.cast().into(),
@@ -698,7 +698,7 @@ impl<T, A: Alloc> RawVec<T, A> {
698698
let elem_size = mem::size_of::<T>();
699699
if elem_size != 0 {
700700
if let Some(layout) = self.current_layout() {
701-
self.a.dealloc(NonNull::from(self.ptr).as_void(), layout);
701+
self.a.dealloc(NonNull::from(self.ptr).as_opaque(), layout);
702702
}
703703
}
704704
}
@@ -734,7 +734,7 @@ fn alloc_guard(alloc_size: usize) -> Result<(), CollectionAllocErr> {
734734
#[cfg(test)]
735735
mod tests {
736736
use super::*;
737-
use alloc::Void;
737+
use alloc::Opaque;
738738

739739
#[test]
740740
fn allocator_param() {
@@ -754,7 +754,7 @@ mod tests {
754754
// before allocation attempts start failing.
755755
struct BoundedAlloc { fuel: usize }
756756
unsafe impl Alloc for BoundedAlloc {
757-
unsafe fn alloc(&mut self, layout: Layout) -> Result<NonNull<Void>, AllocErr> {
757+
unsafe fn alloc(&mut self, layout: Layout) -> Result<NonNull<Opaque>, AllocErr> {
758758
let size = layout.size();
759759
if size > self.fuel {
760760
return Err(AllocErr);
@@ -764,7 +764,7 @@ mod tests {
764764
err @ Err(_) => err,
765765
}
766766
}
767-
unsafe fn dealloc(&mut self, ptr: NonNull<Void>, layout: Layout) {
767+
unsafe fn dealloc(&mut self, ptr: NonNull<Opaque>, layout: Layout) {
768768
Global.dealloc(ptr, layout)
769769
}
770770
}

src/liballoc/rc.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ use core::ops::CoerceUnsized;
259259
use core::ptr::{self, NonNull};
260260
use core::convert::From;
261261

262-
use alloc::{Global, Alloc, Layout, Void, box_free};
262+
use alloc::{Global, Alloc, Layout, Opaque, box_free};
263263
use string::String;
264264
use vec::Vec;
265265

@@ -737,7 +737,7 @@ impl<T: Clone> RcFromSlice<T> for Rc<[T]> {
737737
// In the event of a panic, elements that have been written
738738
// into the new RcBox will be dropped, then the memory freed.
739739
struct Guard<T> {
740-
mem: NonNull<Void>,
740+
mem: NonNull<Opaque>,
741741
elems: *mut T,
742742
layout: Layout,
743743
n_elems: usize,
@@ -760,7 +760,7 @@ impl<T: Clone> RcFromSlice<T> for Rc<[T]> {
760760
let v_ptr = v as *const [T];
761761
let ptr = Self::allocate_for_ptr(v_ptr);
762762

763-
let mem = ptr as *mut _ as *mut Void;
763+
let mem = ptr as *mut _ as *mut Opaque;
764764
let layout = Layout::for_value(&*ptr);
765765

766766
// Pointer to first element
@@ -844,7 +844,7 @@ unsafe impl<#[may_dangle] T: ?Sized> Drop for Rc<T> {
844844
self.dec_weak();
845845

846846
if self.weak() == 0 {
847-
Global.dealloc(self.ptr.as_void(), Layout::for_value(self.ptr.as_ref()));
847+
Global.dealloc(self.ptr.as_opaque(), Layout::for_value(self.ptr.as_ref()));
848848
}
849849
}
850850
}
@@ -1268,7 +1268,7 @@ impl<T: ?Sized> Drop for Weak<T> {
12681268
// the weak count starts at 1, and will only go to zero if all
12691269
// the strong pointers have disappeared.
12701270
if self.weak() == 0 {
1271-
Global.dealloc(self.ptr.as_void(), Layout::for_value(self.ptr.as_ref()));
1271+
Global.dealloc(self.ptr.as_opaque(), Layout::for_value(self.ptr.as_ref()));
12721272
}
12731273
}
12741274
}

0 commit comments

Comments
 (0)