summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEmilio Cobos Álvarez <emilio@crisal.io>2019-09-23 17:54:37 +0200
committerEmilio Cobos Álvarez <emilio@crisal.io>2019-09-23 18:33:43 +0200
commit9696bc1795c75b1b527e2b70d9baf3ced9e3c154 (patch)
treee886c1eefa6c1346e5422f6339733e5071a58653
parent8fd16b92320a49b5164793d5ce3693e859139cb7 (diff)
ir: Make Ord and PartialOrd implementations agree.
See https://github.com/rust-lang/rust/issues/64710. Bogus implementations were introduced in 230545e7c, d3e39dc62, and 379bb1663.
-rw-r--r--src/ir/analysis/has_vtable.rs27
-rw-r--r--src/ir/analysis/sizedness.rs39
-rw-r--r--src/ir/derive.rs26
3 files changed, 23 insertions, 69 deletions
diff --git a/src/ir/analysis/has_vtable.rs b/src/ir/analysis/has_vtable.rs
index 40b99792..026eedd0 100644
--- a/src/ir/analysis/has_vtable.rs
+++ b/src/ir/analysis/has_vtable.rs
@@ -9,17 +9,17 @@ use std::ops;
use {Entry, HashMap};
/// The result of the `HasVtableAnalysis` for an individual item.
-#[derive(Copy, Clone, Debug, PartialEq, Eq, Ord)]
+#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord)]
pub enum HasVtableResult {
- /// The item has a vtable, but the actual vtable pointer is in a base
- /// member.
- BaseHasVtable,
+ /// The item does not have a vtable pointer.
+ No,
/// The item has a vtable and the actual vtable pointer is within this item.
SelfHasVtable,
- /// The item does not have a vtable pointer.
- No,
+ /// The item has a vtable, but the actual vtable pointer is in a base
+ /// member.
+ BaseHasVtable,
}
impl Default for HasVtableResult {
@@ -28,21 +28,6 @@ impl Default for HasVtableResult {
}
}
-impl cmp::PartialOrd for HasVtableResult {
- fn partial_cmp(&self, rhs: &Self) -> Option<cmp::Ordering> {
- use self::HasVtableResult::*;
-
- match (*self, *rhs) {
- (x, y) if x == y => Some(cmp::Ordering::Equal),
- (BaseHasVtable, _) => Some(cmp::Ordering::Greater),
- (_, BaseHasVtable) => Some(cmp::Ordering::Less),
- (SelfHasVtable, _) => Some(cmp::Ordering::Greater),
- (_, SelfHasVtable) => Some(cmp::Ordering::Less),
- _ => unreachable!(),
- }
- }
-}
-
impl HasVtableResult {
/// Take the least upper bound of `self` and `rhs`.
pub fn join(self, rhs: Self) -> Self {
diff --git a/src/ir/analysis/sizedness.rs b/src/ir/analysis/sizedness.rs
index 92a47ea8..1c9171bd 100644
--- a/src/ir/analysis/sizedness.rs
+++ b/src/ir/analysis/sizedness.rs
@@ -24,13 +24,14 @@ use {Entry, HashMap};
///
/// We initially assume that all types are `ZeroSized` and then update our
/// understanding as we learn more about each type.
-#[derive(Copy, Clone, Debug, PartialEq, Eq, Ord)]
+#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord)]
pub enum SizednessResult {
- /// Has some size that is known to be greater than zero. That doesn't mean
- /// it has a static size, but it is not zero sized for sure. In other words,
- /// it might contain an incomplete array or some other dynamically sized
- /// type.
- NonZeroSized,
+ /// The type is zero-sized.
+ ///
+ /// This means that if it is a C++ type, and is not being used as a base
+ /// member, then we must add an `_address` byte to enforce the
+ /// unique-address-per-distinct-object-instance rule.
+ ZeroSized,
/// Whether this type is zero-sized or not depends on whether a type
/// parameter is zero-sized or not.
@@ -54,12 +55,11 @@ pub enum SizednessResult {
/// https://github.com/rust-lang/rust-bindgen/issues/586
DependsOnTypeParam,
- /// The type is zero-sized.
- ///
- /// This means that if it is a C++ type, and is not being used as a base
- /// member, then we must add an `_address` byte to enforce the
- /// unique-address-per-distinct-object-instance rule.
- ZeroSized,
+ /// Has some size that is known to be greater than zero. That doesn't mean
+ /// it has a static size, but it is not zero sized for sure. In other words,
+ /// it might contain an incomplete array or some other dynamically sized
+ /// type.
+ NonZeroSized,
}
impl Default for SizednessResult {
@@ -68,21 +68,6 @@ impl Default for SizednessResult {
}
}
-impl cmp::PartialOrd for SizednessResult {
- fn partial_cmp(&self, rhs: &Self) -> Option<cmp::Ordering> {
- use self::SizednessResult::*;
-
- match (*self, *rhs) {
- (x, y) if x == y => Some(cmp::Ordering::Equal),
- (NonZeroSized, _) => Some(cmp::Ordering::Greater),
- (_, NonZeroSized) => Some(cmp::Ordering::Less),
- (DependsOnTypeParam, _) => Some(cmp::Ordering::Greater),
- (_, DependsOnTypeParam) => Some(cmp::Ordering::Less),
- _ => unreachable!(),
- }
- }
-}
-
impl SizednessResult {
/// Take the least upper bound of `self` and `rhs`.
pub fn join(self, rhs: Self) -> Self {
diff --git a/src/ir/derive.rs b/src/ir/derive.rs
index 254072dd..594ce2ab 100644
--- a/src/ir/derive.rs
+++ b/src/ir/derive.rs
@@ -92,10 +92,10 @@ pub trait CanDeriveOrd {
///
/// Initially we assume that we can derive trait for all types and then
/// update our understanding as we learn more about each type.
-#[derive(Debug, Copy, Clone, PartialEq, Eq, Ord)]
+#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord)]
pub enum CanDerive {
- /// No, we cannot.
- No,
+ /// Yes, we can derive automatically.
+ Yes,
/// The only thing that stops us from automatically deriving is that
/// array with more than maximum number of elements is used.
@@ -103,8 +103,8 @@ pub enum CanDerive {
/// This means we probably can "manually" implement such trait.
Manually,
- /// Yes, we can derive automatically.
- Yes,
+ /// No, we cannot.
+ No,
}
impl Default for CanDerive {
@@ -113,22 +113,6 @@ impl Default for CanDerive {
}
}
-impl cmp::PartialOrd for CanDerive {
- fn partial_cmp(&self, rhs: &Self) -> Option<cmp::Ordering> {
- use self::CanDerive::*;
-
- let ordering = match (*self, *rhs) {
- (x, y) if x == y => cmp::Ordering::Equal,
- (No, _) => cmp::Ordering::Greater,
- (_, No) => cmp::Ordering::Less,
- (Manually, _) => cmp::Ordering::Greater,
- (_, Manually) => cmp::Ordering::Less,
- _ => unreachable!(),
- };
- Some(ordering)
- }
-}
-
impl CanDerive {
/// Take the least upper bound of `self` and `rhs`.
pub fn join(self, rhs: Self) -> Self {