File tree 2 files changed +12
-13
lines changed
2 files changed +12
-13
lines changed Original file line number Diff line number Diff line change @@ -40,19 +40,8 @@ impl_is_zero!(char, |x| x == '\0');
40
40
impl_is_zero ! ( f32 , |x: f32 | x. to_bits( ) == 0 ) ;
41
41
impl_is_zero ! ( f64 , |x: f64 | x. to_bits( ) == 0 ) ;
42
42
43
- unsafe impl < T > IsZero for * const T {
44
- #[ inline]
45
- fn is_zero ( & self ) -> bool {
46
- ( * self ) . is_null ( )
47
- }
48
- }
49
-
50
- unsafe impl < T > IsZero for * mut T {
51
- #[ inline]
52
- fn is_zero ( & self ) -> bool {
53
- ( * self ) . is_null ( )
54
- }
55
- }
43
+ // `IsZero` cannot be soundly implemented for pointers because of provenance
44
+ // (see #135338).
56
45
57
46
unsafe impl < T : IsZero , const N : usize > IsZero for [ T ; N ] {
58
47
#[ inline]
Original file line number Diff line number Diff line change @@ -2742,3 +2742,13 @@ fn max_swap_remove() {
2742
2742
let mut v = vec ! [ 0 ] ;
2743
2743
v. swap_remove ( usize:: MAX ) ;
2744
2744
}
2745
+
2746
+ // Regression test for #135338
2747
+ #[ test]
2748
+ fn vec_null_ptr_roundtrip ( ) {
2749
+ let ptr = std:: ptr:: from_ref ( & 42 ) ;
2750
+ let zero = ptr. with_addr ( 0 ) ;
2751
+ let roundtripped = vec ! [ zero; 1 ] . pop ( ) . unwrap ( ) ;
2752
+ let new = roundtripped. with_addr ( ptr. addr ( ) ) ;
2753
+ unsafe { new. read ( ) } ;
2754
+ }
You can’t perform that action at this time.
0 commit comments