about summary refs log tree commit diff
path: root/library/core/src
diff options
context:
space:
mode:
authorLukas Markeffsky <@>2022-09-23 17:52:31 +0200
committerLukas Markeffsky <@>2023-05-23 12:52:23 +0000
commit3e07965244623ea709b842381f475178cf49879a (patch)
tree254382bb8b4649b326e8cdd745e632f0e81bf539 /library/core/src
parentcda5becc27cbc7106646fbc40aacea5e7896d954 (diff)
downloadrust-3e07965244623ea709b842381f475178cf49879a.tar.gz
rust-3e07965244623ea709b842381f475178cf49879a.zip
const stabilize `NonNull::as_ref`
Diffstat (limited to 'library/core/src')
-rw-r--r--library/core/src/ptr/non_null.rs5
1 files changed, 3 insertions, 2 deletions
diff --git a/library/core/src/ptr/non_null.rs b/library/core/src/ptr/non_null.rs
index b492d2f07bc..ebed58ccf03 100644
--- a/library/core/src/ptr/non_null.rs
+++ b/library/core/src/ptr/non_null.rs
@@ -367,13 +367,14 @@ impl<T: ?Sized> NonNull<T> {
     ///
     /// [the module documentation]: crate::ptr#safety
     #[stable(feature = "nonnull", since = "1.25.0")]
-    #[rustc_const_unstable(feature = "const_ptr_as_ref", issue = "91822")]
+    #[rustc_const_stable(feature = "const_nonnull_as_ref", since = "CURRENT_RUSTC_VERSION")]
     #[must_use]
     #[inline(always)]
     pub const unsafe fn as_ref<'a>(&self) -> &'a T {
         // SAFETY: the caller must guarantee that `self` meets all the
         // requirements for a reference.
-        unsafe { &*self.as_ptr() }
+        // `cast_const` avoids a mutable raw pointer deref.
+        unsafe { &*self.as_ptr().cast_const() }
     }
 
     /// Returns a unique reference to the value. If the value may be uninitialized, [`as_uninit_mut`]