@@ -1823,8 +1823,6 @@ mod impls {
1823
1823
impl const PartialEq for $t {
1824
1824
#[ inline]
1825
1825
fn eq( & self , other: & Self ) -> bool { * self == * other }
1826
- #[ inline]
1827
- fn ne( & self , other: & Self ) -> bool { * self != * other }
1828
1826
}
1829
1827
) * )
1830
1828
}
@@ -1835,10 +1833,6 @@ mod impls {
1835
1833
fn eq ( & self , _other : & ( ) ) -> bool {
1836
1834
true
1837
1835
}
1838
- #[ inline]
1839
- fn ne ( & self , _other : & ( ) ) -> bool {
1840
- false
1841
- }
1842
1836
}
1843
1837
1844
1838
partial_eq_impl ! {
@@ -2024,179 +2018,98 @@ mod impls {
2024
2018
}
2025
2019
}
2026
2020
2027
- // & pointers
2021
+ // reference types
2028
2022
2029
- #[ stable( feature = "rust1" , since = "1.0.0" ) ]
2030
- #[ rustc_const_unstable( feature = "const_cmp" , issue = "143800" ) ]
2031
- impl < A : PointeeSized , B : PointeeSized > const PartialEq < & B > for & A
2032
- where
2033
- A : [ const ] PartialEq < B > ,
2034
- {
2035
- #[ inline]
2036
- fn eq ( & self , other : & & B ) -> bool {
2037
- PartialEq :: eq ( * self , * other)
2038
- }
2039
- #[ inline]
2040
- fn ne ( & self , other : & & B ) -> bool {
2041
- PartialEq :: ne ( * self , * other)
2042
- }
2043
- }
2044
- #[ stable( feature = "rust1" , since = "1.0.0" ) ]
2045
- impl < A : PointeeSized , B : PointeeSized > PartialOrd < & B > for & A
2046
- where
2047
- A : PartialOrd < B > ,
2048
- {
2049
- #[ inline]
2050
- fn partial_cmp ( & self , other : & & B ) -> Option < Ordering > {
2051
- PartialOrd :: partial_cmp ( * self , * other)
2052
- }
2053
- #[ inline]
2054
- fn lt ( & self , other : & & B ) -> bool {
2055
- PartialOrd :: lt ( * self , * other)
2056
- }
2057
- #[ inline]
2058
- fn le ( & self , other : & & B ) -> bool {
2059
- PartialOrd :: le ( * self , * other)
2060
- }
2061
- #[ inline]
2062
- fn gt ( & self , other : & & B ) -> bool {
2063
- PartialOrd :: gt ( * self , * other)
2064
- }
2065
- #[ inline]
2066
- fn ge ( & self , other : & & B ) -> bool {
2067
- PartialOrd :: ge ( * self , * other)
2068
- }
2069
- #[ inline]
2070
- fn __chaining_lt ( & self , other : & & B ) -> ControlFlow < bool > {
2071
- PartialOrd :: __chaining_lt ( * self , * other)
2072
- }
2073
- #[ inline]
2074
- fn __chaining_le ( & self , other : & & B ) -> ControlFlow < bool > {
2075
- PartialOrd :: __chaining_le ( * self , * other)
2076
- }
2077
- #[ inline]
2078
- fn __chaining_gt ( & self , other : & & B ) -> ControlFlow < bool > {
2079
- PartialOrd :: __chaining_gt ( * self , * other)
2080
- }
2081
- #[ inline]
2082
- fn __chaining_ge ( & self , other : & & B ) -> ControlFlow < bool > {
2083
- PartialOrd :: __chaining_ge ( * self , * other)
2084
- }
2085
- }
2086
- #[ stable( feature = "rust1" , since = "1.0.0" ) ]
2087
- impl < A : PointeeSized > Ord for & A
2088
- where
2089
- A : Ord ,
2090
- {
2091
- #[ inline]
2092
- fn cmp ( & self , other : & Self ) -> Ordering {
2093
- Ord :: cmp ( * self , * other)
2094
- }
2023
+ macro_rules! partial_eq_impl {
2024
+ ( $( ( $ref_A: ty => $A: ident, $ref_B: ty => $B: ident) ) * ) => ( $(
2025
+ #[ stable( feature = "rust1" , since = "1.0.0" ) ]
2026
+ #[ rustc_const_unstable( feature = "const_cmp" , issue = "143800" ) ]
2027
+ impl <$A, $B> const PartialEq <$ref_B> for $ref_A
2028
+ where
2029
+ $A: [ const ] PartialEq <$B> + PointeeSized ,
2030
+ $B: PointeeSized ,
2031
+ {
2032
+ #[ inline]
2033
+ fn eq( & self , other: & $ref_B) -> bool {
2034
+ PartialEq :: eq( * self , * other)
2035
+ }
2036
+ // if <A as PartialEq<B>>::ne uses inline assembly or FFI, then
2037
+ // this forwarding impl may be more efficient than the default impl
2038
+ #[ inline]
2039
+ fn ne( & self , other: & $ref_B) -> bool {
2040
+ PartialEq :: ne( * self , * other)
2041
+ }
2042
+ }
2043
+ ) * )
2095
2044
}
2096
- #[ stable( feature = "rust1" , since = "1.0.0" ) ]
2097
- impl < A : PointeeSized > Eq for & A where A : Eq { }
2098
2045
2099
- // & mut pointers
2046
+ partial_eq_impl ! ( ( & A => A , & B => B ) ( & A => A , & mut B => B ) ( & mut A => A , & B => B ) ( & mut A => A , & mut B => B ) ) ;
2100
2047
2101
- #[ stable( feature = "rust1" , since = "1.0.0" ) ]
2102
- #[ rustc_const_unstable( feature = "const_cmp" , issue = "143800" ) ]
2103
- impl < A : PointeeSized , B : PointeeSized > const PartialEq < & mut B > for & mut A
2104
- where
2105
- A : [ const ] PartialEq < B > ,
2106
- {
2107
- #[ inline]
2108
- fn eq ( & self , other : & & mut B ) -> bool {
2109
- PartialEq :: eq ( * self , * other)
2110
- }
2111
- #[ inline]
2112
- fn ne ( & self , other : & & mut B ) -> bool {
2113
- PartialEq :: ne ( * self , * other)
2114
- }
2115
- }
2116
- #[ stable( feature = "rust1" , since = "1.0.0" ) ]
2117
- impl < A : PointeeSized , B : PointeeSized > PartialOrd < & mut B > for & mut A
2118
- where
2119
- A : PartialOrd < B > ,
2120
- {
2121
- #[ inline]
2122
- fn partial_cmp ( & self , other : & & mut B ) -> Option < Ordering > {
2123
- PartialOrd :: partial_cmp ( * self , * other)
2124
- }
2125
- #[ inline]
2126
- fn lt ( & self , other : & & mut B ) -> bool {
2127
- PartialOrd :: lt ( * self , * other)
2128
- }
2129
- #[ inline]
2130
- fn le ( & self , other : & & mut B ) -> bool {
2131
- PartialOrd :: le ( * self , * other)
2132
- }
2133
- #[ inline]
2134
- fn gt ( & self , other : & & mut B ) -> bool {
2135
- PartialOrd :: gt ( * self , * other)
2136
- }
2137
- #[ inline]
2138
- fn ge ( & self , other : & & mut B ) -> bool {
2139
- PartialOrd :: ge ( * self , * other)
2140
- }
2141
- #[ inline]
2142
- fn __chaining_lt ( & self , other : & & mut B ) -> ControlFlow < bool > {
2143
- PartialOrd :: __chaining_lt ( * self , * other)
2144
- }
2145
- #[ inline]
2146
- fn __chaining_le ( & self , other : & & mut B ) -> ControlFlow < bool > {
2147
- PartialOrd :: __chaining_le ( * self , * other)
2148
- }
2149
- #[ inline]
2150
- fn __chaining_gt ( & self , other : & & mut B ) -> ControlFlow < bool > {
2151
- PartialOrd :: __chaining_gt ( * self , * other)
2152
- }
2153
- #[ inline]
2154
- fn __chaining_ge ( & self , other : & & mut B ) -> ControlFlow < bool > {
2155
- PartialOrd :: __chaining_ge ( * self , * other)
2156
- }
2157
- }
2158
- #[ stable( feature = "rust1" , since = "1.0.0" ) ]
2159
- impl < A : PointeeSized > Ord for & mut A
2160
- where
2161
- A : Ord ,
2162
- {
2163
- #[ inline]
2164
- fn cmp ( & self , other : & Self ) -> Ordering {
2165
- Ord :: cmp ( * self , * other)
2166
- }
2048
+ macro_rules! partial_ord_impl {
2049
+ ( $( ( $ref_A: ty => $A: ident, $ref_B: ty => $B: ident) ) * ) => ( $(
2050
+ #[ stable( feature = "rust1" , since = "1.0.0" ) ]
2051
+ impl <$A, $B> PartialOrd <$ref_B> for $ref_A
2052
+ where
2053
+ $A: PartialOrd <$B> + PointeeSized ,
2054
+ $B: PointeeSized ,
2055
+ {
2056
+ #[ inline]
2057
+ fn partial_cmp( & self , other: & $ref_B) -> Option <Ordering > {
2058
+ PartialOrd :: partial_cmp( * self , * other)
2059
+ }
2060
+ #[ inline]
2061
+ fn lt( & self , other: & $ref_B) -> bool {
2062
+ PartialOrd :: lt( * self , * other)
2063
+ }
2064
+ #[ inline]
2065
+ fn le( & self , other: & $ref_B) -> bool {
2066
+ PartialOrd :: le( * self , * other)
2067
+ }
2068
+ #[ inline]
2069
+ fn gt( & self , other: & $ref_B) -> bool {
2070
+ PartialOrd :: gt( * self , * other)
2071
+ }
2072
+ #[ inline]
2073
+ fn ge( & self , other: & $ref_B) -> bool {
2074
+ PartialOrd :: ge( * self , * other)
2075
+ }
2076
+ #[ inline]
2077
+ fn __chaining_lt( & self , other: & $ref_B) -> ControlFlow <bool > {
2078
+ PartialOrd :: __chaining_lt( * self , * other)
2079
+ }
2080
+ #[ inline]
2081
+ fn __chaining_le( & self , other: & $ref_B) -> ControlFlow <bool > {
2082
+ PartialOrd :: __chaining_le( * self , * other)
2083
+ }
2084
+ #[ inline]
2085
+ fn __chaining_gt( & self , other: & $ref_B) -> ControlFlow <bool > {
2086
+ PartialOrd :: __chaining_gt( * self , * other)
2087
+ }
2088
+ #[ inline]
2089
+ fn __chaining_ge( & self , other: & $ref_B) -> ControlFlow <bool > {
2090
+ PartialOrd :: __chaining_ge( * self , * other)
2091
+ }
2092
+ }
2093
+ ) * )
2167
2094
}
2168
- #[ stable( feature = "rust1" , since = "1.0.0" ) ]
2169
- impl < A : PointeeSized > Eq for & mut A where A : Eq { }
2170
2095
2171
- #[ stable( feature = "rust1" , since = "1.0.0" ) ]
2172
- #[ rustc_const_unstable( feature = "const_cmp" , issue = "143800" ) ]
2173
- impl < A : PointeeSized , B : PointeeSized > const PartialEq < & mut B > for & A
2174
- where
2175
- A : [ const ] PartialEq < B > ,
2176
- {
2177
- #[ inline]
2178
- fn eq ( & self , other : & & mut B ) -> bool {
2179
- PartialEq :: eq ( * self , * other)
2180
- }
2181
- #[ inline]
2182
- fn ne ( & self , other : & & mut B ) -> bool {
2183
- PartialEq :: ne ( * self , * other)
2184
- }
2185
- }
2096
+ partial_ord_impl ! ( ( & A => A , & B => B ) /*(&A => A, &mut B => B) (&mut A => A, &B => B)*/ ( & mut A => A , & mut B => B ) ) ;
2186
2097
2187
- # [ stable ( feature = "rust1" , since = "1.0.0" ) ]
2188
- # [ rustc_const_unstable ( feature = "const_cmp" , issue = "143800" ) ]
2189
- impl < A : PointeeSized , B : PointeeSized > const PartialEq < & B > for & mut A
2190
- where
2191
- A : [ const ] PartialEq < B > ,
2192
- {
2193
- # [ inline ]
2194
- fn eq ( & self , other : & & B ) -> bool {
2195
- PartialEq :: eq ( * self , * other )
2196
- }
2197
- # [ inline ]
2198
- fn ne ( & self , other : & & B ) -> bool {
2199
- PartialEq :: ne ( * self , * other )
2200
- }
2098
+ macro_rules! ord_eq_impl {
2099
+ ( $ ( $ref_A : ty => $A : ident ) , * ) => ( $ (
2100
+ # [ stable ( feature = "rust1" , since = "1.0.0" ) ]
2101
+ impl <$A : Ord + PointeeSized > Ord for $ref_A
2102
+ {
2103
+ # [ inline ]
2104
+ fn cmp ( & self , other : & Self ) -> Ordering {
2105
+ Ord :: cmp ( * self , * other)
2106
+ }
2107
+ }
2108
+
2109
+ # [ stable ( feature = "rust1" , since = "1.0.0" ) ]
2110
+ impl <$A : Eq + PointeeSized > Eq for $ref_A { }
2111
+ ) * )
2201
2112
}
2113
+
2114
+ ord_eq_impl ! ( & A => A , & mut A => A ) ;
2202
2115
}
0 commit comments