-
Notifications
You must be signed in to change notification settings - Fork 12.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
implement Ord for OutlivesPredicate and other types #50930
Conversation
(rust_highfive has picked a reviewer for you, use r? to override) |
@eddyb isolated the |
I think you can simply add that commit to #50070? |
|
||
impl<'tcx> PartialOrd for TyS<'tcx> { | ||
fn partial_cmp(&self, other: &TyS<'tcx>) -> Option<Ordering> { | ||
Some(self.sty.cmp(&other.sty)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could be Some(self.cmp(other))
, to keep the implementation details in the Ord
impl.
fn partial_cmp(&self, other: &Slice<T>) -> Option<Ordering> { | ||
if self == other { Some(Ordering::Equal) } else { | ||
<[T] as PartialOrd>::partial_cmp(&self.0, &other.0) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here (Some(self.cmp(other))
).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some(self.cmp(other))
will require the bound T: Ord
, which I was not sure we wanted to impose for all types that that maybe only want to implement PartialOrd
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I somehow missed that this was generic - seems fine, then.
@@ -578,6 +590,22 @@ impl <'gcx: 'tcx, 'tcx> Canonicalize<'gcx, 'tcx> for Ty<'tcx> { | |||
#[derive(Debug, RustcEncodable)] | |||
pub struct Slice<T>([T]); | |||
|
|||
impl<T> Ord for Slice<T> where T: Ord { | |||
fn cmp(&self, other: &Slice<T>) -> Ordering { | |||
if self == other { Ordering::Equal } else { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice optimization!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
credit goes to @nikomatsakis
impl<'tcx> Ord for Kind<'tcx> { | ||
fn cmp(&self, other: &Kind) -> Ordering { | ||
match (self.unpack(), other.unpack()) { | ||
(UnpackedKind::Type(_), UnpackedKind::Lifetime(_)) => Ordering::Greater, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You don't need to implement all of this manually, just add #[derive(PartialEq, Eq, PartialOrd, Ord)]
on UnpackedKind
and implement this method going through that. That's how other traits are implemented on Kind
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems to be unresolved?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oops missed this one. Here is a pr for that #54074
@ishitatsuyuki A reason for extracting this into a separate PR was because the changes in this PR are isolated from #50070 and are useful on their own. Also this way others not familiar with #50070 can review these changes without prior context and hopefully its less messy and easier to understand :) |
c3c8049
to
fabe510
Compare
@nikomatsakis @eddyb rebased to master and should be ready for review |
@bors r+ |
📌 Commit fabe510 has been approved by |
☔ The latest upstream changes (presumably #50520) made this pull request unmergeable. Please resolve the merge conflicts. |
fabe510
to
6e3a2ed
Compare
@bors r+ |
📌 Commit 6e3a2ed has been approved by |
⌛ Testing commit 6e3a2ed7d3fd0173e507c3bf8f18bd416cdc640c with merge 4fc63c69d4512d3edc6b42624b34bba467b0ee29... |
💔 Test failed - status-travis |
The job Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
1 similar comment
The job Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
6e3a2ed
to
1a159f6
Compare
The job Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
1a159f6
to
9a8400c
Compare
@bors r+ |
📌 Commit 9a8400c has been approved by |
implement Ord for OutlivesPredicate and other types It became necessary while implementing #50070 to have `Ord` implemented for `OutlivesPredicate`. This PR implements `Ord` for `OutlivesPredicate` as well as other types needed for the implementation.
☀️ Test successful - status-appveyor, status-travis |
@@ -332,7 +332,7 @@ impl AddAssign for Size { | |||
/// Each field is a power of two, giving the alignment a maximum value | |||
/// of 2<sup>(2<sup>8</sup> - 1)</sup>, which is limited by LLVM to a | |||
/// maximum capacity of 2<sup>29</sup> or 536870912. | |||
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug, RustcEncodable, RustcDecodable)] | |||
#[derive(Copy, Clone, PartialEq, Eq, Ord, PartialOrd, Hash, Debug, RustcEncodable, RustcDecodable)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a mistake, because this type does not have a defined ordering (see the min
/max
methods).
I'll try to figure out if I can fix it locally (as part of a PR that would probably remove the need for using this type in most places, by replacing it with one alignment, instead of two).
simplify ordering for Kind Missed from rust-lang#50930 r? @eddyb
It became necessary while implementing #50070 to have
Ord
implemented forOutlivesPredicate
.This PR implements
Ord
forOutlivesPredicate
as well as other types needed for the implementation.