Skip to content

Commit cce258b

Browse files
committed
Make NonNull::as_ref (and friends) return refs with unbound lifetimes
1 parent d7769b9 commit cce258b

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

library/core/src/ptr/non_null.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ impl<T: Sized> NonNull<T> {
103103
/// [the module documentation]: crate::ptr#safety
104104
#[inline]
105105
#[unstable(feature = "ptr_as_uninit", issue = "75402")]
106-
pub unsafe fn as_uninit_ref(&self) -> &MaybeUninit<T> {
106+
pub unsafe fn as_uninit_ref<'a>(&self) -> &'a MaybeUninit<T> {
107107
// SAFETY: the caller must guarantee that `self` meets all the
108108
// requirements for a reference.
109109
unsafe { &*self.cast().as_ptr() }
@@ -135,7 +135,7 @@ impl<T: Sized> NonNull<T> {
135135
/// [the module documentation]: crate::ptr#safety
136136
#[inline]
137137
#[unstable(feature = "ptr_as_uninit", issue = "75402")]
138-
pub unsafe fn as_uninit_mut(&mut self) -> &mut MaybeUninit<T> {
138+
pub unsafe fn as_uninit_mut<'a>(&mut self) -> &'a mut MaybeUninit<T> {
139139
// SAFETY: the caller must guarantee that `self` meets all the
140140
// requirements for a reference.
141141
unsafe { &mut *self.cast().as_ptr() }
@@ -206,7 +206,7 @@ impl<T: ?Sized> NonNull<T> {
206206
/// [the module documentation]: crate::ptr#safety
207207
#[stable(feature = "nonnull", since = "1.25.0")]
208208
#[inline]
209-
pub unsafe fn as_ref(&self) -> &T {
209+
pub unsafe fn as_ref<'a>(&self) -> &'a T {
210210
// SAFETY: the caller must guarantee that `self` meets all the
211211
// requirements for a reference.
212212
unsafe { &*self.as_ptr() }
@@ -242,7 +242,7 @@ impl<T: ?Sized> NonNull<T> {
242242
/// [the module documentation]: crate::ptr#safety
243243
#[stable(feature = "nonnull", since = "1.25.0")]
244244
#[inline]
245-
pub unsafe fn as_mut(&mut self) -> &mut T {
245+
pub unsafe fn as_mut<'a>(&mut self) -> &'a mut T {
246246
// SAFETY: the caller must guarantee that `self` meets all the
247247
// requirements for a mutable reference.
248248
unsafe { &mut *self.as_ptr() }
@@ -390,7 +390,7 @@ impl<T> NonNull<[T]> {
390390
/// [`pointer::offset`]: ../../std/primitive.pointer.html#method.offset
391391
#[inline]
392392
#[unstable(feature = "ptr_as_uninit", issue = "75402")]
393-
pub unsafe fn as_uninit_slice(&self) -> &[MaybeUninit<T>] {
393+
pub unsafe fn as_uninit_slice<'a>(&self) -> &'a [MaybeUninit<T>] {
394394
// SAFETY: the caller must uphold the safety contract for `as_uninit_slice`.
395395
unsafe { slice::from_raw_parts(self.cast().as_ptr(), self.len()) }
396396
}
@@ -452,7 +452,7 @@ impl<T> NonNull<[T]> {
452452
/// ```
453453
#[inline]
454454
#[unstable(feature = "ptr_as_uninit", issue = "75402")]
455-
pub unsafe fn as_uninit_slice_mut(&self) -> &mut [MaybeUninit<T>] {
455+
pub unsafe fn as_uninit_slice_mut<'a>(&self) -> &'a mut [MaybeUninit<T>] {
456456
// SAFETY: the caller must uphold the safety contract for `as_uninit_slice_mut`.
457457
unsafe { slice::from_raw_parts_mut(self.cast().as_ptr(), self.len()) }
458458
}

0 commit comments

Comments
 (0)