@@ -97,6 +97,10 @@ pub (crate) use self::into_iter::AsIntoIter;
97
97
98
98
mod into_iter;
99
99
100
+ use self :: is_zero:: IsZero ;
101
+
102
+ mod is_zero;
103
+
100
104
/// A contiguous growable array type, written `Vec<T>` but pronounced 'vector'.
101
105
///
102
106
/// # Examples
@@ -2042,76 +2046,6 @@ impl<T: Clone + IsZero> SpecFromElem for T {
2042
2046
}
2043
2047
}
2044
2048
2045
- #[ rustc_specialization_trait]
2046
- unsafe trait IsZero {
2047
- /// Whether this value is zero
2048
- fn is_zero ( & self ) -> bool ;
2049
- }
2050
-
2051
- macro_rules! impl_is_zero {
2052
- ( $t: ty, $is_zero: expr) => {
2053
- unsafe impl IsZero for $t {
2054
- #[ inline]
2055
- fn is_zero( & self ) -> bool {
2056
- $is_zero( * self )
2057
- }
2058
- }
2059
- } ;
2060
- }
2061
-
2062
- impl_is_zero ! ( i16 , |x| x == 0 ) ;
2063
- impl_is_zero ! ( i32 , |x| x == 0 ) ;
2064
- impl_is_zero ! ( i64 , |x| x == 0 ) ;
2065
- impl_is_zero ! ( i128 , |x| x == 0 ) ;
2066
- impl_is_zero ! ( isize , |x| x == 0 ) ;
2067
-
2068
- impl_is_zero ! ( u16 , |x| x == 0 ) ;
2069
- impl_is_zero ! ( u32 , |x| x == 0 ) ;
2070
- impl_is_zero ! ( u64 , |x| x == 0 ) ;
2071
- impl_is_zero ! ( u128 , |x| x == 0 ) ;
2072
- impl_is_zero ! ( usize , |x| x == 0 ) ;
2073
-
2074
- impl_is_zero ! ( bool , |x| x == false ) ;
2075
- impl_is_zero ! ( char , |x| x == '\0' ) ;
2076
-
2077
- impl_is_zero ! ( f32 , |x: f32 | x. to_bits( ) == 0 ) ;
2078
- impl_is_zero ! ( f64 , |x: f64 | x. to_bits( ) == 0 ) ;
2079
-
2080
- unsafe impl < T > IsZero for * const T {
2081
- #[ inline]
2082
- fn is_zero ( & self ) -> bool {
2083
- ( * self ) . is_null ( )
2084
- }
2085
- }
2086
-
2087
- unsafe impl < T > IsZero for * mut T {
2088
- #[ inline]
2089
- fn is_zero ( & self ) -> bool {
2090
- ( * self ) . is_null ( )
2091
- }
2092
- }
2093
-
2094
- // `Option<&T>` and `Option<Box<T>>` are guaranteed to represent `None` as null.
2095
- // For fat pointers, the bytes that would be the pointer metadata in the `Some`
2096
- // variant are padding in the `None` variant, so ignoring them and
2097
- // zero-initializing instead is ok.
2098
- // `Option<&mut T>` never implements `Clone`, so there's no need for an impl of
2099
- // `SpecFromElem`.
2100
-
2101
- unsafe impl < T : ?Sized > IsZero for Option < & T > {
2102
- #[ inline]
2103
- fn is_zero ( & self ) -> bool {
2104
- self . is_none ( )
2105
- }
2106
- }
2107
-
2108
- unsafe impl < T : ?Sized > IsZero for Option < Box < T > > {
2109
- #[ inline]
2110
- fn is_zero ( & self ) -> bool {
2111
- self . is_none ( )
2112
- }
2113
- }
2114
-
2115
2049
////////////////////////////////////////////////////////////////////////////////
2116
2050
// Common trait implementations for Vec
2117
2051
////////////////////////////////////////////////////////////////////////////////
0 commit comments