about summary refs log tree commit diff
path: root/library/core/src
diff options
context:
space:
mode:
authorChris Denton <chris@chrisdenton.dev>2025-04-06 07:06:10 +0000
committerChris Denton <chris@chrisdenton.dev>2025-04-11 10:49:33 +0000
commit830bd8b6f4feb8665c8865beb20ffb424e8d8ee6 (patch)
tree019b47524c9388fb26a0f71d060a302242fa2d76 /library/core/src
parent18a029cfe8e761533634bda8fe8a14e30280a21b (diff)
downloadrust-830bd8b6f4feb8665c8865beb20ffb424e8d8ee6.tar.gz
rust-830bd8b6f4feb8665c8865beb20ffb424e8d8ee6.zip
Implement Default for raw pointers
Diffstat (limited to 'library/core/src')
-rw-r--r--library/core/src/ptr/const_ptr.rs8
-rw-r--r--library/core/src/ptr/mut_ptr.rs8
2 files changed, 16 insertions, 0 deletions
diff --git a/library/core/src/ptr/const_ptr.rs b/library/core/src/ptr/const_ptr.rs
index 0854e31c199..2d869958b85 100644
--- a/library/core/src/ptr/const_ptr.rs
+++ b/library/core/src/ptr/const_ptr.rs
@@ -1739,3 +1739,11 @@ impl<T: ?Sized> PartialOrd for *const T {
         *self >= *other
     }
 }
+
+#[stable(feature = "raw_ptr_default", since = "CURRENT_RUSTC_VERSION")]
+impl<T: ?Sized + Thin> Default for *const T {
+    /// Returns the default value of [`null()`][crate::ptr::null].
+    fn default() -> Self {
+        crate::ptr::null()
+    }
+}
diff --git a/library/core/src/ptr/mut_ptr.rs b/library/core/src/ptr/mut_ptr.rs
index e29774963db..df49eedb350 100644
--- a/library/core/src/ptr/mut_ptr.rs
+++ b/library/core/src/ptr/mut_ptr.rs
@@ -2156,3 +2156,11 @@ impl<T: ?Sized> PartialOrd for *mut T {
         *self >= *other
     }
 }
+
+#[stable(feature = "raw_ptr_default", since = "CURRENT_RUSTC_VERSION")]
+impl<T: ?Sized + Thin> Default for *mut T {
+    /// Returns the default value of [`null_mut()`][crate::ptr::null_mut].
+    fn default() -> Self {
+        crate::ptr::null_mut()
+    }
+}