Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions library/core/src/ptr/const_ptr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}
8 changes: 8 additions & 0 deletions library/core/src/ptr/mut_ptr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}
17 changes: 17 additions & 0 deletions library/coretests/tests/ptr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1020,3 +1020,20 @@ fn test_ptr_swap_nonoverlapping_is_untyped() {
ptr_swap_nonoverlapping_is_untyped_inner();
const { ptr_swap_nonoverlapping_is_untyped_inner() };
}

#[test]
fn test_ptr_default() {
#[derive(Default)]
struct PtrDefaultTest {
ptr: *const u64,
}
let default = PtrDefaultTest::default();
assert!(default.ptr.is_null());

#[derive(Default)]
struct PtrMutDefaultTest {
ptr: *mut u64,
}
let default = PtrMutDefaultTest::default();
assert!(default.ptr.is_null());
}
Loading