subscriber: make PartialOrd
& Ord
impls more correct
#995
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.
Motivation
Currently, there are some minor issues with
Ord
andPartialOrd
implsin
tracing_subscriber::filter::env
:Directive
andStaticDirective
types implementPartialOrd
with an implementation that never returns
None
, and then haveOrd
implementations that call
partial_cmp
andexpect
that the returnedvalue is
Some
. This isn't necessary.field::Match
implementsPartialOrd
manually but derivesOrd
.Since these traits must agree, using the derived implementation for
one but manually implementing the other is potentially incorrect (see
fix nightly clippy warnings #991).
Solution
This branch fixes these issues. I've moved actual comparison code from
PartialOrd
impls forDirective
andStaticDirective
to theirOrd
impls, and changed
PartialOrd::partial_cmp
for those types to callOrd::cmp
and wrap it in aSome
, rather than havingOrd::cmp
callPartialOrd::partial_cmp
and unwrap it. This way, the fact that thesecomparison impls can never return
None
is encoded at the type level,rather than having an
expect
that will always succeed.Additionally, I've added a manual impl of
Ord
forfield::Match
andremoved the derived impl. This should make Clippy happier.
Signed-off-by: Eliza Weisman eliza@buoyant.io