diff --git a/library/core/src/cmp.rs b/library/core/src/cmp.rs index 95896ab144187..051720a6c624d 100644 --- a/library/core/src/cmp.rs +++ b/library/core/src/cmp.rs @@ -1861,8 +1861,6 @@ mod impls { impl const PartialEq for $t { #[inline] fn eq(&self, other: &Self) -> bool { *self == *other } - #[inline] - fn ne(&self, other: &Self) -> bool { *self != *other } } )*) } @@ -1874,10 +1872,6 @@ mod impls { fn eq(&self, _other: &()) -> bool { true } - #[inline] - fn ne(&self, _other: &()) -> bool { - false - } } partial_eq_impl! { @@ -2075,185 +2069,101 @@ mod impls { } } - // & pointers + // reference types - #[stable(feature = "rust1", since = "1.0.0")] - #[rustc_const_unstable(feature = "const_cmp", issue = "143800")] - impl const PartialEq<&B> for &A - where - A: [const] PartialEq, - { - #[inline] - fn eq(&self, other: &&B) -> bool { - PartialEq::eq(*self, *other) - } - #[inline] - fn ne(&self, other: &&B) -> bool { - PartialEq::ne(*self, *other) - } - } - #[stable(feature = "rust1", since = "1.0.0")] - #[rustc_const_unstable(feature = "const_cmp", issue = "143800")] - impl const PartialOrd<&B> for &A - where - A: [const] PartialOrd, - { - #[inline] - fn partial_cmp(&self, other: &&B) -> Option { - PartialOrd::partial_cmp(*self, *other) - } - #[inline] - fn lt(&self, other: &&B) -> bool { - PartialOrd::lt(*self, *other) - } - #[inline] - fn le(&self, other: &&B) -> bool { - PartialOrd::le(*self, *other) - } - #[inline] - fn gt(&self, other: &&B) -> bool { - PartialOrd::gt(*self, *other) - } - #[inline] - fn ge(&self, other: &&B) -> bool { - PartialOrd::ge(*self, *other) - } - #[inline] - fn __chaining_lt(&self, other: &&B) -> ControlFlow { - PartialOrd::__chaining_lt(*self, *other) - } - #[inline] - fn __chaining_le(&self, other: &&B) -> ControlFlow { - PartialOrd::__chaining_le(*self, *other) - } - #[inline] - fn __chaining_gt(&self, other: &&B) -> ControlFlow { - PartialOrd::__chaining_gt(*self, *other) - } - #[inline] - fn __chaining_ge(&self, other: &&B) -> ControlFlow { - PartialOrd::__chaining_ge(*self, *other) - } - } - #[stable(feature = "rust1", since = "1.0.0")] - #[rustc_const_unstable(feature = "const_cmp", issue = "143800")] - impl const Ord for &A - where - A: [const] Ord, - { - #[inline] - fn cmp(&self, other: &Self) -> Ordering { - Ord::cmp(*self, *other) - } + macro_rules! impl_partial_eq { + (<$A:ident, $B:ident> for $(($ref_A:ty, $ref_B:ty))*) => ($( + #[stable(feature = "rust1", since = "1.0.0")] + #[rustc_const_unstable(feature = "const_cmp", issue = "143800")] + impl<$A, $B> const PartialEq<$ref_B> for $ref_A + where + $A: [const] PartialEq<$B> + PointeeSized, + $B: PointeeSized, + { + #[inline] + fn eq(&self, other: &$ref_B) -> bool { + PartialEq::eq(*self, *other) + } + // if >::ne uses inline assembly or FFI, then + // this forwarding impl may be more efficient than the default impl + #[inline] + fn ne(&self, other: &$ref_B) -> bool { + PartialEq::ne(*self, *other) + } + } + )*) } - #[stable(feature = "rust1", since = "1.0.0")] - #[rustc_const_unstable(feature = "const_cmp", issue = "143800")] - impl const Eq for &A where A: [const] Eq {} - // &mut pointers + impl_partial_eq!( for (&A, &B) (&A, &mut B) (&mut A, &B) (&mut A, &mut B)); - #[stable(feature = "rust1", since = "1.0.0")] - #[rustc_const_unstable(feature = "const_cmp", issue = "143800")] - impl const PartialEq<&mut B> for &mut A - where - A: [const] PartialEq, - { - #[inline] - fn eq(&self, other: &&mut B) -> bool { - PartialEq::eq(*self, *other) - } - #[inline] - fn ne(&self, other: &&mut B) -> bool { - PartialEq::ne(*self, *other) - } - } - #[stable(feature = "rust1", since = "1.0.0")] - #[rustc_const_unstable(feature = "const_cmp", issue = "143800")] - impl const PartialOrd<&mut B> for &mut A - where - A: [const] PartialOrd, - { - #[inline] - fn partial_cmp(&self, other: &&mut B) -> Option { - PartialOrd::partial_cmp(*self, *other) - } - #[inline] - fn lt(&self, other: &&mut B) -> bool { - PartialOrd::lt(*self, *other) - } - #[inline] - fn le(&self, other: &&mut B) -> bool { - PartialOrd::le(*self, *other) - } - #[inline] - fn gt(&self, other: &&mut B) -> bool { - PartialOrd::gt(*self, *other) - } - #[inline] - fn ge(&self, other: &&mut B) -> bool { - PartialOrd::ge(*self, *other) - } - #[inline] - fn __chaining_lt(&self, other: &&mut B) -> ControlFlow { - PartialOrd::__chaining_lt(*self, *other) - } - #[inline] - fn __chaining_le(&self, other: &&mut B) -> ControlFlow { - PartialOrd::__chaining_le(*self, *other) - } - #[inline] - fn __chaining_gt(&self, other: &&mut B) -> ControlFlow { - PartialOrd::__chaining_gt(*self, *other) - } - #[inline] - fn __chaining_ge(&self, other: &&mut B) -> ControlFlow { - PartialOrd::__chaining_ge(*self, *other) - } - } - #[stable(feature = "rust1", since = "1.0.0")] - #[rustc_const_unstable(feature = "const_cmp", issue = "143800")] - impl const Ord for &mut A - where - A: [const] Ord, - { - #[inline] - fn cmp(&self, other: &Self) -> Ordering { - Ord::cmp(*self, *other) - } + macro_rules! impl_partial_ord { + (<$A:ident, $B:ident> for $(($ref_A:ty, $ref_B:ty))*) => ($( + #[stable(feature = "rust1", since = "1.0.0")] + #[rustc_const_unstable(feature = "const_cmp", issue = "143800")] + impl<$A, $B> const PartialOrd<$ref_B> for $ref_A + where + $A: [const] PartialOrd<$B> + PointeeSized, + $B: PointeeSized, + { + #[inline] + fn partial_cmp(&self, other: &$ref_B) -> Option { + PartialOrd::partial_cmp(*self, *other) + } + #[inline] + fn lt(&self, other: &$ref_B) -> bool { + PartialOrd::lt(*self, *other) + } + #[inline] + fn le(&self, other: &$ref_B) -> bool { + PartialOrd::le(*self, *other) + } + #[inline] + fn gt(&self, other: &$ref_B) -> bool { + PartialOrd::gt(*self, *other) + } + #[inline] + fn ge(&self, other: &$ref_B) -> bool { + PartialOrd::ge(*self, *other) + } + #[inline] + fn __chaining_lt(&self, other: &$ref_B) -> ControlFlow { + PartialOrd::__chaining_lt(*self, *other) + } + #[inline] + fn __chaining_le(&self, other: &$ref_B) -> ControlFlow { + PartialOrd::__chaining_le(*self, *other) + } + #[inline] + fn __chaining_gt(&self, other: &$ref_B) -> ControlFlow { + PartialOrd::__chaining_gt(*self, *other) + } + #[inline] + fn __chaining_ge(&self, other: &$ref_B) -> ControlFlow { + PartialOrd::__chaining_ge(*self, *other) + } + } + )*) } - #[stable(feature = "rust1", since = "1.0.0")] - #[rustc_const_unstable(feature = "const_cmp", issue = "143800")] - impl const Eq for &mut A where A: [const] Eq {} - #[stable(feature = "rust1", since = "1.0.0")] - #[rustc_const_unstable(feature = "const_cmp", issue = "143800")] - impl const PartialEq<&mut B> for &A - where - A: [const] PartialEq, - { - #[inline] - fn eq(&self, other: &&mut B) -> bool { - PartialEq::eq(*self, *other) - } - #[inline] - fn ne(&self, other: &&mut B) -> bool { - PartialEq::ne(*self, *other) - } - } + impl_partial_ord!( for (&A, &B) /*(&A, &mut B) (&mut A, &B)*/ (&mut A, &mut B)); - #[stable(feature = "rust1", since = "1.0.0")] - #[rustc_const_unstable(feature = "const_cmp", issue = "143800")] - impl const PartialEq<&B> for &mut A - where - A: [const] PartialEq, - { - #[inline] - fn eq(&self, other: &&B) -> bool { - PartialEq::eq(*self, *other) - } - #[inline] - fn ne(&self, other: &&B) -> bool { - PartialEq::ne(*self, *other) - } + macro_rules! impl_ord_eq { + (<$A:ident> for $($ref_A:ty),*) => ($( + #[stable(feature = "rust1", since = "1.0.0")] + #[rustc_const_unstable(feature = "const_cmp", issue = "143800")] + impl<$A: [const] Ord + PointeeSized> const Ord for $ref_A + { + #[inline] + fn cmp(&self, other: &Self) -> Ordering { + Ord::cmp(*self, *other) + } + } + + #[stable(feature = "rust1", since = "1.0.0")] + #[rustc_const_unstable(feature = "const_cmp", issue = "143800")] + impl<$A: [const] Eq + PointeeSized> const Eq for $ref_A {} + )*) } + + impl_ord_eq!( for &A, &mut A); }