Skip to content

Commit f6ede52

Browse files
authored
Merge pull request #63 from SimonSapin/transparent
Cast to `*mut _` to avoid importing std::alloc::Opaque
2 parents 3c56329 + 4808cf3 commit f6ede52

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
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, unique)]
3030

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

@@ -38,7 +38,7 @@ impl<T> Drop for Box<T> {
3838
fn drop(&mut self) {
3939
unsafe {
4040
drop_in_place(self.ptr.as_ptr());
41-
Global.dealloc(self.ptr.as_ptr() as *mut Opaque, Layout::new::<T>())
41+
Global.dealloc(self.ptr.as_ptr() as *mut _, Layout::new::<T>())
4242
}
4343
}
4444
}
@@ -54,7 +54,7 @@ However this wouldn't work:
5454
```rust
5555
#![feature(allocator_api, ptr_internals, unique)]
5656

57-
use std::alloc::{Global, GlobalAlloc, Layout, Opaque};
57+
use std::alloc::{Global, GlobalAlloc, Layout};
5858
use std::ptr::{drop_in_place, Unique};
5959
use std::mem;
6060

@@ -64,7 +64,7 @@ impl<T> Drop for Box<T> {
6464
fn drop(&mut self) {
6565
unsafe {
6666
drop_in_place(self.ptr.as_ptr());
67-
Global.dealloc(self.ptr.as_ptr() as *mut Opaque, Layout::new::<T>());
67+
Global.dealloc(self.ptr.as_ptr() as *mut _, Layout::new::<T>());
6868
}
6969
}
7070
}
@@ -76,7 +76,7 @@ impl<T> Drop for SuperBox<T> {
7676
unsafe {
7777
// Hyper-optimized: deallocate the box's contents for it
7878
// without `drop`ing the contents
79-
Global.dealloc(self.my_box.ptr.as_ptr() as *mut Opaque, Layout::new::<T>());
79+
Global.dealloc(self.my_box.ptr.as_ptr() as *mut _, Layout::new::<T>());
8080
}
8181
}
8282
}
@@ -125,7 +125,7 @@ of Self during `drop` is to use an Option:
125125
```rust
126126
#![feature(allocator_api, ptr_internals, unique)]
127127

128-
use std::alloc::{GlobalAlloc, Global, Layout, Opaque};
128+
use std::alloc::{GlobalAlloc, Global, Layout};
129129
use std::ptr::{drop_in_place, Unique};
130130
use std::mem;
131131

@@ -135,7 +135,7 @@ impl<T> Drop for Box<T> {
135135
fn drop(&mut self) {
136136
unsafe {
137137
drop_in_place(self.ptr.as_ptr());
138-
Global.dealloc(self.ptr.as_ptr() as *mut Opaque, Layout::new::<T>());
138+
Global.dealloc(self.ptr.as_ptr() as *mut _, Layout::new::<T>());
139139
}
140140
}
141141
}
@@ -149,7 +149,7 @@ impl<T> Drop for SuperBox<T> {
149149
// without `drop`ing the contents. Need to set the `box`
150150
// field as `None` to prevent Rust from trying to Drop it.
151151
let my_box = self.my_box.take().unwrap();
152-
Global.dealloc(my_box.ptr.as_ptr() as *mut Opaque, Layout::new::<T>());
152+
Global.dealloc(my_box.ptr.as_ptr() as *mut _, Layout::new::<T>());
153153
mem::forget(my_box);
154154
}
155155
}

0 commit comments

Comments
 (0)