@@ -29,7 +29,7 @@ mod bytewise;
29
29
pub ( crate ) use bytewise:: BytewiseEq ;
30
30
31
31
use self :: Ordering :: * ;
32
- use crate :: marker:: PointeeSized ;
32
+ use crate :: marker:: { Destruct , PointeeSized } ;
33
33
use crate :: ops:: ControlFlow ;
34
34
35
35
/// Trait for comparisons using the equality operator.
@@ -335,7 +335,8 @@ pub macro PartialEq($item:item) {
335
335
#[ doc( alias = "!=" ) ]
336
336
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
337
337
#[ rustc_diagnostic_item = "Eq" ]
338
- pub trait Eq : PartialEq < Self > + PointeeSized {
338
+ #[ rustc_const_unstable( feature = "const_cmp" , issue = "143800" ) ]
339
+ pub const trait Eq : [ const ] PartialEq < Self > + PointeeSized {
339
340
// this method is used solely by `impl Eq or #[derive(Eq)]` to assert that every component of a
340
341
// type implements `Eq` itself. The current deriving infrastructure means doing this assertion
341
342
// without using a method on this trait is nearly impossible.
@@ -958,7 +959,8 @@ impl<T: Clone> Clone for Reverse<T> {
958
959
#[ doc( alias = ">=" ) ]
959
960
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
960
961
#[ rustc_diagnostic_item = "Ord" ]
961
- pub trait Ord : Eq + PartialOrd < Self > + PointeeSized {
962
+ #[ rustc_const_unstable( feature = "const_cmp" , issue = "143800" ) ]
963
+ pub const trait Ord : [ const ] Eq + [ const ] PartialOrd < Self > + PointeeSized {
962
964
/// This method returns an [`Ordering`] between `self` and `other`.
963
965
///
964
966
/// By convention, `self.cmp(&other)` returns the ordering matching the expression
@@ -1012,7 +1014,7 @@ pub trait Ord: Eq + PartialOrd<Self> + PointeeSized {
1012
1014
#[ rustc_diagnostic_item = "cmp_ord_max" ]
1013
1015
fn max ( self , other : Self ) -> Self
1014
1016
where
1015
- Self : Sized ,
1017
+ Self : Sized + [ const ] Destruct ,
1016
1018
{
1017
1019
if other < self { self } else { other }
1018
1020
}
@@ -1051,7 +1053,7 @@ pub trait Ord: Eq + PartialOrd<Self> + PointeeSized {
1051
1053
#[ rustc_diagnostic_item = "cmp_ord_min" ]
1052
1054
fn min ( self , other : Self ) -> Self
1053
1055
where
1054
- Self : Sized ,
1056
+ Self : Sized + [ const ] Destruct ,
1055
1057
{
1056
1058
if other < self { other } else { self }
1057
1059
}
@@ -1077,7 +1079,7 @@ pub trait Ord: Eq + PartialOrd<Self> + PointeeSized {
1077
1079
#[ stable( feature = "clamp" , since = "1.50.0" ) ]
1078
1080
fn clamp ( self , min : Self , max : Self ) -> Self
1079
1081
where
1080
- Self : Sized ,
1082
+ Self : Sized + [ const ] Destruct ,
1081
1083
{
1082
1084
assert ! ( min <= max) ;
1083
1085
if self < min {
@@ -1342,7 +1344,10 @@ pub macro Ord($item:item) {
1342
1344
) ]
1343
1345
#[ rustc_diagnostic_item = "PartialOrd" ]
1344
1346
#[ allow( multiple_supertrait_upcastable) ] // FIXME(sized_hierarchy): remove this
1345
- pub trait PartialOrd < Rhs : PointeeSized = Self > : PartialEq < Rhs > + PointeeSized {
1347
+ #[ rustc_const_unstable( feature = "const_cmp" , issue = "143800" ) ]
1348
+ pub const trait PartialOrd <Rhs : PointeeSized = Self >:
1349
+ [ const ] PartialEq < Rhs > + PointeeSized
1350
+ {
1346
1351
/// This method returns an ordering between `self` and `other` values if one exists.
1347
1352
///
1348
1353
/// # Examples
@@ -1482,14 +1487,12 @@ pub trait PartialOrd<Rhs: PointeeSized = Self>: PartialEq<Rhs> + PointeeSized {
1482
1487
}
1483
1488
}
1484
1489
1485
- fn default_chaining_impl < T , U > (
1486
- lhs : & T ,
1487
- rhs : & U ,
1488
- p : impl FnOnce ( Ordering ) -> bool ,
1489
- ) -> ControlFlow < bool >
1490
+ #[ rustc_const_unstable( feature = "const_cmp" , issue = "143800" ) ]
1491
+ const fn default_chaining_impl< T , U , F > ( lhs : & T , rhs : & U , p : F ) -> ControlFlow < bool >
1490
1492
where
1491
- T : PartialOrd < U > + PointeeSized ,
1493
+ T : [ const ] PartialOrd < U > + PointeeSized ,
1492
1494
U : PointeeSized ,
1495
+ F : [ const ] Destruct + [ const ] FnOnce ( Ordering ) -> bool ,
1493
1496
{
1494
1497
// It's important that this only call `partial_cmp` once, not call `eq` then
1495
1498
// one of the relational operators. We don't want to `bcmp`-then-`memcp` a
@@ -1831,7 +1834,8 @@ mod impls {
1831
1834
}
1832
1835
1833
1836
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
1834
- impl PartialEq for ( ) {
1837
+ #[ rustc_const_unstable( feature = "const_cmp" , issue = "143800" ) ]
1838
+ impl const PartialEq for ( ) {
1835
1839
#[ inline]
1836
1840
fn eq ( & self , _other : & ( ) ) -> bool {
1837
1841
true
@@ -1849,7 +1853,8 @@ mod impls {
1849
1853
macro_rules! eq_impl {
1850
1854
( $( $t: ty) * ) => ( $(
1851
1855
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
1852
- impl Eq for $t { }
1856
+ #[ rustc_const_unstable( feature = "const_cmp" , issue = "143800" ) ]
1857
+ impl const Eq for $t { }
1853
1858
) * )
1854
1859
}
1855
1860
@@ -1897,7 +1902,8 @@ mod impls {
1897
1902
macro_rules! partial_ord_impl {
1898
1903
( $( $t: ty) * ) => ( $(
1899
1904
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
1900
- impl PartialOrd for $t {
1905
+ #[ rustc_const_unstable( feature = "const_cmp" , issue = "143800" ) ]
1906
+ impl const PartialOrd for $t {
1901
1907
#[ inline]
1902
1908
fn partial_cmp( & self , other: & Self ) -> Option <Ordering > {
1903
1909
match ( * self <= * other, * self >= * other) {
@@ -1914,15 +1920,17 @@ mod impls {
1914
1920
}
1915
1921
1916
1922
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
1917
- impl PartialOrd for ( ) {
1923
+ #[ rustc_const_unstable( feature = "const_cmp" , issue = "143800" ) ]
1924
+ impl const PartialOrd for ( ) {
1918
1925
#[ inline]
1919
1926
fn partial_cmp ( & self , _: & ( ) ) -> Option < Ordering > {
1920
1927
Some ( Equal )
1921
1928
}
1922
1929
}
1923
1930
1924
1931
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
1925
- impl PartialOrd for bool {
1932
+ #[ rustc_const_unstable( feature = "const_cmp" , issue = "143800" ) ]
1933
+ impl const PartialOrd for bool {
1926
1934
#[ inline]
1927
1935
fn partial_cmp ( & self , other : & bool ) -> Option < Ordering > {
1928
1936
Some ( self . cmp ( other) )
@@ -1936,7 +1944,8 @@ mod impls {
1936
1944
macro_rules! ord_impl {
1937
1945
( $( $t: ty) * ) => ( $(
1938
1946
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
1939
- impl PartialOrd for $t {
1947
+ #[ rustc_const_unstable( feature = "const_cmp" , issue = "143800" ) ]
1948
+ impl const PartialOrd for $t {
1940
1949
#[ inline]
1941
1950
fn partial_cmp( & self , other: & Self ) -> Option <Ordering > {
1942
1951
Some ( crate :: intrinsics:: three_way_compare( * self , * other) )
@@ -1946,7 +1955,8 @@ mod impls {
1946
1955
}
1947
1956
1948
1957
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
1949
- impl Ord for $t {
1958
+ #[ rustc_const_unstable( feature = "const_cmp" , issue = "143800" ) ]
1959
+ impl const Ord for $t {
1950
1960
#[ inline]
1951
1961
fn cmp( & self , other: & Self ) -> Ordering {
1952
1962
crate :: intrinsics:: three_way_compare( * self , * other)
@@ -1956,15 +1966,17 @@ mod impls {
1956
1966
}
1957
1967
1958
1968
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
1959
- impl Ord for ( ) {
1969
+ #[ rustc_const_unstable( feature = "const_cmp" , issue = "143800" ) ]
1970
+ impl const Ord for ( ) {
1960
1971
#[ inline]
1961
1972
fn cmp ( & self , _other : & ( ) ) -> Ordering {
1962
1973
Equal
1963
1974
}
1964
1975
}
1965
1976
1966
1977
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
1967
- impl Ord for bool {
1978
+ #[ rustc_const_unstable( feature = "const_cmp" , issue = "143800" ) ]
1979
+ impl const Ord for bool {
1968
1980
#[ inline]
1969
1981
fn cmp ( & self , other : & bool ) -> Ordering {
1970
1982
// Casting to i8's and converting the difference to an Ordering generates
@@ -2043,9 +2055,10 @@ mod impls {
2043
2055
}
2044
2056
}
2045
2057
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
2046
- impl < A : PointeeSized , B : PointeeSized > PartialOrd < & B > for & A
2058
+ #[ rustc_const_unstable( feature = "const_cmp" , issue = "143800" ) ]
2059
+ impl < A : PointeeSized , B : PointeeSized > const PartialOrd < & B > for & A
2047
2060
where
2048
- A : PartialOrd < B > ,
2061
+ A : [ const ] PartialOrd < B > ,
2049
2062
{
2050
2063
#[ inline]
2051
2064
fn partial_cmp ( & self , other : & & B ) -> Option < Ordering > {
@@ -2085,17 +2098,19 @@ mod impls {
2085
2098
}
2086
2099
}
2087
2100
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
2088
- impl < A : PointeeSized > Ord for & A
2101
+ #[ rustc_const_unstable( feature = "const_cmp" , issue = "143800" ) ]
2102
+ impl < A : PointeeSized > const Ord for & A
2089
2103
where
2090
- A : Ord ,
2104
+ A : [ const ] Ord ,
2091
2105
{
2092
2106
#[ inline]
2093
2107
fn cmp ( & self , other : & Self ) -> Ordering {
2094
2108
Ord :: cmp ( * self , * other)
2095
2109
}
2096
2110
}
2097
2111
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
2098
- impl < A : PointeeSized > Eq for & A where A : Eq { }
2112
+ #[ rustc_const_unstable( feature = "const_cmp" , issue = "143800" ) ]
2113
+ impl < A : PointeeSized > const Eq for & A where A : [ const ] Eq { }
2099
2114
2100
2115
// &mut pointers
2101
2116
@@ -2115,9 +2130,10 @@ mod impls {
2115
2130
}
2116
2131
}
2117
2132
#[ stable ( feature = "rust1" , since = "1.0.0" ) ]
2118
- impl < A : PointeeSized , B : PointeeSized > PartialOrd < & mut B > for & mut A
2133
+ #[ rustc_const_unstable ( feature = "const_cmp" , issue = "143800" ) ]
2134
+ impl <A : PointeeSized , B : PointeeSized > const PartialOrd < & mut B > for & mut A
2119
2135
where
2120
- A : PartialOrd < B > ,
2136
+ A : [ const ] PartialOrd < B > ,
2121
2137
{
2122
2138
#[ inline ]
2123
2139
fn partial_cmp ( & self , other : & & mut B ) -> Option < Ordering > {
@@ -2157,17 +2173,19 @@ mod impls {
2157
2173
}
2158
2174
}
2159
2175
#[ stable ( feature = "rust1" , since = "1.0.0" ) ]
2160
- impl < A : PointeeSized > Ord for & mut A
2176
+ #[ rustc_const_unstable ( feature = "const_cmp" , issue = "143800" ) ]
2177
+ impl <A : PointeeSized > const Ord for & mut A
2161
2178
where
2162
- A : Ord ,
2179
+ A : [ const ] Ord ,
2163
2180
{
2164
2181
#[ inline ]
2165
2182
fn cmp ( & self , other : & Self ) -> Ordering {
2166
2183
Ord :: cmp ( * self , * other )
2167
2184
}
2168
2185
}
2169
2186
#[ stable ( feature = "rust1" , since = "1.0.0" ) ]
2170
- impl < A : PointeeSized > Eq for & mut A where A : Eq { }
2187
+ #[ rustc_const_unstable ( feature = "const_cmp" , issue = "143800" ) ]
2188
+ impl <A : PointeeSized > const Eq for & mut A where A : [ const ] Eq { }
2171
2189
2172
2190
#[ stable ( feature = "rust1" , since = "1.0.0" ) ]
2173
2191
#[ rustc_const_unstable ( feature = "const_cmp" , issue = "143800" ) ]
0 commit comments