|
|
|
|
|
by pas
1916 days ago
|
|
You don't have to use PhantomData. > "upstream crates may add a new impl" I have satisfied the compiler but no bugs were prevented. Trial-and-error debugging which version causes a bug is busywork, preventing it right when someone introduces the potential problem is at best annoying, but very fast compared to the alternative. |
|
https://play.rust-lang.org/?gist=84883cb7cdd09acdcd919888cef...
It's especially bad if your type is an enum, since there's no obvious place to put the PhantomData:
https://github.com/rust-lang/rust/issues/32739
> Trial-and-error debugging which version causes a bug is busywork, preventing it right when someone introduces the potential problem is at best annoying
It's a silly limitation. For example, u64 and u128 are not From<usize> because...well I have no idea. But you can't make them From, because Rust wants to reserve the right to make them From in the future. And you can't write a function that assumes they are NOT From, for the same reason.
So it's pointlessly hard to write generics over integers. I encounter lots of weird holes like this.
https://play.rust-lang.org/?gist=600a1ca784ee7df02351e58df43...