Skip to content

Commit

Permalink
Change as_uninit_* methods on NonNull from taking self by
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Raekye committed Apr 16, 2022
1 parent 3f391b8 commit d5f96e6
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions library/core/src/ptr/non_null.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ impl<T: Sized> NonNull<T> {
#[must_use]
#[unstable(feature = "ptr_as_uninit", issue = "75402")]
#[rustc_const_unstable(feature = "const_ptr_as_ref", issue = "91822")]
pub const unsafe fn as_uninit_ref<'a>(&self) -> &'a MaybeUninit<T> {
pub const unsafe fn as_uninit_ref<'a>(self) -> &'a MaybeUninit<T> {
// SAFETY: the caller must guarantee that `self` meets all the
// requirements for a reference.
unsafe { &*self.cast().as_ptr() }
Expand Down Expand Up @@ -158,7 +158,7 @@ impl<T: Sized> NonNull<T> {
#[must_use]
#[unstable(feature = "ptr_as_uninit", issue = "75402")]
#[rustc_const_unstable(feature = "const_ptr_as_ref", issue = "91822")]
pub const unsafe fn as_uninit_mut<'a>(&mut self) -> &'a mut MaybeUninit<T> {
pub const unsafe fn as_uninit_mut<'a>(self) -> &'a mut MaybeUninit<T> {
// SAFETY: the caller must guarantee that `self` meets all the
// requirements for a reference.
unsafe { &mut *self.cast().as_ptr() }
Expand Down Expand Up @@ -592,7 +592,7 @@ impl<T> NonNull<[T]> {
#[must_use]
#[unstable(feature = "ptr_as_uninit", issue = "75402")]
#[rustc_const_unstable(feature = "const_ptr_as_ref", issue = "91822")]
pub const unsafe fn as_uninit_slice<'a>(&self) -> &'a [MaybeUninit<T>] {
pub const unsafe fn as_uninit_slice<'a>(self) -> &'a [MaybeUninit<T>] {
// SAFETY: the caller must uphold the safety contract for `as_uninit_slice`.
unsafe { slice::from_raw_parts(self.cast().as_ptr(), self.len()) }
}
Expand Down Expand Up @@ -655,7 +655,7 @@ impl<T> NonNull<[T]> {
#[must_use]
#[unstable(feature = "ptr_as_uninit", issue = "75402")]
#[rustc_const_unstable(feature = "const_ptr_as_ref", issue = "91822")]
pub const unsafe fn as_uninit_slice_mut<'a>(&self) -> &'a mut [MaybeUninit<T>] {
pub const unsafe fn as_uninit_slice_mut<'a>(self) -> &'a mut [MaybeUninit<T>] {
// SAFETY: the caller must uphold the safety contract for `as_uninit_slice_mut`.
unsafe { slice::from_raw_parts_mut(self.cast().as_ptr(), self.len()) }
}
Expand Down

0 comments on commit d5f96e6

Please sign in to comment.