File tree 4 files changed +9
-9
lines changed
4 files changed +9
-9
lines changed Original file line number Diff line number Diff line change @@ -9,8 +9,8 @@ This is perfectly fine because we already have `cap == 0` as our sentinel for no
9
9
allocation. We don't even need to handle it specially in almost any code because
10
10
we usually need to check if ` cap > len ` or ` len > 0 ` anyway. The recommended
11
11
Rust value to put here is ` mem::align_of::<T>() ` . Unique provides a convenience
12
- for this: ` Unique::empty () ` . There are quite a few places where we'll
13
- want to use ` empty ` because there's no real allocation to talk about but
12
+ for this: ` Unique::dangling () ` . There are quite a few places where we'll
13
+ want to use ` dangling ` because there's no real allocation to talk about but
14
14
` null ` would make the compiler do bad things.
15
15
16
16
So:
@@ -23,7 +23,7 @@ use std::mem;
23
23
impl<T> Vec<T> {
24
24
fn new() -> Self {
25
25
assert!(mem::size_of::<T>() != 0, "We're not ready to handle ZSTs");
26
- Vec { ptr: Unique::empty (), len: 0, cap: 0 }
26
+ Vec { ptr: Unique::dangling (), len: 0, cap: 0 }
27
27
}
28
28
}
29
29
```
Original file line number Diff line number Diff line change @@ -29,8 +29,8 @@ impl<T> RawVec<T> {
29
29
// !0 is usize::MAX. This branch should be stripped at compile time.
30
30
let cap = if mem :: size_of :: <T >() == 0 { ! 0 } else { 0 };
31
31
32
- // Unique::empty () doubles as "unallocated" and "zero-sized allocation"
33
- RawVec { ptr : Unique :: empty (), cap : cap }
32
+ // Unique::dangling () doubles as "unallocated" and "zero-sized allocation"
33
+ RawVec { ptr : Unique :: dangling (), cap : cap }
34
34
}
35
35
36
36
fn grow (& mut self ) {
Original file line number Diff line number Diff line change @@ -18,7 +18,7 @@ struct RawVec<T> {
18
18
impl<T> RawVec<T> {
19
19
fn new() -> Self {
20
20
assert!(mem::size_of::<T>() != 0, "TODO: implement ZST support");
21
- RawVec { ptr: Unique::empty (), cap: 0 }
21
+ RawVec { ptr: Unique::dangling (), cap: 0 }
22
22
}
23
23
24
24
// unchanged from Vec
Original file line number Diff line number Diff line change @@ -19,7 +19,7 @@ RawValIter and RawVec respectively. How mysteriously convenient.
19
19
## Allocating Zero-Sized Types
20
20
21
21
So if the allocator API doesn't support zero-sized allocations, what on earth
22
- do we store as our allocation? ` Unique::empty () ` of course! Almost every operation
22
+ do we store as our allocation? ` Unique::dangling () ` of course! Almost every operation
23
23
with a ZST is a no-op since ZSTs have exactly one value, and therefore no state needs
24
24
to be considered to store or load them. This actually extends to ` ptr::read ` and
25
25
` ptr::write ` : they won't actually look at the pointer at all. As such we never need
@@ -38,8 +38,8 @@ impl<T> RawVec<T> {
38
38
// !0 is usize::MAX. This branch should be stripped at compile time.
39
39
let cap = if mem::size_of::<T>() == 0 { !0 } else { 0 };
40
40
41
- // Unique::empty () doubles as "unallocated" and "zero-sized allocation"
42
- RawVec { ptr: Unique::empty (), cap: cap }
41
+ // Unique::dangling () doubles as "unallocated" and "zero-sized allocation"
42
+ RawVec { ptr: Unique::dangling (), cap: cap }
43
43
}
44
44
45
45
fn grow(&mut self) {
You can’t perform that action at this time.
0 commit comments