Skip to content

Commit

Permalink
document that the null pointer has the 0 address
Browse files Browse the repository at this point in the history
  • Loading branch information
RalfJung committed Oct 20, 2023
1 parent 274455a commit 98d54da
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions library/core/src/ptr/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -505,13 +505,18 @@ pub unsafe fn drop_in_place<T: ?Sized>(to_drop: *mut T) {

/// Creates a null raw pointer.
///
/// This function is equivalent to zero-initializing the pointer:
/// `MaybeUninit::<*const T>::zeroed().assume_init()`.
/// The resulting pointer has the address 0.
///
/// # Examples
///
/// ```
/// use std::ptr;
///
/// let p: *const i32 = ptr::null();
/// assert!(p.is_null());
/// assert_eq!(p as usize, 0); // this pointer has the address 0
/// ```
#[inline(always)]
#[must_use]
Expand All @@ -526,13 +531,18 @@ pub const fn null<T: ?Sized + Thin>() -> *const T {

/// Creates a null mutable raw pointer.
///
/// This function is equivalent to zero-initializing the pointer:
/// `MaybeUninit::<*mut T>::zeroed().assume_init()`.
/// The resulting pointer has the address 0.
///
/// # Examples
///
/// ```
/// use std::ptr;
///
/// let p: *mut i32 = ptr::null_mut();
/// assert!(p.is_null());
/// assert_eq!(p as usize, 0); // this pointer has the address 0
/// ```
#[inline(always)]
#[must_use]
Expand Down

0 comments on commit 98d54da

Please sign in to comment.