Constify Eq, Ord, PartialOrd
This commit is contained in:
@@ -705,7 +705,8 @@ impl dyn Any + Send + Sync {
|
||||
/// std::mem::forget(fake_one_ring);
|
||||
/// }
|
||||
/// ```
|
||||
#[derive(Clone, Copy, Eq, PartialOrd, Ord)]
|
||||
#[derive(Copy, PartialOrd, Ord)]
|
||||
#[derive_const(Clone, Eq)]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[lang = "type_id"]
|
||||
pub struct TypeId {
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
use crate::cmp::BytewiseEq;
|
||||
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
impl<T, U, const N: usize> PartialEq<[U; N]> for [T; N]
|
||||
#[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
|
||||
impl<T, U, const N: usize> const PartialEq<[U; N]> for [T; N]
|
||||
where
|
||||
T: PartialEq<U>,
|
||||
T: [const] PartialEq<U>,
|
||||
{
|
||||
#[inline]
|
||||
fn eq(&self, other: &[U; N]) -> bool {
|
||||
@@ -16,9 +17,10 @@ where
|
||||
}
|
||||
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
impl<T, U, const N: usize> PartialEq<[U]> for [T; N]
|
||||
#[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
|
||||
impl<T, U, const N: usize> const PartialEq<[U]> for [T; N]
|
||||
where
|
||||
T: PartialEq<U>,
|
||||
T: [const] PartialEq<U>,
|
||||
{
|
||||
#[inline]
|
||||
fn eq(&self, other: &[U]) -> bool {
|
||||
@@ -37,9 +39,10 @@ where
|
||||
}
|
||||
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
impl<T, U, const N: usize> PartialEq<[U; N]> for [T]
|
||||
#[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
|
||||
impl<T, U, const N: usize> const PartialEq<[U; N]> for [T]
|
||||
where
|
||||
T: PartialEq<U>,
|
||||
T: [const] PartialEq<U>,
|
||||
{
|
||||
#[inline]
|
||||
fn eq(&self, other: &[U; N]) -> bool {
|
||||
@@ -58,9 +61,10 @@ where
|
||||
}
|
||||
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
impl<T, U, const N: usize> PartialEq<&[U]> for [T; N]
|
||||
#[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
|
||||
impl<T, U, const N: usize> const PartialEq<&[U]> for [T; N]
|
||||
where
|
||||
T: PartialEq<U>,
|
||||
T: [const] PartialEq<U>,
|
||||
{
|
||||
#[inline]
|
||||
fn eq(&self, other: &&[U]) -> bool {
|
||||
@@ -73,9 +77,10 @@ where
|
||||
}
|
||||
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
impl<T, U, const N: usize> PartialEq<[U; N]> for &[T]
|
||||
#[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
|
||||
impl<T, U, const N: usize> const PartialEq<[U; N]> for &[T]
|
||||
where
|
||||
T: PartialEq<U>,
|
||||
T: [const] PartialEq<U>,
|
||||
{
|
||||
#[inline]
|
||||
fn eq(&self, other: &[U; N]) -> bool {
|
||||
@@ -88,9 +93,10 @@ where
|
||||
}
|
||||
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
impl<T, U, const N: usize> PartialEq<&mut [U]> for [T; N]
|
||||
#[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
|
||||
impl<T, U, const N: usize> const PartialEq<&mut [U]> for [T; N]
|
||||
where
|
||||
T: PartialEq<U>,
|
||||
T: [const] PartialEq<U>,
|
||||
{
|
||||
#[inline]
|
||||
fn eq(&self, other: &&mut [U]) -> bool {
|
||||
@@ -103,9 +109,10 @@ where
|
||||
}
|
||||
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
impl<T, U, const N: usize> PartialEq<[U; N]> for &mut [T]
|
||||
#[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
|
||||
impl<T, U, const N: usize> const PartialEq<[U; N]> for &mut [T]
|
||||
where
|
||||
T: PartialEq<U>,
|
||||
T: [const] PartialEq<U>,
|
||||
{
|
||||
#[inline]
|
||||
fn eq(&self, other: &[U; N]) -> bool {
|
||||
@@ -122,14 +129,18 @@ where
|
||||
// __impl_slice_eq2! { [A; $N], &'b mut [B; $N] }
|
||||
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
impl<T: Eq, const N: usize> Eq for [T; N] {}
|
||||
#[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
|
||||
impl<T: [const] Eq, const N: usize> const Eq for [T; N] {}
|
||||
|
||||
#[const_trait]
|
||||
#[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
|
||||
trait SpecArrayEq<Other, const N: usize>: Sized {
|
||||
fn spec_eq(a: &[Self; N], b: &[Other; N]) -> bool;
|
||||
fn spec_ne(a: &[Self; N], b: &[Other; N]) -> bool;
|
||||
}
|
||||
|
||||
impl<T: PartialEq<Other>, Other, const N: usize> SpecArrayEq<Other, N> for T {
|
||||
#[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
|
||||
impl<T: [const] PartialEq<Other>, Other, const N: usize> const SpecArrayEq<Other, N> for T {
|
||||
default fn spec_eq(a: &[Self; N], b: &[Other; N]) -> bool {
|
||||
a[..] == b[..]
|
||||
}
|
||||
@@ -138,7 +149,8 @@ impl<T: PartialEq<Other>, Other, const N: usize> SpecArrayEq<Other, N> for T {
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: BytewiseEq<U>, U, const N: usize> SpecArrayEq<U, N> for T {
|
||||
#[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
|
||||
impl<T: [const] BytewiseEq<U>, U, const N: usize> const SpecArrayEq<U, N> for T {
|
||||
fn spec_eq(a: &[T; N], b: &[U; N]) -> bool {
|
||||
// SAFETY: Arrays are compared element-wise, and don't add any padding
|
||||
// between elements, so when the elements are `BytewiseEq`, we can
|
||||
|
||||
@@ -54,7 +54,8 @@ use crate::{assert_unsafe_precondition, fmt};
|
||||
/// [chart]: https://www.unicode.org/charts/PDF/U0000.pdf
|
||||
/// [NIST FIPS 1-2]: https://nvlpubs.nist.gov/nistpubs/Legacy/FIPS/fipspub1-2-1977.pdf
|
||||
/// [NamesList]: https://www.unicode.org/Public/15.0.0/ucd/NamesList.txt
|
||||
#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
|
||||
#[derive(Copy, Hash)]
|
||||
#[derive_const(Clone, Eq, PartialEq, Ord, PartialOrd)]
|
||||
#[unstable(feature = "ascii_char", issue = "110998")]
|
||||
#[repr(u8)]
|
||||
pub enum AsciiChar {
|
||||
|
||||
@@ -29,7 +29,7 @@ mod bytewise;
|
||||
pub(crate) use bytewise::BytewiseEq;
|
||||
|
||||
use self::Ordering::*;
|
||||
use crate::marker::PointeeSized;
|
||||
use crate::marker::{Destruct, PointeeSized};
|
||||
use crate::ops::ControlFlow;
|
||||
|
||||
/// Trait for comparisons using the equality operator.
|
||||
@@ -334,7 +334,9 @@ pub macro PartialEq($item:item) {
|
||||
#[doc(alias = "!=")]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[rustc_diagnostic_item = "Eq"]
|
||||
pub trait Eq: PartialEq<Self> + PointeeSized {
|
||||
#[const_trait]
|
||||
#[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
|
||||
pub trait Eq: [const] PartialEq<Self> + PointeeSized {
|
||||
// this method is used solely by `impl Eq or #[derive(Eq)]` to assert that every component of a
|
||||
// type implements `Eq` itself. The current deriving infrastructure means doing this assertion
|
||||
// without using a method on this trait is nearly impossible.
|
||||
@@ -380,8 +382,8 @@ pub struct AssertParamIsEq<T: Eq + PointeeSized> {
|
||||
///
|
||||
/// assert_eq!(2.cmp(&1), Ordering::Greater);
|
||||
/// ```
|
||||
#[derive(Clone, Copy, Eq, PartialOrd, Ord, Debug, Hash)]
|
||||
#[derive_const(PartialEq)]
|
||||
#[derive(Copy, Debug, Hash)]
|
||||
#[derive_const(Clone, Eq, PartialOrd, Ord, PartialEq)]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
// This is a lang item only so that `BinOp::Cmp` in MIR can return it.
|
||||
// It has no special behavior, but does require that the three variants
|
||||
@@ -635,7 +637,11 @@ impl Ordering {
|
||||
#[inline]
|
||||
#[must_use]
|
||||
#[stable(feature = "ordering_chaining", since = "1.17.0")]
|
||||
pub fn then_with<F: FnOnce() -> Ordering>(self, f: F) -> Ordering {
|
||||
#[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
|
||||
pub const fn then_with<F>(self, f: F) -> Ordering
|
||||
where
|
||||
F: [const] FnOnce() -> Ordering + [const] Destruct,
|
||||
{
|
||||
match self {
|
||||
Equal => f(),
|
||||
_ => self,
|
||||
@@ -659,13 +665,15 @@ impl Ordering {
|
||||
/// v.sort_by_key(|&num| (num > 3, Reverse(num)));
|
||||
/// assert_eq!(v, vec![3, 2, 1, 6, 5, 4]);
|
||||
/// ```
|
||||
#[derive(PartialEq, Eq, Debug, Copy, Default, Hash)]
|
||||
#[derive(Copy, Debug, Hash)]
|
||||
#[derive_const(PartialEq, Eq, Default)]
|
||||
#[stable(feature = "reverse_cmp_key", since = "1.19.0")]
|
||||
#[repr(transparent)]
|
||||
pub struct Reverse<T>(#[stable(feature = "reverse_cmp_key", since = "1.19.0")] pub T);
|
||||
|
||||
#[stable(feature = "reverse_cmp_key", since = "1.19.0")]
|
||||
impl<T: PartialOrd> PartialOrd for Reverse<T> {
|
||||
#[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
|
||||
impl<T: [const] PartialOrd> const PartialOrd for Reverse<T> {
|
||||
#[inline]
|
||||
fn partial_cmp(&self, other: &Reverse<T>) -> Option<Ordering> {
|
||||
other.0.partial_cmp(&self.0)
|
||||
@@ -690,7 +698,8 @@ impl<T: PartialOrd> PartialOrd for Reverse<T> {
|
||||
}
|
||||
|
||||
#[stable(feature = "reverse_cmp_key", since = "1.19.0")]
|
||||
impl<T: Ord> Ord for Reverse<T> {
|
||||
#[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
|
||||
impl<T: [const] Ord> const Ord for Reverse<T> {
|
||||
#[inline]
|
||||
fn cmp(&self, other: &Reverse<T>) -> Ordering {
|
||||
other.0.cmp(&self.0)
|
||||
@@ -957,7 +966,9 @@ impl<T: Clone> Clone for Reverse<T> {
|
||||
#[doc(alias = ">=")]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[rustc_diagnostic_item = "Ord"]
|
||||
pub trait Ord: Eq + PartialOrd<Self> + PointeeSized {
|
||||
#[const_trait]
|
||||
#[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
|
||||
pub trait Ord: [const] Eq + [const] PartialOrd<Self> + PointeeSized {
|
||||
/// This method returns an [`Ordering`] between `self` and `other`.
|
||||
///
|
||||
/// By convention, `self.cmp(&other)` returns the ordering matching the expression
|
||||
@@ -1011,7 +1022,7 @@ pub trait Ord: Eq + PartialOrd<Self> + PointeeSized {
|
||||
#[rustc_diagnostic_item = "cmp_ord_max"]
|
||||
fn max(self, other: Self) -> Self
|
||||
where
|
||||
Self: Sized,
|
||||
Self: Sized + [const] Destruct,
|
||||
{
|
||||
if other < self { self } else { other }
|
||||
}
|
||||
@@ -1050,7 +1061,7 @@ pub trait Ord: Eq + PartialOrd<Self> + PointeeSized {
|
||||
#[rustc_diagnostic_item = "cmp_ord_min"]
|
||||
fn min(self, other: Self) -> Self
|
||||
where
|
||||
Self: Sized,
|
||||
Self: Sized + [const] Destruct,
|
||||
{
|
||||
if other < self { other } else { self }
|
||||
}
|
||||
@@ -1076,7 +1087,7 @@ pub trait Ord: Eq + PartialOrd<Self> + PointeeSized {
|
||||
#[stable(feature = "clamp", since = "1.50.0")]
|
||||
fn clamp(self, min: Self, max: Self) -> Self
|
||||
where
|
||||
Self: Sized,
|
||||
Self: Sized + [const] Destruct,
|
||||
{
|
||||
assert!(min <= max);
|
||||
if self < min {
|
||||
@@ -1341,6 +1352,8 @@ pub macro Ord($item:item) {
|
||||
)]
|
||||
#[rustc_diagnostic_item = "PartialOrd"]
|
||||
#[allow(multiple_supertrait_upcastable)] // FIXME(sized_hierarchy): remove this
|
||||
#[const_trait]
|
||||
#[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
|
||||
pub trait PartialOrd<Rhs: PointeeSized = Self>: PartialEq<Rhs> + PointeeSized {
|
||||
/// This method returns an ordering between `self` and `other` values if one exists.
|
||||
///
|
||||
@@ -1481,13 +1494,14 @@ pub trait PartialOrd<Rhs: PointeeSized = Self>: PartialEq<Rhs> + PointeeSized {
|
||||
}
|
||||
}
|
||||
|
||||
fn default_chaining_impl<T, U>(
|
||||
#[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
|
||||
const fn default_chaining_impl<T, U>(
|
||||
lhs: &T,
|
||||
rhs: &U,
|
||||
p: impl FnOnce(Ordering) -> bool,
|
||||
p: impl [const] FnOnce(Ordering) -> bool + [const] Destruct,
|
||||
) -> ControlFlow<bool>
|
||||
where
|
||||
T: PartialOrd<U> + PointeeSized,
|
||||
T: [const] PartialOrd<U> + PointeeSized,
|
||||
U: PointeeSized,
|
||||
{
|
||||
// It's important that this only call `partial_cmp` once, not call `eq` then
|
||||
@@ -1545,7 +1559,8 @@ pub macro PartialOrd($item:item) {
|
||||
#[must_use]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[rustc_diagnostic_item = "cmp_min"]
|
||||
pub fn min<T: Ord>(v1: T, v2: T) -> T {
|
||||
#[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
|
||||
pub const fn min<T: [const] Ord + [const] Destruct>(v1: T, v2: T) -> T {
|
||||
v1.min(v2)
|
||||
}
|
||||
|
||||
@@ -1575,7 +1590,12 @@ pub fn min<T: Ord>(v1: T, v2: T) -> T {
|
||||
#[inline]
|
||||
#[must_use]
|
||||
#[stable(feature = "cmp_min_max_by", since = "1.53.0")]
|
||||
pub fn min_by<T, F: FnOnce(&T, &T) -> Ordering>(v1: T, v2: T, compare: F) -> T {
|
||||
#[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
|
||||
pub const fn min_by<T: [const] Destruct, F: [const] FnOnce(&T, &T) -> Ordering>(
|
||||
v1: T,
|
||||
v2: T,
|
||||
compare: F,
|
||||
) -> T {
|
||||
if compare(&v1, &v2).is_le() { v1 } else { v2 }
|
||||
}
|
||||
|
||||
@@ -1600,7 +1620,13 @@ pub fn min_by<T, F: FnOnce(&T, &T) -> Ordering>(v1: T, v2: T, compare: F) -> T {
|
||||
#[inline]
|
||||
#[must_use]
|
||||
#[stable(feature = "cmp_min_max_by", since = "1.53.0")]
|
||||
pub fn min_by_key<T, F: FnMut(&T) -> K, K: Ord>(v1: T, v2: T, mut f: F) -> T {
|
||||
#[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
|
||||
pub const fn min_by_key<T, F, K>(v1: T, v2: T, mut f: F) -> T
|
||||
where
|
||||
T: [const] Destruct,
|
||||
F: [const] FnMut(&T) -> K + [const] Destruct,
|
||||
K: [const] Ord + [const] Destruct,
|
||||
{
|
||||
if f(&v2) < f(&v1) { v2 } else { v1 }
|
||||
}
|
||||
|
||||
@@ -1640,7 +1666,8 @@ pub fn min_by_key<T, F: FnMut(&T) -> K, K: Ord>(v1: T, v2: T, mut f: F) -> T {
|
||||
#[must_use]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[rustc_diagnostic_item = "cmp_max"]
|
||||
pub fn max<T: Ord>(v1: T, v2: T) -> T {
|
||||
#[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
|
||||
pub const fn max<T: [const] Ord + [const] Destruct>(v1: T, v2: T) -> T {
|
||||
v1.max(v2)
|
||||
}
|
||||
|
||||
@@ -1670,7 +1697,12 @@ pub fn max<T: Ord>(v1: T, v2: T) -> T {
|
||||
#[inline]
|
||||
#[must_use]
|
||||
#[stable(feature = "cmp_min_max_by", since = "1.53.0")]
|
||||
pub fn max_by<T, F: FnOnce(&T, &T) -> Ordering>(v1: T, v2: T, compare: F) -> T {
|
||||
#[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
|
||||
pub const fn max_by<T: [const] Destruct, F: [const] FnOnce(&T, &T) -> Ordering>(
|
||||
v1: T,
|
||||
v2: T,
|
||||
compare: F,
|
||||
) -> T {
|
||||
if compare(&v1, &v2).is_gt() { v1 } else { v2 }
|
||||
}
|
||||
|
||||
@@ -1695,7 +1727,13 @@ pub fn max_by<T, F: FnOnce(&T, &T) -> Ordering>(v1: T, v2: T, compare: F) -> T {
|
||||
#[inline]
|
||||
#[must_use]
|
||||
#[stable(feature = "cmp_min_max_by", since = "1.53.0")]
|
||||
pub fn max_by_key<T, F: FnMut(&T) -> K, K: Ord>(v1: T, v2: T, mut f: F) -> T {
|
||||
#[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
|
||||
pub const fn max_by_key<T, F, K>(v1: T, v2: T, mut f: F) -> T
|
||||
where
|
||||
T: [const] Destruct,
|
||||
F: [const] FnMut(&T) -> K + [const] Destruct,
|
||||
K: [const] Ord + [const] Destruct,
|
||||
{
|
||||
if f(&v2) < f(&v1) { v1 } else { v2 }
|
||||
}
|
||||
|
||||
@@ -1739,9 +1777,10 @@ pub fn max_by_key<T, F: FnMut(&T) -> K, K: Ord>(v1: T, v2: T, mut f: F) -> T {
|
||||
#[inline]
|
||||
#[must_use]
|
||||
#[unstable(feature = "cmp_minmax", issue = "115939")]
|
||||
pub fn minmax<T>(v1: T, v2: T) -> [T; 2]
|
||||
#[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
|
||||
pub const fn minmax<T>(v1: T, v2: T) -> [T; 2]
|
||||
where
|
||||
T: Ord,
|
||||
T: [const] Ord,
|
||||
{
|
||||
if v2 < v1 { [v2, v1] } else { [v1, v2] }
|
||||
}
|
||||
@@ -1773,9 +1812,10 @@ where
|
||||
#[inline]
|
||||
#[must_use]
|
||||
#[unstable(feature = "cmp_minmax", issue = "115939")]
|
||||
pub fn minmax_by<T, F>(v1: T, v2: T, compare: F) -> [T; 2]
|
||||
#[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
|
||||
pub const fn minmax_by<T, F>(v1: T, v2: T, compare: F) -> [T; 2]
|
||||
where
|
||||
F: FnOnce(&T, &T) -> Ordering,
|
||||
F: [const] FnOnce(&T, &T) -> Ordering,
|
||||
{
|
||||
if compare(&v1, &v2).is_le() { [v1, v2] } else { [v2, v1] }
|
||||
}
|
||||
@@ -1801,10 +1841,11 @@ where
|
||||
#[inline]
|
||||
#[must_use]
|
||||
#[unstable(feature = "cmp_minmax", issue = "115939")]
|
||||
pub fn minmax_by_key<T, F, K>(v1: T, v2: T, mut f: F) -> [T; 2]
|
||||
#[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
|
||||
pub const fn minmax_by_key<T, F, K>(v1: T, v2: T, mut f: F) -> [T; 2]
|
||||
where
|
||||
F: FnMut(&T) -> K,
|
||||
K: Ord,
|
||||
F: [const] FnMut(&T) -> K + [const] Destruct,
|
||||
K: [const] Ord + [const] Destruct,
|
||||
{
|
||||
if f(&v2) < f(&v1) { [v2, v1] } else { [v1, v2] }
|
||||
}
|
||||
@@ -1830,7 +1871,8 @@ mod impls {
|
||||
}
|
||||
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
impl PartialEq for () {
|
||||
#[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
|
||||
impl const PartialEq for () {
|
||||
#[inline]
|
||||
fn eq(&self, _other: &()) -> bool {
|
||||
true
|
||||
@@ -1848,7 +1890,8 @@ mod impls {
|
||||
macro_rules! eq_impl {
|
||||
($($t:ty)*) => ($(
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
impl Eq for $t {}
|
||||
#[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
|
||||
impl const Eq for $t {}
|
||||
)*)
|
||||
}
|
||||
|
||||
@@ -1896,7 +1939,8 @@ mod impls {
|
||||
macro_rules! partial_ord_impl {
|
||||
($($t:ty)*) => ($(
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
impl PartialOrd for $t {
|
||||
#[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
|
||||
impl const PartialOrd for $t {
|
||||
#[inline]
|
||||
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
|
||||
match (*self <= *other, *self >= *other) {
|
||||
@@ -1913,7 +1957,8 @@ mod impls {
|
||||
}
|
||||
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
impl PartialOrd for () {
|
||||
#[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
|
||||
impl const PartialOrd for () {
|
||||
#[inline]
|
||||
fn partial_cmp(&self, _: &()) -> Option<Ordering> {
|
||||
Some(Equal)
|
||||
@@ -1921,7 +1966,8 @@ mod impls {
|
||||
}
|
||||
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
impl PartialOrd for bool {
|
||||
#[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
|
||||
impl const PartialOrd for bool {
|
||||
#[inline]
|
||||
fn partial_cmp(&self, other: &bool) -> Option<Ordering> {
|
||||
Some(self.cmp(other))
|
||||
@@ -1935,7 +1981,8 @@ mod impls {
|
||||
macro_rules! ord_impl {
|
||||
($($t:ty)*) => ($(
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
impl PartialOrd for $t {
|
||||
#[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
|
||||
impl const PartialOrd for $t {
|
||||
#[inline]
|
||||
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
|
||||
Some(crate::intrinsics::three_way_compare(*self, *other))
|
||||
@@ -1945,7 +1992,8 @@ mod impls {
|
||||
}
|
||||
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
impl Ord for $t {
|
||||
#[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
|
||||
impl const Ord for $t {
|
||||
#[inline]
|
||||
fn cmp(&self, other: &Self) -> Ordering {
|
||||
crate::intrinsics::three_way_compare(*self, *other)
|
||||
@@ -1955,7 +2003,8 @@ mod impls {
|
||||
}
|
||||
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
impl Ord for () {
|
||||
#[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
|
||||
impl const Ord for () {
|
||||
#[inline]
|
||||
fn cmp(&self, _other: &()) -> Ordering {
|
||||
Equal
|
||||
@@ -1963,7 +2012,8 @@ mod impls {
|
||||
}
|
||||
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
impl Ord for bool {
|
||||
#[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
|
||||
impl const Ord for bool {
|
||||
#[inline]
|
||||
fn cmp(&self, other: &bool) -> Ordering {
|
||||
// Casting to i8's and converting the difference to an Ordering generates
|
||||
@@ -1998,7 +2048,8 @@ mod impls {
|
||||
ord_impl! { char usize u8 u16 u32 u64 u128 isize i8 i16 i32 i64 i128 }
|
||||
|
||||
#[unstable(feature = "never_type", issue = "35121")]
|
||||
impl PartialEq for ! {
|
||||
#[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
|
||||
impl const PartialEq for ! {
|
||||
#[inline]
|
||||
fn eq(&self, _: &!) -> bool {
|
||||
*self
|
||||
@@ -2006,10 +2057,12 @@ mod impls {
|
||||
}
|
||||
|
||||
#[unstable(feature = "never_type", issue = "35121")]
|
||||
impl Eq for ! {}
|
||||
#[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
|
||||
impl const Eq for ! {}
|
||||
|
||||
#[unstable(feature = "never_type", issue = "35121")]
|
||||
impl PartialOrd for ! {
|
||||
#[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
|
||||
impl const PartialOrd for ! {
|
||||
#[inline]
|
||||
fn partial_cmp(&self, _: &!) -> Option<Ordering> {
|
||||
*self
|
||||
@@ -2017,7 +2070,8 @@ mod impls {
|
||||
}
|
||||
|
||||
#[unstable(feature = "never_type", issue = "35121")]
|
||||
impl Ord for ! {
|
||||
#[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
|
||||
impl const Ord for ! {
|
||||
#[inline]
|
||||
fn cmp(&self, _: &!) -> Ordering {
|
||||
*self
|
||||
@@ -2042,9 +2096,10 @@ mod impls {
|
||||
}
|
||||
}
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
impl<A: PointeeSized, B: PointeeSized> PartialOrd<&B> for &A
|
||||
#[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
|
||||
impl<A: PointeeSized, B: PointeeSized> const PartialOrd<&B> for &A
|
||||
where
|
||||
A: PartialOrd<B>,
|
||||
A: [const] PartialOrd<B>,
|
||||
{
|
||||
#[inline]
|
||||
fn partial_cmp(&self, other: &&B) -> Option<Ordering> {
|
||||
@@ -2084,9 +2139,10 @@ mod impls {
|
||||
}
|
||||
}
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
impl<A: PointeeSized> Ord for &A
|
||||
#[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
|
||||
impl<A: PointeeSized> const Ord for &A
|
||||
where
|
||||
A: Ord,
|
||||
A: [const] Ord,
|
||||
{
|
||||
#[inline]
|
||||
fn cmp(&self, other: &Self) -> Ordering {
|
||||
@@ -2094,7 +2150,8 @@ mod impls {
|
||||
}
|
||||
}
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
impl<A: PointeeSized> Eq for &A where A: Eq {}
|
||||
#[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
|
||||
impl<A: PointeeSized> const Eq for &A where A: [const] Eq {}
|
||||
|
||||
// &mut pointers
|
||||
|
||||
@@ -2114,9 +2171,10 @@ mod impls {
|
||||
}
|
||||
}
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
impl<A: PointeeSized, B: PointeeSized> PartialOrd<&mut B> for &mut A
|
||||
#[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
|
||||
impl<A: PointeeSized, B: PointeeSized> const PartialOrd<&mut B> for &mut A
|
||||
where
|
||||
A: PartialOrd<B>,
|
||||
A: [const] PartialOrd<B>,
|
||||
{
|
||||
#[inline]
|
||||
fn partial_cmp(&self, other: &&mut B) -> Option<Ordering> {
|
||||
@@ -2156,9 +2214,10 @@ mod impls {
|
||||
}
|
||||
}
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
impl<A: PointeeSized> Ord for &mut A
|
||||
#[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
|
||||
impl<A: PointeeSized> const Ord for &mut A
|
||||
where
|
||||
A: Ord,
|
||||
A: [const] Ord,
|
||||
{
|
||||
#[inline]
|
||||
fn cmp(&self, other: &Self) -> Ordering {
|
||||
@@ -2166,7 +2225,8 @@ mod impls {
|
||||
}
|
||||
}
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
impl<A: PointeeSized> Eq for &mut A where A: Eq {}
|
||||
#[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
|
||||
impl<A: PointeeSized> const Eq for &mut A where A: [const] Eq {}
|
||||
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
|
||||
|
||||
@@ -963,17 +963,20 @@ impl const PartialEq for Infallible {
|
||||
}
|
||||
|
||||
#[stable(feature = "convert_infallible", since = "1.34.0")]
|
||||
impl Eq for Infallible {}
|
||||
#[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
|
||||
impl const Eq for Infallible {}
|
||||
|
||||
#[stable(feature = "convert_infallible", since = "1.34.0")]
|
||||
impl PartialOrd for Infallible {
|
||||
#[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
|
||||
impl const PartialOrd for Infallible {
|
||||
fn partial_cmp(&self, _other: &Self) -> Option<crate::cmp::Ordering> {
|
||||
match *self {}
|
||||
}
|
||||
}
|
||||
|
||||
#[stable(feature = "convert_infallible", since = "1.34.0")]
|
||||
impl Ord for Infallible {
|
||||
#[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
|
||||
impl const Ord for Infallible {
|
||||
fn cmp(&self, _other: &Self) -> crate::cmp::Ordering {
|
||||
match *self {}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ use super::{IntErrorKind, ParseIntError};
|
||||
use crate::clone::UseCloned;
|
||||
use crate::cmp::Ordering;
|
||||
use crate::hash::{Hash, Hasher};
|
||||
use crate::marker::{Freeze, StructuralPartialEq};
|
||||
use crate::marker::{Destruct, Freeze, StructuralPartialEq};
|
||||
use crate::ops::{BitOr, BitOrAssign, Div, DivAssign, Neg, Rem, RemAssign};
|
||||
use crate::panic::{RefUnwindSafe, UnwindSafe};
|
||||
use crate::str::FromStr;
|
||||
@@ -220,12 +220,14 @@ where
|
||||
impl<T> StructuralPartialEq for NonZero<T> where T: ZeroablePrimitive + StructuralPartialEq {}
|
||||
|
||||
#[stable(feature = "nonzero", since = "1.28.0")]
|
||||
impl<T> Eq for NonZero<T> where T: ZeroablePrimitive + Eq {}
|
||||
#[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
|
||||
impl<T> const Eq for NonZero<T> where T: ZeroablePrimitive + [const] Eq {}
|
||||
|
||||
#[stable(feature = "nonzero", since = "1.28.0")]
|
||||
impl<T> PartialOrd for NonZero<T>
|
||||
#[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
|
||||
impl<T> const PartialOrd for NonZero<T>
|
||||
where
|
||||
T: ZeroablePrimitive + PartialOrd,
|
||||
T: ZeroablePrimitive + [const] PartialOrd,
|
||||
{
|
||||
#[inline]
|
||||
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
|
||||
@@ -254,9 +256,12 @@ where
|
||||
}
|
||||
|
||||
#[stable(feature = "nonzero", since = "1.28.0")]
|
||||
impl<T> Ord for NonZero<T>
|
||||
#[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
|
||||
impl<T> const Ord for NonZero<T>
|
||||
where
|
||||
T: ZeroablePrimitive + Ord,
|
||||
// FIXME(const_hack): the T: ~const Destruct should be inferred from the Self: ~const Destruct.
|
||||
// See https://github.com/rust-lang/rust/issues/144207
|
||||
T: ZeroablePrimitive + [const] Ord + [const] Destruct,
|
||||
{
|
||||
#[inline]
|
||||
fn cmp(&self, other: &Self) -> Ordering {
|
||||
|
||||
@@ -83,7 +83,8 @@ use crate::{convert, ops};
|
||||
#[must_use]
|
||||
// ControlFlow should not implement PartialOrd or Ord, per RFC 3058:
|
||||
// https://rust-lang.github.io/rfcs/3058-try-trait-v2.html#traits-for-controlflow
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||
#[derive(Copy, Debug, Hash)]
|
||||
#[derive_const(Clone, PartialEq, Eq)]
|
||||
pub enum ControlFlow<B, C = ()> {
|
||||
/// Move on to the next phase of the operation as normal.
|
||||
#[stable(feature = "control_flow_enum_type", since = "1.55.0")]
|
||||
|
||||
@@ -585,7 +585,8 @@ use crate::{cmp, convert, hint, mem, slice};
|
||||
|
||||
/// The `Option` type. See [the module level documentation](self) for more.
|
||||
#[doc(search_unbox)]
|
||||
#[derive(Copy, Eq, Debug, Hash)]
|
||||
#[derive(Copy, Debug, Hash)]
|
||||
#[derive_const(Eq)]
|
||||
#[rustc_diagnostic_item = "Option"]
|
||||
#[lang = "Option"]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
@@ -2363,7 +2364,8 @@ impl<T: [const] PartialEq> const PartialEq for Option<T> {
|
||||
// https://github.com/rust-lang/rust/issues/49892, although still
|
||||
// not optimal.
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
impl<T: PartialOrd> PartialOrd for Option<T> {
|
||||
#[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
|
||||
impl<T: [const] PartialOrd> const PartialOrd for Option<T> {
|
||||
#[inline]
|
||||
fn partial_cmp(&self, other: &Self) -> Option<cmp::Ordering> {
|
||||
match (self, other) {
|
||||
@@ -2376,7 +2378,8 @@ impl<T: PartialOrd> PartialOrd for Option<T> {
|
||||
}
|
||||
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
impl<T: Ord> Ord for Option<T> {
|
||||
#[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
|
||||
impl<T: [const] Ord> const Ord for Option<T> {
|
||||
#[inline]
|
||||
fn cmp(&self, other: &Self) -> cmp::Ordering {
|
||||
match (self, other) {
|
||||
|
||||
@@ -49,7 +49,8 @@ pub use crate::ops::{Bound, IntoBounds, OneSidedRange, RangeBounds, RangeFull, R
|
||||
/// assert_eq!(3 + 4 + 5, Range::from(3..6).into_iter().sum());
|
||||
/// ```
|
||||
#[lang = "RangeCopy"]
|
||||
#[derive(Clone, Copy, Default, PartialEq, Eq, Hash)]
|
||||
#[derive(Copy, Hash)]
|
||||
#[derive_const(Clone, Default, PartialEq, Eq)]
|
||||
#[unstable(feature = "new_range_api", issue = "125687")]
|
||||
pub struct Range<Idx> {
|
||||
/// The lower bound of the range (inclusive).
|
||||
@@ -424,7 +425,8 @@ impl<T> const From<legacy::RangeInclusive<T>> for RangeInclusive<T> {
|
||||
/// assert_eq!(2 + 3 + 4, RangeFrom::from(2..).into_iter().take(3).sum());
|
||||
/// ```
|
||||
#[lang = "RangeFromCopy"]
|
||||
#[derive(Clone, Copy, PartialEq, Eq, Hash)]
|
||||
#[derive(Copy, Hash)]
|
||||
#[derive_const(Clone, PartialEq, Eq)]
|
||||
#[unstable(feature = "new_range_api", issue = "125687")]
|
||||
pub struct RangeFrom<Idx> {
|
||||
/// The lower bound of the range (inclusive).
|
||||
|
||||
@@ -542,7 +542,8 @@ use crate::{convert, fmt, hint};
|
||||
///
|
||||
/// See the [module documentation](self) for details.
|
||||
#[doc(search_unbox)]
|
||||
#[derive(Copy, PartialEq, PartialOrd, Eq, Ord, Debug, Hash)]
|
||||
#[derive(Copy, Debug, Hash)]
|
||||
#[derive_const(PartialEq, PartialOrd, Eq, Ord)]
|
||||
#[must_use = "this `Result` may be an `Err` variant, which should be handled"]
|
||||
#[rustc_diagnostic_item = "Result"]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
|
||||
@@ -23,7 +23,8 @@ where
|
||||
}
|
||||
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
impl<T: Eq> Eq for [T] {}
|
||||
#[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
|
||||
impl<T: [const] Eq> const Eq for [T] {}
|
||||
|
||||
/// Implements comparison of slices [lexicographically](Ord#lexicographical-comparison).
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
@@ -34,7 +35,7 @@ impl<T: Ord> Ord for [T] {
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn as_underlying(x: ControlFlow<bool>) -> u8 {
|
||||
const fn as_underlying(x: ControlFlow<bool>) -> u8 {
|
||||
// SAFETY: This will only compile if `bool` and `ControlFlow<bool>` have the same
|
||||
// size (which isn't guaranteed but this is libcore). Because they have the same
|
||||
// size, it's a niched implementation, which in one byte means there can't be
|
||||
@@ -154,12 +155,16 @@ where
|
||||
}
|
||||
|
||||
#[doc(hidden)]
|
||||
#[const_trait]
|
||||
#[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
|
||||
// intermediate trait for specialization of slice's PartialOrd
|
||||
trait SlicePartialOrd: Sized {
|
||||
fn partial_compare(left: &[Self], right: &[Self]) -> Option<Ordering>;
|
||||
}
|
||||
|
||||
#[doc(hidden)]
|
||||
#[const_trait]
|
||||
#[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
|
||||
// intermediate trait for specialization of slice's PartialOrd chaining methods
|
||||
trait SliceChain: Sized {
|
||||
fn chaining_lt(left: &[Self], right: &[Self]) -> ControlFlow<bool>;
|
||||
@@ -231,14 +236,17 @@ where
|
||||
}
|
||||
*/
|
||||
|
||||
impl<A: AlwaysApplicableOrd> SlicePartialOrd for A {
|
||||
#[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
|
||||
impl<A: [const] AlwaysApplicableOrd> const SlicePartialOrd for A {
|
||||
fn partial_compare(left: &[A], right: &[A]) -> Option<Ordering> {
|
||||
Some(SliceOrd::compare(left, right))
|
||||
}
|
||||
}
|
||||
|
||||
#[rustc_specialization_trait]
|
||||
trait AlwaysApplicableOrd: SliceOrd + Ord {}
|
||||
#[const_trait]
|
||||
#[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
|
||||
trait AlwaysApplicableOrd: [const] SliceOrd + [const] Ord {}
|
||||
|
||||
macro_rules! always_applicable_ord {
|
||||
($([$($p:tt)*] $t:ty,)*) => {
|
||||
@@ -257,6 +265,8 @@ always_applicable_ord! {
|
||||
}
|
||||
|
||||
#[doc(hidden)]
|
||||
#[const_trait]
|
||||
#[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
|
||||
// intermediate trait for specialization of slice's Ord
|
||||
trait SliceOrd: Sized {
|
||||
fn compare(left: &[Self], right: &[Self]) -> Ordering;
|
||||
@@ -282,17 +292,24 @@ impl<A: Ord> SliceOrd for A {
|
||||
/// * For every `x` and `y` of this type, `Ord(x, y)` must return the same
|
||||
/// value as `Ord::cmp(transmute::<_, u8>(x), transmute::<_, u8>(y))`.
|
||||
#[rustc_specialization_trait]
|
||||
unsafe trait UnsignedBytewiseOrd: Ord {}
|
||||
#[const_trait]
|
||||
unsafe trait UnsignedBytewiseOrd: [const] Ord {}
|
||||
|
||||
unsafe impl UnsignedBytewiseOrd for bool {}
|
||||
unsafe impl UnsignedBytewiseOrd for u8 {}
|
||||
unsafe impl UnsignedBytewiseOrd for NonZero<u8> {}
|
||||
unsafe impl UnsignedBytewiseOrd for Option<NonZero<u8>> {}
|
||||
unsafe impl UnsignedBytewiseOrd for ascii::Char {}
|
||||
#[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
|
||||
unsafe impl const UnsignedBytewiseOrd for bool {}
|
||||
#[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
|
||||
unsafe impl const UnsignedBytewiseOrd for u8 {}
|
||||
#[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
|
||||
unsafe impl const UnsignedBytewiseOrd for NonZero<u8> {}
|
||||
#[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
|
||||
unsafe impl const UnsignedBytewiseOrd for Option<NonZero<u8>> {}
|
||||
#[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
|
||||
unsafe impl const UnsignedBytewiseOrd for ascii::Char {}
|
||||
|
||||
// `compare_bytes` compares a sequence of unsigned bytes lexicographically, so
|
||||
// use it if the requirements for `UnsignedBytewiseOrd` are fulfilled.
|
||||
impl<A: Ord + UnsignedBytewiseOrd> SliceOrd for A {
|
||||
#[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
|
||||
impl<A: [const] Ord + [const] UnsignedBytewiseOrd> const SliceOrd for A {
|
||||
#[inline]
|
||||
fn compare(left: &[Self], right: &[Self]) -> Ordering {
|
||||
// Since the length of a slice is always less than or equal to
|
||||
@@ -317,7 +334,9 @@ impl<A: Ord + UnsignedBytewiseOrd> SliceOrd for A {
|
||||
}
|
||||
|
||||
// Don't generate our own chaining loops for `memcmp`-able things either.
|
||||
impl<A: PartialOrd + UnsignedBytewiseOrd> SliceChain for A {
|
||||
|
||||
#[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
|
||||
impl<A: [const] PartialOrd + [const] UnsignedBytewiseOrd> const SliceChain for A {
|
||||
#[inline]
|
||||
fn chaining_lt(left: &[Self], right: &[Self]) -> ControlFlow<bool> {
|
||||
match SliceOrd::compare(left, right) {
|
||||
|
||||
@@ -32,7 +32,8 @@ impl const PartialEq for str {
|
||||
}
|
||||
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
impl Eq for str {}
|
||||
#[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
|
||||
impl const Eq for str {}
|
||||
|
||||
/// Implements comparison operations on strings.
|
||||
///
|
||||
|
||||
@@ -23,7 +23,8 @@ macro_rules! tuple_impls {
|
||||
maybe_tuple_doc! {
|
||||
$($T)+ @
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
impl<$($T: PartialEq),+> PartialEq for ($($T,)+) {
|
||||
#[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
|
||||
impl<$($T: [const] PartialEq),+> const PartialEq for ($($T,)+) {
|
||||
#[inline]
|
||||
fn eq(&self, other: &($($T,)+)) -> bool {
|
||||
$( ${ignore($T)} self.${index()} == other.${index()} )&&+
|
||||
@@ -38,7 +39,8 @@ macro_rules! tuple_impls {
|
||||
maybe_tuple_doc! {
|
||||
$($T)+ @
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
impl<$($T: Eq),+> Eq for ($($T,)+)
|
||||
#[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
|
||||
impl<$($T: [const] Eq),+> const Eq for ($($T,)+)
|
||||
{}
|
||||
}
|
||||
|
||||
@@ -66,7 +68,8 @@ macro_rules! tuple_impls {
|
||||
maybe_tuple_doc! {
|
||||
$($T)+ @
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
impl<$($T: PartialOrd),+> PartialOrd for ($($T,)+)
|
||||
#[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
|
||||
impl<$($T: [const] PartialOrd),+> const PartialOrd for ($($T,)+)
|
||||
{
|
||||
#[inline]
|
||||
fn partial_cmp(&self, other: &($($T,)+)) -> Option<Ordering> {
|
||||
@@ -110,7 +113,8 @@ macro_rules! tuple_impls {
|
||||
maybe_tuple_doc! {
|
||||
$($T)+ @
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
impl<$($T: Ord),+> Ord for ($($T,)+)
|
||||
#[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
|
||||
impl<$($T: [const] Ord),+> const Ord for ($($T,)+)
|
||||
{
|
||||
#[inline]
|
||||
fn cmp(&self, other: &($($T,)+)) -> Ordering {
|
||||
|
||||
@@ -215,19 +215,18 @@ fn cmp_default() {
|
||||
assert_eq!(Fool(false), Fool(true));
|
||||
}
|
||||
|
||||
/* FIXME(#110395)
|
||||
mod const_cmp {
|
||||
use super::*;
|
||||
|
||||
struct S(i32);
|
||||
|
||||
impl PartialEq for S {
|
||||
impl const PartialEq for S {
|
||||
fn eq(&self, other: &Self) -> bool {
|
||||
self.0 == other.0
|
||||
}
|
||||
}
|
||||
|
||||
impl PartialOrd for S {
|
||||
impl const PartialOrd for S {
|
||||
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
|
||||
let ret = match (self.0, other.0) {
|
||||
(a, b) if a > b => Ordering::Greater,
|
||||
@@ -247,4 +246,3 @@ mod const_cmp {
|
||||
const _: () = assert!(S(0) < S(1));
|
||||
const _: () = assert!(S(1) > S(0));
|
||||
}
|
||||
*/
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
#![feature(cfg_target_has_reliable_f16_f128)]
|
||||
#![feature(char_max_len)]
|
||||
#![feature(clone_to_uninit)]
|
||||
#![feature(const_cmp)]
|
||||
#![feature(const_convert)]
|
||||
#![feature(const_destruct)]
|
||||
#![feature(const_eval_select)]
|
||||
|
||||
@@ -9,8 +9,7 @@ fn main() {
|
||||
assert!(TypeId::of::<u8>() == TypeId::of::<u8>());
|
||||
assert!(TypeId::of::<()>() != TypeId::of::<u8>());
|
||||
let _a = TypeId::of::<u8>() < TypeId::of::<u16>();
|
||||
//~^ ERROR: cannot call non-const operator in constants
|
||||
// can't assert `_a` because it is not deterministic
|
||||
// FIXME(const_trait_impl) make it pass
|
||||
//~^ ERROR: the trait bound `TypeId: const PartialOrd` is not satisfied
|
||||
// FIXME(const_trait_impl) make it pass; requires const comparison of pointers (#53020)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +1,9 @@
|
||||
error[E0015]: cannot call non-const operator in constants
|
||||
error[E0277]: the trait bound `TypeId: const PartialOrd` is not satisfied
|
||||
--> $DIR/const_cmp_type_id.rs:11:18
|
||||
|
|
||||
LL | let _a = TypeId::of::<u8>() < TypeId::of::<u16>();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
note: impl defined here, but it is not `const`
|
||||
--> $SRC_DIR/core/src/any.rs:LL:COL
|
||||
= note: calls in constants are limited to constant functions, tuple structs and tuple variants
|
||||
|
||||
error: aborting due to 1 previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0015`.
|
||||
For more information about this error, try `rustc --explain E0277`.
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
//@ known-bug: #110395
|
||||
//@ check-pass
|
||||
|
||||
#![feature(const_fn_trait_ref_impls)]
|
||||
#![feature(fn_traits)]
|
||||
#![feature(unboxed_closures)]
|
||||
#![feature(const_trait_impl)]
|
||||
|
||||
@@ -1,22 +0,0 @@
|
||||
error[E0635]: unknown feature `const_fn_trait_ref_impls`
|
||||
--> $DIR/fn_trait_refs.rs:3:12
|
||||
|
|
||||
LL | #![feature(const_fn_trait_ref_impls)]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error[E0277]: the trait bound `(i32, i32, i32): const PartialEq` is not satisfied
|
||||
--> $DIR/fn_trait_refs.rs:71:17
|
||||
|
|
||||
LL | assert!(test_one == (1, 1, 1));
|
||||
| ^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error[E0277]: the trait bound `(i32, i32): const PartialEq` is not satisfied
|
||||
--> $DIR/fn_trait_refs.rs:74:17
|
||||
|
|
||||
LL | assert!(test_two == (2, 2));
|
||||
| ^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: aborting due to 3 previous errors
|
||||
|
||||
Some errors have detailed explanations: E0277, E0635.
|
||||
For more information about an error, try `rustc --explain E0277`.
|
||||
@@ -1,7 +1,5 @@
|
||||
//@ check-pass
|
||||
//@ compile-flags: -Znext-solver
|
||||
//@ known-bug: #110395
|
||||
|
||||
// Broken until `(): const PartialEq`
|
||||
|
||||
#![allow(incomplete_features)]
|
||||
#![feature(const_trait_impl, const_cmp, const_destruct)]
|
||||
|
||||
@@ -1,17 +0,0 @@
|
||||
error[E0277]: the trait bound `(): const PartialEq` is not satisfied
|
||||
--> $DIR/const-impl-trait.rs:34:17
|
||||
|
|
||||
LL | assert!(cmp(&()));
|
||||
| --- ^^^
|
||||
| |
|
||||
| required by a bound introduced by this call
|
||||
|
|
||||
note: required by a bound in `cmp`
|
||||
--> $DIR/const-impl-trait.rs:11:23
|
||||
|
|
||||
LL | const fn cmp(a: &impl [const] PartialEq) -> bool {
|
||||
| ^^^^^^^^^^^^^^^^^ required by this bound in `cmp`
|
||||
|
||||
error: aborting due to 1 previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0277`.
|
||||
@@ -1,5 +1,4 @@
|
||||
//@ known-bug: #110395
|
||||
|
||||
//@ check-pass
|
||||
#![feature(const_trait_impl, const_default, const_cmp, derive_const)]
|
||||
|
||||
pub struct A;
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
error[E0277]: the trait bound `(): [const] PartialEq` is not satisfied
|
||||
--> $DIR/derive-const-use.rs:16:14
|
||||
|
|
||||
LL | #[derive_const(Default, PartialEq)]
|
||||
| --------- in this derive macro expansion
|
||||
LL | pub struct S((), A);
|
||||
| ^^
|
||||
|
||||
error: aborting due to 1 previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0277`.
|
||||
Reference in New Issue
Block a user