Skip to content

Commit d1517d4

Browse files
ehussGankra
authored andcommitted
Rename Unique::empty to Unique::dangling
1 parent 91dd12b commit d1517d4

File tree

4 files changed

+9
-9
lines changed

4 files changed

+9
-9
lines changed

src/vec-alloc.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ This is perfectly fine because we already have `cap == 0` as our sentinel for no
99
allocation. We don't even need to handle it specially in almost any code because
1010
we usually need to check if `cap > len` or `len > 0` anyway. The recommended
1111
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
1414
`null` would make the compiler do bad things.
1515

1616
So:
@@ -23,7 +23,7 @@ use std::mem;
2323
impl<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
```

src/vec-final.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff 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) {

src/vec-raw.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ struct RawVec<T> {
1818
impl<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

src/vec-zsts.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ RawValIter and RawVec respectively. How mysteriously convenient.
1919
## Allocating Zero-Sized Types
2020

2121
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
2323
with a ZST is a no-op since ZSTs have exactly one value, and therefore no state needs
2424
to 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) {

0 commit comments

Comments
 (0)