about summary refs log tree commit diff
path: root/src/libcore
diff options
context:
space:
mode:
authorTim <t.diekmann.3dv@gmail.com>2019-02-28 07:32:13 +0100
committerTim <t.diekmann.3dv@gmail.com>2019-02-28 07:32:13 +0100
commit797d8ea4789c64bb20869fa7fb0c15e2c09432cf (patch)
treeff34a53df2421ef0eb7d617dba224eed0e09f28f /src/libcore
parent7e001e5c6c7c090b41416a57d4be412ed3ccd937 (diff)
downloadrust-797d8ea4789c64bb20869fa7fb0c15e2c09432cf.tar.gz
rust-797d8ea4789c64bb20869fa7fb0c15e2c09432cf.zip
Make `Unique::as_ptr`, `NonNull::dangling` and `NonNull::cast` const
Make `Unique::as_ptr` const without feature attribute as it's unstable
Make `NonNull::dangling` and `NonNull::cast` const with `feature = "const_ptr_nonnull"`
Diffstat (limited to 'src/libcore')
-rw-r--r--src/libcore/ptr.rs8
1 files changed, 5 insertions, 3 deletions
diff --git a/src/libcore/ptr.rs b/src/libcore/ptr.rs
index 866c8d0896b..3e1773ff9d2 100644
--- a/src/libcore/ptr.rs
+++ b/src/libcore/ptr.rs
@@ -2790,7 +2790,7 @@ impl<T: ?Sized> Unique<T> {
     }
 
     /// Acquires the underlying `*mut` pointer.
-    pub fn as_ptr(self) -> *mut T {
+    pub const fn as_ptr(self) -> *mut T {
         self.pointer as *mut T
     }
 
@@ -2903,7 +2903,8 @@ impl<T: Sized> NonNull<T> {
     /// some other means.
     #[stable(feature = "nonnull", since = "1.25.0")]
     #[inline]
-    pub fn dangling() -> Self {
+    #[cfg_attr(not(stage0), rustc_const_unstable(feature = "const_ptr_nonnull"))]
+    pub const fn dangling() -> Self {
         unsafe {
             let ptr = mem::align_of::<T>() as *mut T;
             NonNull::new_unchecked(ptr)
@@ -2966,7 +2967,8 @@ impl<T: ?Sized> NonNull<T> {
     /// Cast to a pointer of another type
     #[stable(feature = "nonnull_cast", since = "1.27.0")]
     #[inline]
-    pub fn cast<U>(self) -> NonNull<U> {
+    #[cfg_attr(not(stage0), rustc_const_unstable(feature = "const_ptr_nonnull"))]
+    pub const fn cast<U>(self) -> NonNull<U> {
         unsafe {
             NonNull::new_unchecked(self.as_ptr() as *mut U)
         }