Skip to content

Rename Unique::empty to Unique::dangling #217

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/vec-alloc.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ This is perfectly fine because we already have `cap == 0` as our sentinel for no
allocation. We don't even need to handle it specially in almost any code because
we usually need to check if `cap > len` or `len > 0` anyway. The recommended
Rust value to put here is `mem::align_of::<T>()`. Unique provides a convenience
for this: `Unique::empty()`. There are quite a few places where we'll
want to use `empty` because there's no real allocation to talk about but
for this: `Unique::dangling()`. There are quite a few places where we'll
want to use `dangling` because there's no real allocation to talk about but
`null` would make the compiler do bad things.

So:
Expand All @@ -23,7 +23,7 @@ use std::mem;
impl<T> Vec<T> {
fn new() -> Self {
assert!(mem::size_of::<T>() != 0, "We're not ready to handle ZSTs");
Vec { ptr: Unique::empty(), len: 0, cap: 0 }
Vec { ptr: Unique::dangling(), len: 0, cap: 0 }
}
}
```
Expand Down
4 changes: 2 additions & 2 deletions src/vec-final.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ impl<T> RawVec<T> {
// !0 is usize::MAX. This branch should be stripped at compile time.
let cap = if mem::size_of::<T>() == 0 { !0 } else { 0 };

// Unique::empty() doubles as "unallocated" and "zero-sized allocation"
RawVec { ptr: Unique::empty(), cap: cap }
// Unique::dangling() doubles as "unallocated" and "zero-sized allocation"
RawVec { ptr: Unique::dangling(), cap: cap }
}

fn grow(&mut self) {
Expand Down
2 changes: 1 addition & 1 deletion src/vec-raw.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ struct RawVec<T> {
impl<T> RawVec<T> {
fn new() -> Self {
assert!(mem::size_of::<T>() != 0, "TODO: implement ZST support");
RawVec { ptr: Unique::empty(), cap: 0 }
RawVec { ptr: Unique::dangling(), cap: 0 }
}

// unchanged from Vec
Expand Down
6 changes: 3 additions & 3 deletions src/vec-zsts.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ RawValIter and RawVec respectively. How mysteriously convenient.
## Allocating Zero-Sized Types

So if the allocator API doesn't support zero-sized allocations, what on earth
do we store as our allocation? `Unique::empty()` of course! Almost every operation
do we store as our allocation? `Unique::dangling()` of course! Almost every operation
with a ZST is a no-op since ZSTs have exactly one value, and therefore no state needs
to be considered to store or load them. This actually extends to `ptr::read` and
`ptr::write`: they won't actually look at the pointer at all. As such we never need
Expand All @@ -38,8 +38,8 @@ impl<T> RawVec<T> {
// !0 is usize::MAX. This branch should be stripped at compile time.
let cap = if mem::size_of::<T>() == 0 { !0 } else { 0 };

// Unique::empty() doubles as "unallocated" and "zero-sized allocation"
RawVec { ptr: Unique::empty(), cap: cap }
// Unique::dangling() doubles as "unallocated" and "zero-sized allocation"
RawVec { ptr: Unique::dangling(), cap: cap }
}

fn grow(&mut self) {
Expand Down