diff --git a/library/core/src/marker.rs b/library/core/src/marker.rs index c0fb954ce2d9d..61b051cb07938 100644 --- a/library/core/src/marker.rs +++ b/library/core/src/marker.rs @@ -700,7 +700,17 @@ pub trait DiscriminantKind { /// The type of the discriminant, which must satisfy the trait /// bounds required by `mem::Discriminant`. #[lang = "discriminant_type"] - type Discriminant: Clone + Copy + Debug + Eq + PartialEq + Hash + Send + Sync + Unpin; + type Discriminant: Clone + + Copy + + Debug + + Eq + + Hash + + Ord + + PartialEq + + PartialOrd + + Send + + Sync + + Unpin; } /// Compiler-internal trait used to determine whether a type contains diff --git a/library/core/src/mem/mod.rs b/library/core/src/mem/mod.rs index 5e01ccc07d8fd..8a1b01b788242 100644 --- a/library/core/src/mem/mod.rs +++ b/library/core/src/mem/mod.rs @@ -1106,6 +1106,20 @@ impl fmt::Debug for Discriminant { } } +#[stable(feature = "discriminant_ord", since = "CURRENT_RUSTC_VERSION")] +impl cmp::PartialOrd for Discriminant { + fn partial_cmp(&self, other: &Self) -> Option { + self.0.partial_cmp(&other.0) + } +} + +#[stable(feature = "discriminant_ord", since = "CURRENT_RUSTC_VERSION")] +impl cmp::Ord for Discriminant { + fn cmp(&self, other: &Self) -> cmp::Ordering { + self.0.cmp(&other.0) + } +} + /// Returns a value uniquely identifying the enum variant in `v`. /// /// If `T` is not an enum, calling this function will not result in undefined behavior, but the @@ -1113,9 +1127,8 @@ impl fmt::Debug for Discriminant { /// /// # Stability /// -/// The discriminant of an enum variant may change if the enum definition changes. A discriminant -/// of some variant will not change between compilations with the same compiler. See the [Reference] -/// for more information. +/// `Discriminant` is an opaque wrapper around the enum discriminant, therefore its value will +/// change when the enum definition changes. See the [Reference] for more information. /// /// [Reference]: ../../reference/items/enumerations.html#custom-discriminant-values-for-fieldless-enumerations ///