File tree Expand file tree Collapse file tree 4 files changed +9
-9
lines changed Expand file tree Collapse file tree 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
99allocation. We don't even need to handle it specially in almost any code because
1010we usually need to check if ` cap > len ` or ` len > 0 ` anyway. The recommended
1111Rust 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
1414` null ` would make the compiler do bad things.
1515
1616So:
@@ -23,7 +23,7 @@ use std::mem;
2323impl<T> Vec<T> {
2424 fn new() -> Self {
2525 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 }
2727 }
2828}
2929```
Original file line number Diff line number Diff line change @@ -29,8 +29,8 @@ impl<T> RawVec<T> {
2929 // !0 is usize::MAX. This branch should be stripped at compile time.
3030 let cap = if mem :: size_of :: <T >() == 0 { ! 0 } else { 0 };
3131
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 }
3434 }
3535
3636 fn grow (& mut self ) {
Original file line number Diff line number Diff line change @@ -18,7 +18,7 @@ struct RawVec<T> {
1818impl<T> RawVec<T> {
1919 fn new() -> Self {
2020 assert!(mem::size_of::<T>() != 0, "TODO: implement ZST support");
21- RawVec { ptr: Unique::empty (), cap: 0 }
21+ RawVec { ptr: Unique::dangling (), cap: 0 }
2222 }
2323
2424 // unchanged from Vec
Original file line number Diff line number Diff line change @@ -19,7 +19,7 @@ RawValIter and RawVec respectively. How mysteriously convenient.
1919## Allocating Zero-Sized Types
2020
2121So 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
2323with a ZST is a no-op since ZSTs have exactly one value, and therefore no state needs
2424to be considered to store or load them. This actually extends to ` ptr::read ` and
2525` 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> {
3838 // !0 is usize::MAX. This branch should be stripped at compile time.
3939 let cap = if mem::size_of::<T>() == 0 { !0 } else { 0 };
4040
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 }
4343 }
4444
4545 fn grow(&mut self) {
You can’t perform that action at this time.
0 commit comments