Skip to content

Commit 3903ea9

Browse files
committed
Make null() and null_mut() const functions
1 parent 69c3b39 commit 3903ea9

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/libcore/ptr.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ pub use intrinsics::write_bytes;
5151
/// ```
5252
#[inline]
5353
#[stable(feature = "rust1", since = "1.0.0")]
54-
pub fn null<T>() -> *const T { 0 as *const T }
54+
pub const fn null<T>() -> *const T { 0 as *const T }
5555

5656
/// Creates a null mutable raw pointer.
5757
///
@@ -65,7 +65,7 @@ pub fn null<T>() -> *const T { 0 as *const T }
6565
/// ```
6666
#[inline]
6767
#[stable(feature = "rust1", since = "1.0.0")]
68-
pub fn null_mut<T>() -> *mut T { 0 as *mut T }
68+
pub const fn null_mut<T>() -> *mut T { 0 as *mut T }
6969

7070
/// Swaps the values at two mutable locations of the same type, without
7171
/// deinitialising either. They may overlap, unlike `mem::swap` which is
@@ -163,7 +163,7 @@ impl<T: ?Sized> *const T {
163163
#[stable(feature = "rust1", since = "1.0.0")]
164164
#[inline]
165165
pub fn is_null(self) -> bool where T: Sized {
166-
self == 0 as *const T
166+
self == null()
167167
}
168168

169169
/// Returns `None` if the pointer is null, or else returns a reference to
@@ -212,7 +212,7 @@ impl<T: ?Sized> *mut T {
212212
#[stable(feature = "rust1", since = "1.0.0")]
213213
#[inline]
214214
pub fn is_null(self) -> bool where T: Sized {
215-
self == 0 as *mut T
215+
self == null_mut()
216216
}
217217

218218
/// Returns `None` if the pointer is null, or else returns a reference to

0 commit comments

Comments
 (0)