Skip to content

Commit

Permalink
Auto merge of rust-lang#116988 - RalfJung:null, r=WaffleLapkin
Browse files Browse the repository at this point in the history
document that the null pointer has the 0 address

Fixes rust-lang#116895

Will need t-lang FCP, but I think this is fairly uncontroversial -- there's probably already tons of code out there that relies on this.
  • Loading branch information
bors committed Nov 6, 2023
2 parents e1fcecb + 98d54da commit b049093
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 b049093

Please sign in to comment.