@@ -485,9 +485,8 @@ impl<T: ?Sized> *const T {
485
485
/// ```
486
486
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
487
487
#[ inline]
488
- pub fn is_null ( self ) -> bool {
489
- // cast to () pointer, as T may not be sized
490
- self as * const ( ) == null ( )
488
+ pub fn is_null ( self ) -> bool where T : Sized {
489
+ self == null ( )
491
490
}
492
491
493
492
/// Returns `None` if the pointer is null, or else returns a reference to
@@ -518,7 +517,7 @@ impl<T: ?Sized> *const T {
518
517
/// ```
519
518
#[ stable( feature = "ptr_as_ref" , since = "1.9.0" ) ]
520
519
#[ inline]
521
- pub unsafe fn as_ref < ' a > ( self ) -> Option < & ' a T > {
520
+ pub unsafe fn as_ref < ' a > ( self ) -> Option < & ' a T > where T : Sized {
522
521
if self . is_null ( ) {
523
522
None
524
523
} else {
@@ -1117,9 +1116,8 @@ impl<T: ?Sized> *mut T {
1117
1116
/// ```
1118
1117
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
1119
1118
#[ inline]
1120
- pub fn is_null ( self ) -> bool {
1121
- // cast to () pointer, as T may not be sized
1122
- self as * mut ( ) == null_mut ( )
1119
+ pub fn is_null ( self ) -> bool where T : Sized {
1120
+ self == null_mut ( )
1123
1121
}
1124
1122
1125
1123
/// Returns `None` if the pointer is null, or else returns a reference to
@@ -1150,7 +1148,7 @@ impl<T: ?Sized> *mut T {
1150
1148
/// ```
1151
1149
#[ stable( feature = "ptr_as_ref" , since = "1.9.0" ) ]
1152
1150
#[ inline]
1153
- pub unsafe fn as_ref < ' a > ( self ) -> Option < & ' a T > {
1151
+ pub unsafe fn as_ref < ' a > ( self ) -> Option < & ' a T > where T : Sized {
1154
1152
if self . is_null ( ) {
1155
1153
None
1156
1154
} else {
@@ -1274,7 +1272,7 @@ impl<T: ?Sized> *mut T {
1274
1272
/// ```
1275
1273
#[ stable( feature = "ptr_as_ref" , since = "1.9.0" ) ]
1276
1274
#[ inline]
1277
- pub unsafe fn as_mut < ' a > ( self ) -> Option < & ' a mut T > {
1275
+ pub unsafe fn as_mut < ' a > ( self ) -> Option < & ' a mut T > where T : Sized {
1278
1276
if self . is_null ( ) {
1279
1277
None
1280
1278
} else {
0 commit comments