@@ -476,11 +476,6 @@ pub unsafe fn write_volatile<T>(dst: *mut T, src: T) {
476476impl < T : ?Sized > * const T {
477477 /// Returns `true` if the pointer is null.
478478 ///
479- /// Note that unsized types have many possible null pointers, as only the
480- /// raw data pointer is considered, not their length, vtable, etc.
481- /// Therefore, two pointers that are null may still not compare equal to
482- /// each other.
483- ///
484479 /// # Examples
485480 ///
486481 /// Basic usage:
@@ -492,10 +487,8 @@ impl<T: ?Sized> *const T {
492487 /// ```
493488 #[ stable( feature = "rust1" , since = "1.0.0" ) ]
494489 #[ inline]
495- pub fn is_null ( self ) -> bool {
496- // Compare via a cast to a thin pointer, so fat pointers are only
497- // considering their "data" part for null-ness.
498- ( self as * const u8 ) == null ( )
490+ pub fn is_null ( self ) -> bool where T : Sized {
491+ self == null ( )
499492 }
500493
501494 /// Returns `None` if the pointer is null, or else returns a reference to
@@ -527,7 +520,9 @@ impl<T: ?Sized> *const T {
527520 #[ stable( feature = "ptr_as_ref" , since = "1.9.0" ) ]
528521 #[ inline]
529522 pub unsafe fn as_ref < ' a > ( self ) -> Option < & ' a T > {
530- if self . is_null ( ) {
523+ // Check for null via a cast to a thin pointer, so fat pointers are only
524+ // considering their "data" part for null-ness.
525+ if ( self as * const u8 ) . is_null ( ) {
531526 None
532527 } else {
533528 Some ( & * self )
@@ -1114,11 +1109,6 @@ impl<T: ?Sized> *const T {
11141109impl < T : ?Sized > * mut T {
11151110 /// Returns `true` if the pointer is null.
11161111 ///
1117- /// Note that unsized types have many possible null pointers, as only the
1118- /// raw data pointer is considered, not their length, vtable, etc.
1119- /// Therefore, two pointers that are null may still not compare equal to
1120- /// each other.
1121- ///
11221112 /// # Examples
11231113 ///
11241114 /// Basic usage:
@@ -1130,10 +1120,8 @@ impl<T: ?Sized> *mut T {
11301120 /// ```
11311121 #[ stable( feature = "rust1" , since = "1.0.0" ) ]
11321122 #[ inline]
1133- pub fn is_null ( self ) -> bool {
1134- // Compare via a cast to a thin pointer, so fat pointers are only
1135- // considering their "data" part for null-ness.
1136- ( self as * mut u8 ) == null_mut ( )
1123+ pub fn is_null ( self ) -> bool where T : Sized {
1124+ self == null_mut ( )
11371125 }
11381126
11391127 /// Returns `None` if the pointer is null, or else returns a reference to
@@ -1165,7 +1153,9 @@ impl<T: ?Sized> *mut T {
11651153 #[ stable( feature = "ptr_as_ref" , since = "1.9.0" ) ]
11661154 #[ inline]
11671155 pub unsafe fn as_ref < ' a > ( self ) -> Option < & ' a T > {
1168- if self . is_null ( ) {
1156+ // Check for null via a cast to a thin pointer, so fat pointers are only
1157+ // considering their "data" part for null-ness.
1158+ if ( self as * const u8 ) . is_null ( ) {
11691159 None
11701160 } else {
11711161 Some ( & * self )
@@ -1289,7 +1279,9 @@ impl<T: ?Sized> *mut T {
12891279 #[ stable( feature = "ptr_as_ref" , since = "1.9.0" ) ]
12901280 #[ inline]
12911281 pub unsafe fn as_mut < ' a > ( self ) -> Option < & ' a mut T > {
1292- if self . is_null ( ) {
1282+ // Check for null via a cast to a thin pointer, so fat pointers are only
1283+ // considering their "data" part for null-ness.
1284+ if ( self as * mut u8 ) . is_null ( ) {
12931285 None
12941286 } else {
12951287 Some ( & mut * self )
0 commit comments