Skip to content

Commit 3e07965

Browse files
author
Lukas Markeffsky
committed
const stabilize NonNull::as_ref
1 parent cda5bec commit 3e07965

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

library/core/src/ptr/non_null.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -367,13 +367,14 @@ impl<T: ?Sized> NonNull<T> {
367367
///
368368
/// [the module documentation]: crate::ptr#safety
369369
#[stable(feature = "nonnull", since = "1.25.0")]
370-
#[rustc_const_unstable(feature = "const_ptr_as_ref", issue = "91822")]
370+
#[rustc_const_stable(feature = "const_nonnull_as_ref", since = "CURRENT_RUSTC_VERSION")]
371371
#[must_use]
372372
#[inline(always)]
373373
pub const unsafe fn as_ref<'a>(&self) -> &'a T {
374374
// SAFETY: the caller must guarantee that `self` meets all the
375375
// requirements for a reference.
376-
unsafe { &*self.as_ptr() }
376+
// `cast_const` avoids a mutable raw pointer deref.
377+
unsafe { &*self.as_ptr().cast_const() }
377378
}
378379

379380
/// Returns a unique reference to the value. If the value may be uninitialized, [`as_uninit_mut`]

0 commit comments

Comments
 (0)