From eda7f8fdff16aee5ff30b150555c479f885ba993 Mon Sep 17 00:00:00 2001 From: cohenarthur Date: Thu, 30 Apr 2020 11:00:45 +0200 Subject: [PATCH] rename-unique: Rename Unique::empty() to Unique::dangling() rename-unique: Change calls and doc in raw_vec.rs rename-unique: Change empty() -> dangling() in const-ptr-unique-rpass.rs --- src/liballoc/raw_vec.rs | 10 +++++----- src/libcore/ptr/unique.rs | 3 +-- src/test/ui/consts/const-ptr-unique-rpass.rs | 4 ++-- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/liballoc/raw_vec.rs b/src/liballoc/raw_vec.rs index ca165b61e26..a8e19c9cbaa 100644 --- a/src/liballoc/raw_vec.rs +++ b/src/liballoc/raw_vec.rs @@ -25,9 +25,9 @@ /// 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. @@ -125,7 +125,7 @@ impl RawVec { /// 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 @@ -172,7 +172,7 @@ pub unsafe fn from_raw_parts_in(ptr: *mut T, capacity: usize, a: A) -> Self { } /// 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() diff --git a/src/libcore/ptr/unique.rs b/src/libcore/ptr/unique.rs index f5a5baceacc..f58d35f0613 100644 --- a/src/libcore/ptr/unique.rs +++ b/src/libcore/ptr/unique.rs @@ -70,9 +70,8 @@ impl Unique { /// 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::() as *mut T) } diff --git a/src/test/ui/consts/const-ptr-unique-rpass.rs b/src/test/ui/consts/const-ptr-unique-rpass.rs index e8735e1a32c..fc13bb98bd2 100644 --- a/src/test/ui/consts/const-ptr-unique-rpass.rs +++ b/src/test/ui/consts/const-ptr-unique-rpass.rs @@ -8,9 +8,9 @@ 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:: _>(Unique::::empty)().as_ptr()); + assert_eq!(PTR, b:: _>(Unique::::dangling)().as_ptr()); }