You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
subscriber: make PartialOrd & Ord impls more correct (tokio-rs#995)
## Motivation
Currently, there are some minor issues with `Ord` and `PartialOrd` impls
in `tracing_subscriber::filter::env`:
- The `Directive` and `StaticDirective` types implement `PartialOrd`
with an implementation that never returns `None`, and then have `Ord`
implementations that call `partial_cmp` and `expect` that the returned
value is `Some`. This isn't necessary.
- `field::Match` implements `PartialOrd` manually but derives `Ord`.
Since these traits must agree, using the derived implementation for
one but manually implementing the other is potentially incorrect (see
tokio-rs#991).
## Solution
This branch fixes these issues. I've moved actual comparison code from
`PartialOrd` impls for `Directive` and `StaticDirective` to their `Ord`
impls, and changed `PartialOrd::partial_cmp` for those types to call
`Ord::cmp` and wrap it in a `Some`, rather than having `Ord::cmp` call
`PartialOrd::partial_cmp` and unwrap it. This way, the fact that these
comparison 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` for `field::Match` and
removed the derived impl. This should make Clippy happier.
Signed-off-by: Eliza Weisman <eliza@buoyant.io>
0 commit comments