]> git.lizzy.rs Git - rust.git/blobdiff - library/core/src/cmp.rs
Copy an example to PartialOrd as well
[rust.git] / library / core / src / cmp.rs
index 7456f886ea5d8c41555b83d52afdf5fa141bfff1..ef81e8736ed4745f661c5bc560ca9c58a3569152 100644 (file)
@@ -215,6 +215,7 @@ pub trait PartialEq<Rhs: ?Sized = Self> {
     #[inline]
     #[must_use]
     #[stable(feature = "rust1", since = "1.0.0")]
+    #[default_method_body_is_const]
     fn ne(&self, other: &Rhs) -> bool {
         !self.eq(other)
     }
@@ -667,7 +668,7 @@ fn clone_from(&mut self, other: &Self) {
 /// Here's an example:
 ///
 /// ```
-/// #[derive(PartialEq, PartialOrd)]
+/// #[derive(PartialEq, Eq, PartialOrd, Ord)]
 /// enum Size {
 ///     Small,
 ///     Large,
@@ -897,6 +898,18 @@ fn partial_cmp(&self, other: &Ordering) -> Option<Ordering> {
 /// This trait can be used with `#[derive]`. When `derive`d on structs, it will produce a
 /// lexicographic ordering based on the top-to-bottom declaration order of the struct's members.
 /// When `derive`d on enums, variants are ordered by their top-to-bottom discriminant order.
+/// This means variants at the top are less than variants at the bottom.
+/// Here's an example:
+///
+/// ```
+/// #[derive(PartialEq, PartialOrd)]
+/// enum Size {
+///     Small,
+///     Large,
+/// }
+///
+/// assert!(Size::Small < Size::Large);
+/// ```
 ///
 /// ## How can I implement `PartialOrd`?
 ///
@@ -969,8 +982,8 @@ fn partial_cmp(&self, other: &Ordering) -> Option<Ordering> {
 /// # Examples
 ///
 /// ```
-/// let x : u32 = 0;
-/// let y : u32 = 1;
+/// let x: u32 = 0;
+/// let y: u32 = 1;
 ///
 /// assert_eq!(x < y, true);
 /// assert_eq!(x.lt(&y), true);
@@ -1031,6 +1044,7 @@ pub trait PartialOrd<Rhs: ?Sized = Self>: PartialEq<Rhs> {
     #[inline]
     #[must_use]
     #[stable(feature = "rust1", since = "1.0.0")]
+    #[default_method_body_is_const]
     fn lt(&self, other: &Rhs) -> bool {
         matches!(self.partial_cmp(other), Some(Less))
     }
@@ -1050,6 +1064,7 @@ fn lt(&self, other: &Rhs) -> bool {
     #[inline]
     #[must_use]
     #[stable(feature = "rust1", since = "1.0.0")]
+    #[default_method_body_is_const]
     fn le(&self, other: &Rhs) -> bool {
         // Pattern `Some(Less | Eq)` optimizes worse than negating `None | Some(Greater)`.
         // FIXME: The root cause was fixed upstream in LLVM with:
@@ -1072,6 +1087,7 @@ fn le(&self, other: &Rhs) -> bool {
     #[inline]
     #[must_use]
     #[stable(feature = "rust1", since = "1.0.0")]
+    #[default_method_body_is_const]
     fn gt(&self, other: &Rhs) -> bool {
         matches!(self.partial_cmp(other), Some(Greater))
     }
@@ -1091,6 +1107,7 @@ fn gt(&self, other: &Rhs) -> bool {
     #[inline]
     #[must_use]
     #[stable(feature = "rust1", since = "1.0.0")]
+    #[default_method_body_is_const]
     fn ge(&self, other: &Rhs) -> bool {
         matches!(self.partial_cmp(other), Some(Greater | Equal))
     }