-
Notifications
You must be signed in to change notification settings - Fork 192
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Reconsider PartialEq and PartialOrd with primitives #150
Comments
(Can't say I have big projects using That certainly looks nasty - makes you wish for binary operation traits to have defaults for inferring RHS == LHS types... This basically makes it impossible to implement nice interoperability between builtin and third-party numeric types. |
I was trying to reconcile why this wasn't so bad with other binary operators, like Whereas with I'd like to find a compromise where we can solve the rough goal -- comparing bigints with primitives without converting (and allocating) the latter. Maybe we could add our own |
This manually reverts the new implementations from pull request rust-num#136. As noted in issue rust-num#150, the mere existence of those impls can have a bad effect on type inference in other parts of a crate, even from afar. All comparisons of primitives with an unknown type become ambiguous whether that's meant to compare with itself or a bigint, even if `num-bigint` is not directly in scope at all. Since this can break unrelated code in surprising ways, I think it's not wise for us to have these implementations. Maybe we can explore other methods to compare with primitives in the future, though it won't be as convenient as using the operators.
Interesting issue. Why are you not concerned about the The conclusion is probably good anyway, I'm just making noise about my aversion to naked |
In comparison context? I guess I was not concerned because it was working fine. Maybe that was lazy of me, but still, that code broke here. I also had some comparisons with I think it's pretty idiomatic to prefer type inference over explicit types when you can get away with it. |
It is idiomatic but using AsRef and Into outside of argument conversion has always been a trap for code that will break due to type inference in this way. It is not localized here, it's a general problem with those traits. IMO it's always been wrong to use them like this, but I can't turn the tide. For example a failed attempt to turn the tide: :) rust-lang/rust#36443 |
151: Revert PartialEq and PartialOrd with primitives r=cuviper a=cuviper This manually reverts the new implementations from pull request #136. As noted in issue #150, the mere existence of those impls can have a bad effect on type inference in other parts of a crate, even from afar. All comparisons of primitives with an unknown type become ambiguous whether that's meant to compare with itself or a bigint, even if `num-bigint` is not directly in scope at all. Since this can break unrelated code in surprising ways, I think it's not wise for us to have these implementations. Maybe we can explore other methods to compare with primitives in the future, though it won't be as convenient as using the operators. Co-authored-by: Josh Stone <cuviper@gmail.com>
Would it make sense to also remove other operators (+, *, etc) between BigInt/BigUint and primitive types? This would be consistent with they are not allowed between different primitive types. To avoid losing performance, BigUint representation could be special-cased for a single BigDigit so that conversions are very cheap. |
Argh, I was just about to open a PR adding those implementations and I've stumbled upon this issue. IMHO breaking a generic |
This afternoon I tried updating some of my numerical code (Project Euler stuff) to use the master branch of
num-bigint
for pre-release testing. Some of the changes needed are expected, but the one that's really killing me is the expandedPartialEq
andPartialOrd
(#105/#136). This broke type inference in many places, even wherenum-bigint
wasn't used at all!I have a common
euler
crate with utility stuff, which does pull innum-bigint
. However, this problemp082
doesn't use anything with bigint, yet it's affected:That's a bad error about
weights
-- the problem is really in theMAX.into()
type, which previously inferred correctly fromu8
tousize
. I may try to reduce a test case of that bad message for a rustc bug. But I'm really concerned that we've affected type inference from afar.cc @hansihe @birkenfeld -- have you tried using master
num-bigint
on any big projects?The text was updated successfully, but these errors were encountered: