Skip to content

Commit 97a8870

Browse files
authored
Rollup merge of #71597 - CohenArthur:refactor-unique-empty, r=shepmaster
Rename Unique::empty() -> Unique::dangling() A `FIXME` comment in `src/libcore/ptr/unique.rs` suggested refactoring `Unique::empty()` to `Unique::dangling()` which this PR does.
2 parents 2770f82 + eda7f8f commit 97a8870

File tree

3 files changed

+8
-9
lines changed

3 files changed

+8
-9
lines changed

src/liballoc/raw_vec.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ mod tests;
2525
/// involved. This type is excellent for building your own data structures like Vec and VecDeque.
2626
/// In particular:
2727
///
28-
/// * Produces `Unique::empty()` on zero-sized types.
29-
/// * Produces `Unique::empty()` on zero-length allocations.
30-
/// * Avoids freeing `Unique::empty()`.
28+
/// * Produces `Unique::dangling()` on zero-sized types.
29+
/// * Produces `Unique::dangling()` on zero-length allocations.
30+
/// * Avoids freeing `Unique::dangling()`.
3131
/// * Catches all overflows in capacity computations (promotes them to "capacity overflow" panics).
3232
/// * Guards against 32-bit systems allocating more than isize::MAX bytes.
3333
/// * Guards against overflowing your length.
@@ -125,7 +125,7 @@ impl<T, A: AllocRef> RawVec<T, A> {
125125
/// the returned `RawVec`.
126126
pub const fn new_in(alloc: A) -> Self {
127127
// `cap: 0` means "unallocated". zero-sized types are ignored.
128-
Self { ptr: Unique::empty(), cap: 0, alloc }
128+
Self { ptr: Unique::dangling(), cap: 0, alloc }
129129
}
130130

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

174174
/// Gets a raw pointer to the start of the allocation. Note that this is
175-
/// `Unique::empty()` if `capacity == 0` or `T` is zero-sized. In the former case, you must
175+
/// `Unique::dangling()` if `capacity == 0` or `T` is zero-sized. In the former case, you must
176176
/// be careful.
177177
pub fn ptr(&self) -> *mut T {
178178
self.ptr.as_ptr()

src/libcore/ptr/unique.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,8 @@ impl<T: Sized> Unique<T> {
7070
/// a `T`, which means this must not be used as a "not yet initialized"
7171
/// sentinel value. Types that lazily allocate must track initialization by
7272
/// some other means.
73-
// FIXME: rename to dangling() to match NonNull?
7473
#[inline]
75-
pub const fn empty() -> Self {
74+
pub const fn dangling() -> Self {
7675
// SAFETY: mem::align_of() returns a valid, non-null pointer. The
7776
// conditions to call new_unchecked() are thus respected.
7877
unsafe { Unique::new_unchecked(mem::align_of::<T>() as *mut T) }

src/test/ui/consts/const-ptr-unique-rpass.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ use test::black_box as b; // prevent promotion of the argument and const-propaga
88
use std::ptr::Unique;
99

1010

11-
const PTR: *mut u32 = Unique::empty().as_ptr();
11+
const PTR: *mut u32 = Unique::dangling().as_ptr();
1212

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

0 commit comments

Comments
 (0)