From 3237c316b546724b88f88445dd179ec1f2a80954 Mon Sep 17 00:00:00 2001 From: EFanZh Date: Wed, 4 Jan 2023 02:01:48 +0800 Subject: [PATCH 1/7] Implement `Ord` for `Discriminant` --- library/core/src/marker.rs | 12 +++++++++++- library/core/src/mem/mod.rs | 14 ++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) 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..95bdb5785fa53 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_value", since = "1.21.0")] +impl cmp::PartialOrd for Discriminant { + fn partial_cmp(&self, other: &Self) -> Option { + self.0.partial_cmp(&other.0) + } +} + +#[stable(feature = "discriminant_value", since = "1.21.0")] +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 From 2fd6091db8a84257c826e401db7d39c45f9fe529 Mon Sep 17 00:00:00 2001 From: EFanZh Date: Wed, 15 Nov 2023 19:59:52 +0800 Subject: [PATCH 2/7] Update library/core/src/mem/mod.rs Co-authored-by: daxpedda --- library/core/src/mem/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/core/src/mem/mod.rs b/library/core/src/mem/mod.rs index 95bdb5785fa53..cbe8c78378113 100644 --- a/library/core/src/mem/mod.rs +++ b/library/core/src/mem/mod.rs @@ -1106,7 +1106,7 @@ impl fmt::Debug for Discriminant { } } -#[stable(feature = "discriminant_value", since = "1.21.0")] +#[stable(feature = "discriminant_value", since = "CURRENT_RUSTC_VERSION")] impl cmp::PartialOrd for Discriminant { fn partial_cmp(&self, other: &Self) -> Option { self.0.partial_cmp(&other.0) From db4656f228eb96f06633d4b583dc078ba8035cc4 Mon Sep 17 00:00:00 2001 From: EFanZh Date: Wed, 15 Nov 2023 20:00:02 +0800 Subject: [PATCH 3/7] Update library/core/src/mem/mod.rs Co-authored-by: daxpedda --- library/core/src/mem/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/core/src/mem/mod.rs b/library/core/src/mem/mod.rs index cbe8c78378113..10f7e8256ad4a 100644 --- a/library/core/src/mem/mod.rs +++ b/library/core/src/mem/mod.rs @@ -1113,7 +1113,7 @@ impl cmp::PartialOrd for Discriminant { } } -#[stable(feature = "discriminant_value", since = "1.21.0")] +#[stable(feature = "discriminant_value", since = "CURRENT_RUSTC_VERSION")] impl cmp::Ord for Discriminant { fn cmp(&self, other: &Self) -> cmp::Ordering { self.0.cmp(&other.0) From 2ff6f209c1848d332f7d9906e04a9ff7938de961 Mon Sep 17 00:00:00 2001 From: daxpedda Date: Wed, 15 Nov 2023 13:15:45 +0100 Subject: [PATCH 4/7] Improve stability documentation --- library/core/src/mem/mod.rs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/library/core/src/mem/mod.rs b/library/core/src/mem/mod.rs index 10f7e8256ad4a..7fb7598e7a62b 100644 --- a/library/core/src/mem/mod.rs +++ b/library/core/src/mem/mod.rs @@ -1127,11 +1127,10 @@ impl cmp::Ord 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 it's 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 +/// [Reference]: ../../reference/items/enumerations.html#discriminants /// /// # Examples /// From dbc3154377240ed0e67b11d04bbe9db46fe8d3c6 Mon Sep 17 00:00:00 2001 From: EFanZh Date: Wed, 15 Nov 2023 20:30:48 +0800 Subject: [PATCH 5/7] Fix feature name --- library/core/src/mem/mod.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/library/core/src/mem/mod.rs b/library/core/src/mem/mod.rs index 7fb7598e7a62b..d05661189dcc3 100644 --- a/library/core/src/mem/mod.rs +++ b/library/core/src/mem/mod.rs @@ -1106,14 +1106,14 @@ impl fmt::Debug for Discriminant { } } -#[stable(feature = "discriminant_value", since = "CURRENT_RUSTC_VERSION")] +#[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_value", since = "CURRENT_RUSTC_VERSION")] +#[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) From 36ce983b8d9ae385bff4d265d5e6734c95fe13d3 Mon Sep 17 00:00:00 2001 From: EFanZh Date: Wed, 15 Nov 2023 08:53:48 -0800 Subject: [PATCH 6/7] Update library/core/src/mem/mod.rs Co-authored-by: daxpedda --- library/core/src/mem/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/core/src/mem/mod.rs b/library/core/src/mem/mod.rs index d05661189dcc3..01e8a82f5486f 100644 --- a/library/core/src/mem/mod.rs +++ b/library/core/src/mem/mod.rs @@ -1130,7 +1130,7 @@ impl cmp::Ord for Discriminant { /// `Discriminant` is an opaque wrapper around the enum discriminant, therefore it's value will /// change when the enum definition changes. See the [Reference] for more information. /// -/// [Reference]: ../../reference/items/enumerations.html#discriminants +/// [Reference]: ../../reference/items/enumerations.html#custom-discriminant-values-for-fieldless-enumerations /// /// # Examples /// From ec64db79ebd7f7b154340935f1ef9f8e9a6e9a40 Mon Sep 17 00:00:00 2001 From: EFanZh Date: Fri, 26 Jan 2024 14:07:51 +0800 Subject: [PATCH 7/7] Update library/core/src/mem/mod.rs Co-authored-by: David Tolnay --- library/core/src/mem/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/core/src/mem/mod.rs b/library/core/src/mem/mod.rs index 01e8a82f5486f..8a1b01b788242 100644 --- a/library/core/src/mem/mod.rs +++ b/library/core/src/mem/mod.rs @@ -1127,7 +1127,7 @@ impl cmp::Ord for Discriminant { /// /// # Stability /// -/// `Discriminant` is an opaque wrapper around the enum discriminant, therefore it's value will +/// `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