Mark defaulted PartialEq/PartialOrd methods as const

This commit is contained in:
Dylan MacKenzie 2021-11-29 19:06:44 -08:00
parent 9b45f04414
commit 9c83b56056

View file

@ -215,6 +215,7 @@ pub trait PartialEq<Rhs: ?Sized = Self> {
#[inline] #[inline]
#[must_use] #[must_use]
#[stable(feature = "rust1", since = "1.0.0")] #[stable(feature = "rust1", since = "1.0.0")]
#[default_method_body_is_const]
fn ne(&self, other: &Rhs) -> bool { fn ne(&self, other: &Rhs) -> bool {
!self.eq(other) !self.eq(other)
} }
@ -1031,6 +1032,7 @@ pub trait PartialOrd<Rhs: ?Sized = Self>: PartialEq<Rhs> {
#[inline] #[inline]
#[must_use] #[must_use]
#[stable(feature = "rust1", since = "1.0.0")] #[stable(feature = "rust1", since = "1.0.0")]
#[default_method_body_is_const]
fn lt(&self, other: &Rhs) -> bool { fn lt(&self, other: &Rhs) -> bool {
matches!(self.partial_cmp(other), Some(Less)) matches!(self.partial_cmp(other), Some(Less))
} }
@ -1050,6 +1052,7 @@ pub trait PartialOrd<Rhs: ?Sized = Self>: PartialEq<Rhs> {
#[inline] #[inline]
#[must_use] #[must_use]
#[stable(feature = "rust1", since = "1.0.0")] #[stable(feature = "rust1", since = "1.0.0")]
#[default_method_body_is_const]
fn le(&self, other: &Rhs) -> bool { fn le(&self, other: &Rhs) -> bool {
// Pattern `Some(Less | Eq)` optimizes worse than negating `None | Some(Greater)`. // Pattern `Some(Less | Eq)` optimizes worse than negating `None | Some(Greater)`.
// FIXME: The root cause was fixed upstream in LLVM with: // FIXME: The root cause was fixed upstream in LLVM with:
@ -1072,6 +1075,7 @@ pub trait PartialOrd<Rhs: ?Sized = Self>: PartialEq<Rhs> {
#[inline] #[inline]
#[must_use] #[must_use]
#[stable(feature = "rust1", since = "1.0.0")] #[stable(feature = "rust1", since = "1.0.0")]
#[default_method_body_is_const]
fn gt(&self, other: &Rhs) -> bool { fn gt(&self, other: &Rhs) -> bool {
matches!(self.partial_cmp(other), Some(Greater)) matches!(self.partial_cmp(other), Some(Greater))
} }
@ -1091,6 +1095,7 @@ pub trait PartialOrd<Rhs: ?Sized = Self>: PartialEq<Rhs> {
#[inline] #[inline]
#[must_use] #[must_use]
#[stable(feature = "rust1", since = "1.0.0")] #[stable(feature = "rust1", since = "1.0.0")]
#[default_method_body_is_const]
fn ge(&self, other: &Rhs) -> bool { fn ge(&self, other: &Rhs) -> bool {
matches!(self.partial_cmp(other), Some(Greater | Equal)) matches!(self.partial_cmp(other), Some(Greater | Equal))
} }