mirror of
https://github.com/BurntSushi/jiff.git
synced 2025-12-23 08:47:45 +00:00
Unfortunately, these impls can cause inference regressions when
non-robust code is written that assumes there is only one
Partial{Eq,Ord} impl for a particular integer type.
It would be one thing if these trait impls were external or somehow
fundamental to Jiff's design. But they only existed as a convenience. So
we remove the trait impls and take our medicine. We already had a
`Constant` wrapper type (also used for trait impls), so we just switch
all equality and inequality comparisons over to that.
I tested this with the following program:
```rust
use env_logger;
fn main() {
let x: u64 = 1;
let y: i128 = 0;
assert!(y < x.into());
let x: u32 = 1;
let y: i64 = 0;
assert!(y < x.into());
let x: u16 = 1;
let y: i32 = 0;
assert!(y < x.into());
let x: u8 = 1;
let y: i16 = 0;
assert!(y < x.into());
}
```
And this `Cargo.toml`:
```toml
[package]
publish = false
name = "jiff-inference-regression"
version = "0.1.0"
edition = "2024"
[patch.crates-io]
jiff = { path = "/home/andrew/rust/jiff/fixit" }
[dependencies]
env_logger = { version = "0.11.7", features = ["humantime"] }
[[bin]]
name = "jiff-inference-regression"
path = "main.rs"
[profile.release]
debug = true
```
I took this path because it's either this or the reporter fixes their
code. Arguably, the reporter should fix their code since it's likely
their code will break when or if some other crate adds similar trait
impls. But as I said, these trait impls are just for convenience, so
the pragmatic trade-off is to remove them and thus not be the source of
whatever problems folks hit.
[I asked the lang team about this problem][lang-zulip-question], and
they seem to agree that this is the right course of action. (And there
are ideas swirling around on how to mitigate this problem, but that's
for the future.)
Fixes #293
[lang-zulip-question]:
|
||
|---|---|---|
| .. | ||
| civil | ||
| fmt | ||
| shared | ||
| tz | ||
| util | ||
| duration.rs | ||
| error.rs | ||
| lib.rs | ||
| logging.rs | ||
| now.rs | ||
| signed_duration.rs | ||
| span.rs | ||
| timestamp.rs | ||
| zoned.rs | ||