Skip to content

Commit

Permalink
Rollup merge of rust-lang#64996 - lzutao:inline-ptr-null, r=oli-obk
Browse files Browse the repository at this point in the history
Inline `ptr::null(_mut)` even in debug builds

I think we should treat `ptr::null(_mut)` as a constant. As It may help reduce code size
in debug build.
See godbolt link: https://godbolt.org/z/b9YMtD
  • Loading branch information
Centril authored Oct 19, 2019
2 parents c491875 + d0862ec commit 4d96185
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/libcore/ptr/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ unsafe fn real_drop_in_place<T: ?Sized>(to_drop: &mut T) {
/// let p: *const i32 = ptr::null();
/// assert!(p.is_null());
/// ```
#[inline]
#[inline(always)]
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_promotable]
pub const fn null<T>() -> *const T { 0 as *const T }
Expand All @@ -203,7 +203,7 @@ pub const fn null<T>() -> *const T { 0 as *const T }
/// let p: *mut i32 = ptr::null_mut();
/// assert!(p.is_null());
/// ```
#[inline]
#[inline(always)]
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_promotable]
pub const fn null_mut<T>() -> *mut T { 0 as *mut T }
Expand Down

0 comments on commit 4d96185

Please sign in to comment.