Explictly call Ord::cmp to compare priorities #85
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Following up discussion in #84
Previously we would call
PartialOrd::partial_cmpimplicilty using the overloaded comparison operators>and<when comparing priorities, despite the fact that P is required to beOrd. A well behaved implementation ofpartial_cmpis supposed to returnSome(Ord::cmp(self, other)). That relationship is only a convention, so a misbehaved implementation may return None, which may cause the order items are popped from the queue to behave seemingly randomly.We can be a bit more defensive here and instead always call
Ord::cmpdirectly, ensuring that we never try to compare things that could possibly returnNone. In order to enforce this going forward I added a test that panics in the implementation for partial_cmp and exercised all of the code paths that might call it. This isn't perfect, since new callsites could be added, but I figure its probably good enough for now.Not sure exactly how to version this, it's not a breaking change if your implementation of
PartialOrdfollows the convention, but if you don't it would be a breaking change, since we'd be using a different function for comparisons.