@@ -22,13 +22,13 @@ use core::cmp;
22
22
/// involved. This type is excellent for building your own data structures like Vec and VecDeque.
23
23
/// In particular:
24
24
///
25
- /// * Produces heap::EMPTY on zero-sized types
26
- /// * Produces heap::EMPTY on zero-length allocations
25
+ /// * Produces Unique::empty() on zero-sized types
26
+ /// * Produces Unique::empty() on zero-length allocations
27
27
/// * Catches all overflows in capacity computations (promotes them to "capacity overflow" panics)
28
28
/// * Guards against 32-bit systems allocating more than isize::MAX bytes
29
29
/// * Guards against overflowing your length
30
30
/// * Aborts on OOM
31
- /// * Avoids freeing heap::EMPTY
31
+ /// * Avoids freeing Unique::empty()
32
32
/// * Contains a ptr::Unique and thus endows the user with all related benefits
33
33
///
34
34
/// This type does not in anyway inspect the memory that it manages. When dropped it *will*
@@ -55,15 +55,13 @@ impl<T> RawVec<T> {
55
55
/// it makes a RawVec with capacity `usize::MAX`. Useful for implementing
56
56
/// delayed allocation.
57
57
pub fn new ( ) -> Self {
58
- unsafe {
59
- // !0 is usize::MAX. This branch should be stripped at compile time.
60
- let cap = if mem:: size_of :: < T > ( ) == 0 { !0 } else { 0 } ;
58
+ // !0 is usize::MAX. This branch should be stripped at compile time.
59
+ let cap = if mem:: size_of :: < T > ( ) == 0 { !0 } else { 0 } ;
61
60
62
- // heap::EMPTY doubles as "unallocated" and "zero-sized allocation"
63
- RawVec {
64
- ptr : Unique :: new ( heap:: EMPTY as * mut T ) ,
65
- cap : cap,
66
- }
61
+ // Unique::empty() doubles as "unallocated" and "zero-sized allocation"
62
+ RawVec {
63
+ ptr : Unique :: empty ( ) ,
64
+ cap : cap,
67
65
}
68
66
}
69
67
@@ -101,7 +99,7 @@ impl<T> RawVec<T> {
101
99
102
100
// handles ZSTs and `cap = 0` alike
103
101
let ptr = if alloc_size == 0 {
104
- heap :: EMPTY as * mut u8
102
+ mem :: align_of :: < T > ( ) as * mut u8
105
103
} else {
106
104
let align = mem:: align_of :: < T > ( ) ;
107
105
let ptr = if zeroed {
@@ -148,10 +146,10 @@ impl<T> RawVec<T> {
148
146
149
147
impl < T > RawVec < T > {
150
148
/// Gets a raw pointer to the start of the allocation. Note that this is
151
- /// heap::EMPTY if `cap = 0` or T is zero-sized. In the former case, you must
149
+ /// Unique::empty() if `cap = 0` or T is zero-sized. In the former case, you must
152
150
/// be careful.
153
151
pub fn ptr ( & self ) -> * mut T {
154
- self . ptr . ptr ( )
152
+ self . ptr . as_ptr ( )
155
153
}
156
154
157
155
/// Gets the capacity of the allocation.
0 commit comments