Skip to content

Commit 9696bc1

Browse files
committed
ir: Make Ord and PartialOrd implementations agree.
See rust-lang/rust#64710. Bogus implementations were introduced in 230545e, d3e39dc, and 379bb16.
1 parent 8fd16b9 commit 9696bc1

File tree

3 files changed

+23
-69
lines changed

3 files changed

+23
-69
lines changed

src/ir/analysis/has_vtable.rs

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,17 @@ use std::ops;
99
use {Entry, HashMap};
1010

1111
/// The result of the `HasVtableAnalysis` for an individual item.
12-
#[derive(Copy, Clone, Debug, PartialEq, Eq, Ord)]
12+
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord)]
1313
pub enum HasVtableResult {
14-
/// The item has a vtable, but the actual vtable pointer is in a base
15-
/// member.
16-
BaseHasVtable,
14+
/// The item does not have a vtable pointer.
15+
No,
1716

1817
/// The item has a vtable and the actual vtable pointer is within this item.
1918
SelfHasVtable,
2019

21-
/// The item does not have a vtable pointer.
22-
No,
20+
/// The item has a vtable, but the actual vtable pointer is in a base
21+
/// member.
22+
BaseHasVtable,
2323
}
2424

2525
impl Default for HasVtableResult {
@@ -28,21 +28,6 @@ impl Default for HasVtableResult {
2828
}
2929
}
3030

31-
impl cmp::PartialOrd for HasVtableResult {
32-
fn partial_cmp(&self, rhs: &Self) -> Option<cmp::Ordering> {
33-
use self::HasVtableResult::*;
34-
35-
match (*self, *rhs) {
36-
(x, y) if x == y => Some(cmp::Ordering::Equal),
37-
(BaseHasVtable, _) => Some(cmp::Ordering::Greater),
38-
(_, BaseHasVtable) => Some(cmp::Ordering::Less),
39-
(SelfHasVtable, _) => Some(cmp::Ordering::Greater),
40-
(_, SelfHasVtable) => Some(cmp::Ordering::Less),
41-
_ => unreachable!(),
42-
}
43-
}
44-
}
45-
4631
impl HasVtableResult {
4732
/// Take the least upper bound of `self` and `rhs`.
4833
pub fn join(self, rhs: Self) -> Self {

src/ir/analysis/sizedness.rs

Lines changed: 12 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,14 @@ use {Entry, HashMap};
2424
///
2525
/// We initially assume that all types are `ZeroSized` and then update our
2626
/// understanding as we learn more about each type.
27-
#[derive(Copy, Clone, Debug, PartialEq, Eq, Ord)]
27+
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord)]
2828
pub enum SizednessResult {
29-
/// Has some size that is known to be greater than zero. That doesn't mean
30-
/// it has a static size, but it is not zero sized for sure. In other words,
31-
/// it might contain an incomplete array or some other dynamically sized
32-
/// type.
33-
NonZeroSized,
29+
/// The type is zero-sized.
30+
///
31+
/// This means that if it is a C++ type, and is not being used as a base
32+
/// member, then we must add an `_address` byte to enforce the
33+
/// unique-address-per-distinct-object-instance rule.
34+
ZeroSized,
3435

3536
/// Whether this type is zero-sized or not depends on whether a type
3637
/// parameter is zero-sized or not.
@@ -54,12 +55,11 @@ pub enum SizednessResult {
5455
/// https://github.com/rust-lang/rust-bindgen/issues/586
5556
DependsOnTypeParam,
5657

57-
/// The type is zero-sized.
58-
///
59-
/// This means that if it is a C++ type, and is not being used as a base
60-
/// member, then we must add an `_address` byte to enforce the
61-
/// unique-address-per-distinct-object-instance rule.
62-
ZeroSized,
58+
/// Has some size that is known to be greater than zero. That doesn't mean
59+
/// it has a static size, but it is not zero sized for sure. In other words,
60+
/// it might contain an incomplete array or some other dynamically sized
61+
/// type.
62+
NonZeroSized,
6363
}
6464

6565
impl Default for SizednessResult {
@@ -68,21 +68,6 @@ impl Default for SizednessResult {
6868
}
6969
}
7070

71-
impl cmp::PartialOrd for SizednessResult {
72-
fn partial_cmp(&self, rhs: &Self) -> Option<cmp::Ordering> {
73-
use self::SizednessResult::*;
74-
75-
match (*self, *rhs) {
76-
(x, y) if x == y => Some(cmp::Ordering::Equal),
77-
(NonZeroSized, _) => Some(cmp::Ordering::Greater),
78-
(_, NonZeroSized) => Some(cmp::Ordering::Less),
79-
(DependsOnTypeParam, _) => Some(cmp::Ordering::Greater),
80-
(_, DependsOnTypeParam) => Some(cmp::Ordering::Less),
81-
_ => unreachable!(),
82-
}
83-
}
84-
}
85-
8671
impl SizednessResult {
8772
/// Take the least upper bound of `self` and `rhs`.
8873
pub fn join(self, rhs: Self) -> Self {

src/ir/derive.rs

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -92,19 +92,19 @@ pub trait CanDeriveOrd {
9292
///
9393
/// Initially we assume that we can derive trait for all types and then
9494
/// update our understanding as we learn more about each type.
95-
#[derive(Debug, Copy, Clone, PartialEq, Eq, Ord)]
95+
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord)]
9696
pub enum CanDerive {
97-
/// No, we cannot.
98-
No,
97+
/// Yes, we can derive automatically.
98+
Yes,
9999

100100
/// The only thing that stops us from automatically deriving is that
101101
/// array with more than maximum number of elements is used.
102102
///
103103
/// This means we probably can "manually" implement such trait.
104104
Manually,
105105

106-
/// Yes, we can derive automatically.
107-
Yes,
106+
/// No, we cannot.
107+
No,
108108
}
109109

110110
impl Default for CanDerive {
@@ -113,22 +113,6 @@ impl Default for CanDerive {
113113
}
114114
}
115115

116-
impl cmp::PartialOrd for CanDerive {
117-
fn partial_cmp(&self, rhs: &Self) -> Option<cmp::Ordering> {
118-
use self::CanDerive::*;
119-
120-
let ordering = match (*self, *rhs) {
121-
(x, y) if x == y => cmp::Ordering::Equal,
122-
(No, _) => cmp::Ordering::Greater,
123-
(_, No) => cmp::Ordering::Less,
124-
(Manually, _) => cmp::Ordering::Greater,
125-
(_, Manually) => cmp::Ordering::Less,
126-
_ => unreachable!(),
127-
};
128-
Some(ordering)
129-
}
130-
}
131-
132116
impl CanDerive {
133117
/// Take the least upper bound of `self` and `rhs`.
134118
pub fn join(self, rhs: Self) -> Self {

0 commit comments

Comments
 (0)