Skip to content

Commit 87464fe

Browse files
committed
Change as_uninit_* methods on NonNull from taking self by
reference to taking `self` by value. This is consistent with the methods of the same names on primitive pointers. The returned lifetime was already previously unbounded.
1 parent 4c24901 commit 87464fe

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

core/src/ptr/non_null.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ impl<T: Sized> NonNull<T> {
124124
#[must_use]
125125
#[unstable(feature = "ptr_as_uninit", issue = "75402")]
126126
#[rustc_const_unstable(feature = "const_ptr_as_ref", issue = "91822")]
127-
pub const unsafe fn as_uninit_ref<'a>(&self) -> &'a MaybeUninit<T> {
127+
pub const unsafe fn as_uninit_ref<'a>(self) -> &'a MaybeUninit<T> {
128128
// SAFETY: the caller must guarantee that `self` meets all the
129129
// requirements for a reference.
130130
unsafe { &*self.cast().as_ptr() }
@@ -158,7 +158,7 @@ impl<T: Sized> NonNull<T> {
158158
#[must_use]
159159
#[unstable(feature = "ptr_as_uninit", issue = "75402")]
160160
#[rustc_const_unstable(feature = "const_ptr_as_ref", issue = "91822")]
161-
pub const unsafe fn as_uninit_mut<'a>(&mut self) -> &'a mut MaybeUninit<T> {
161+
pub const unsafe fn as_uninit_mut<'a>(self) -> &'a mut MaybeUninit<T> {
162162
// SAFETY: the caller must guarantee that `self` meets all the
163163
// requirements for a reference.
164164
unsafe { &mut *self.cast().as_ptr() }
@@ -592,7 +592,7 @@ impl<T> NonNull<[T]> {
592592
#[must_use]
593593
#[unstable(feature = "ptr_as_uninit", issue = "75402")]
594594
#[rustc_const_unstable(feature = "const_ptr_as_ref", issue = "91822")]
595-
pub const unsafe fn as_uninit_slice<'a>(&self) -> &'a [MaybeUninit<T>] {
595+
pub const unsafe fn as_uninit_slice<'a>(self) -> &'a [MaybeUninit<T>] {
596596
// SAFETY: the caller must uphold the safety contract for `as_uninit_slice`.
597597
unsafe { slice::from_raw_parts(self.cast().as_ptr(), self.len()) }
598598
}
@@ -655,7 +655,7 @@ impl<T> NonNull<[T]> {
655655
#[must_use]
656656
#[unstable(feature = "ptr_as_uninit", issue = "75402")]
657657
#[rustc_const_unstable(feature = "const_ptr_as_ref", issue = "91822")]
658-
pub const unsafe fn as_uninit_slice_mut<'a>(&self) -> &'a mut [MaybeUninit<T>] {
658+
pub const unsafe fn as_uninit_slice_mut<'a>(self) -> &'a mut [MaybeUninit<T>] {
659659
// SAFETY: the caller must uphold the safety contract for `as_uninit_slice_mut`.
660660
unsafe { slice::from_raw_parts_mut(self.cast().as_ptr(), self.len()) }
661661
}

0 commit comments

Comments
 (0)