Commit 2f1fb1a
committed
subscriber: make
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
#991).
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>PartialOrd & Ord impls more correct1 parent 216b98e commit 2f1fb1a
2 files changed
+25
-16
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
275 | 275 | | |
276 | 276 | | |
277 | 277 | | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
278 | 284 | | |
279 | 285 | | |
280 | 286 | | |
| |||
321 | 327 | | |
322 | 328 | | |
323 | 329 | | |
324 | | - | |
| 330 | + | |
325 | 331 | | |
326 | 332 | | |
327 | 333 | | |
| |||
502 | 508 | | |
503 | 509 | | |
504 | 510 | | |
505 | | - | |
506 | | - | |
| 511 | + | |
| 512 | + | |
507 | 513 | | |
508 | 514 | | |
509 | 515 | | |
| |||
542 | 548 | | |
543 | 549 | | |
544 | 550 | | |
545 | | - | |
| 551 | + | |
546 | 552 | | |
547 | 553 | | |
548 | 554 | | |
549 | | - | |
550 | | - | |
551 | | - | |
552 | | - | |
| 555 | + | |
| 556 | + | |
| 557 | + | |
553 | 558 | | |
554 | 559 | | |
555 | 560 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
16 | | - | |
| 16 | + | |
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
| |||
95 | 95 | | |
96 | 96 | | |
97 | 97 | | |
98 | | - | |
99 | | - | |
| 98 | + | |
| 99 | + | |
100 | 100 | | |
101 | 101 | | |
102 | 102 | | |
| |||
113 | 113 | | |
114 | 114 | | |
115 | 115 | | |
116 | | - | |
117 | | - | |
118 | | - | |
119 | | - | |
120 | | - | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
121 | 125 | | |
122 | 126 | | |
123 | 127 | | |
| |||
0 commit comments