Skip to content
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

Rename Unique::empty() -> Unique::dangling() #71597

Merged
merged 1 commit into from
Apr 30, 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
10 changes: 5 additions & 5 deletions src/liballoc/raw_vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ mod tests;
/// involved. This type is excellent for building your own data structures like Vec and VecDeque.
/// In particular:
///
/// * Produces `Unique::empty()` on zero-sized types.
/// * Produces `Unique::empty()` on zero-length allocations.
/// * Avoids freeing `Unique::empty()`.
/// * Produces `Unique::dangling()` on zero-sized types.
/// * Produces `Unique::dangling()` on zero-length allocations.
/// * Avoids freeing `Unique::dangling()`.
/// * Catches all overflows in capacity computations (promotes them to "capacity overflow" panics).
/// * Guards against 32-bit systems allocating more than isize::MAX bytes.
/// * Guards against overflowing your length.
Expand Down Expand Up @@ -125,7 +125,7 @@ impl<T, A: AllocRef> RawVec<T, A> {
/// the returned `RawVec`.
pub const fn new_in(alloc: A) -> Self {
// `cap: 0` means "unallocated". zero-sized types are ignored.
Self { ptr: Unique::empty(), cap: 0, alloc }
Self { ptr: Unique::dangling(), cap: 0, alloc }
}

/// Like `with_capacity`, but parameterized over the choice of
Expand Down Expand Up @@ -172,7 +172,7 @@ impl<T, A: AllocRef> RawVec<T, A> {
}

/// Gets a raw pointer to the start of the allocation. Note that this is
/// `Unique::empty()` if `capacity == 0` or `T` is zero-sized. In the former case, you must
/// `Unique::dangling()` if `capacity == 0` or `T` is zero-sized. In the former case, you must
/// be careful.
pub fn ptr(&self) -> *mut T {
self.ptr.as_ptr()
Expand Down
3 changes: 1 addition & 2 deletions src/libcore/ptr/unique.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,8 @@ impl<T: Sized> Unique<T> {
/// a `T`, which means this must not be used as a "not yet initialized"
/// sentinel value. Types that lazily allocate must track initialization by
/// some other means.
// FIXME: rename to dangling() to match NonNull?
#[inline]
pub const fn empty() -> Self {
pub const fn dangling() -> Self {
// SAFETY: mem::align_of() returns a valid, non-null pointer. The
// conditions to call new_unchecked() are thus respected.
unsafe { Unique::new_unchecked(mem::align_of::<T>() as *mut T) }
Expand Down
4 changes: 2 additions & 2 deletions src/test/ui/consts/const-ptr-unique-rpass.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ use test::black_box as b; // prevent promotion of the argument and const-propaga
use std::ptr::Unique;


const PTR: *mut u32 = Unique::empty().as_ptr();
const PTR: *mut u32 = Unique::dangling().as_ptr();

pub fn main() {
// Be super-extra paranoid and cast the fn items to fn pointers before blackboxing them.
assert_eq!(PTR, b::<fn() -> _>(Unique::<u32>::empty)().as_ptr());
assert_eq!(PTR, b::<fn() -> _>(Unique::<u32>::dangling)().as_ptr());
}