Auto merge of #116988 - RalfJung:null, r=WaffleLapkin
document that the null pointer has the 0 address Fixes https://github.com/rust-lang/rust/issues/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.
This commit is contained in:
commit
b049093560
@ -505,6 +505,10 @@ 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
|
||||
///
|
||||
/// ```
|
||||
@ -512,6 +516,7 @@ pub unsafe fn drop_in_place<T: ?Sized>(to_drop: *mut T) {
|
||||
///
|
||||
/// 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]
|
||||
@ -526,6 +531,10 @@ 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
|
||||
///
|
||||
/// ```
|
||||
@ -533,6 +542,7 @@ pub const fn null<T: ?Sized + Thin>() -> *const T {
|
||||
///
|
||||
/// 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]
|
||||
|
Loading…
Reference in New Issue
Block a user