Skip to content
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

Add impl From<&CompactDecimal> for PluralOperands #4828

Merged
merged 7 commits into from May 23, 2024

Conversation

sffc
Copy link
Member

@sffc sffc commented Apr 19, 2024

@sffc sffc requested a review from eggrobin April 19, 2024 22:15
@sffc sffc requested a review from zbraniecki as a code owner April 19, 2024 22:15
@sffc sffc requested review from echeran and removed request for zbraniecki April 19, 2024 22:15
@sffc sffc requested a review from a team as a code owner April 19, 2024 22:22
@sffc
Copy link
Member Author

sffc commented Apr 19, 2024

Oof, the resolver was being too smart before, and now it's biting us. This is in tutorials-local CI:

error[E0283]: type annotations needed
  --> src/main.rs:16:24
   |
16 |     let result = rules.category_for(&3.into());
   |                        ^^^^^^^^^^^^    ---- type must be known at this point
   |                        |
   |                        cannot infer type of the type parameter `I` declared on the method `category_for`
   |
   = note: cannot satisfy `_: From<i32>`
   = note: required for `i32` to implement `Into<_>`

I thought adding impls was supposed to always be semver safe.

@sffc sffc requested a review from Manishearth April 19, 2024 22:27
@sffc
Copy link
Member Author

sffc commented Apr 19, 2024

Adding @Manishearth as reviewer because of the resolver issue

@Manishearth
Copy link
Member

I thought adding impls was supposed to always be semver safe.

No, it's actually expected: In general Rust does not consider "you will need to disambiguate" as a breaking change because otherwise you would never be able to add anything to your API. Adding From impls can have that effect.

@sffc
Copy link
Member Author

sffc commented Apr 23, 2024

I thought adding impls was supposed to always be semver safe.

No, it's actually expected: In general Rust does not consider "you will need to disambiguate" as a breaking change because otherwise you would never be able to add anything to your API. Adding From impls can have that effect.

ok so does this mean we can land this without a semver bump?

@Manishearth
Copy link
Member

Yes

@Manishearth
Copy link
Member

However we should use our judgement on how commonly we expect this breakage to cause actual problems.

echeran
echeran previously approved these changes Apr 23, 2024
Copy link
Contributor

@echeran echeran left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@sffc
Copy link
Member Author

sffc commented Apr 23, 2024

Yet Another Reason™ to not use Into bounds on function parameters.

(CC @zbraniecki @robertbastian who like to do this sometimes)

@sffc sffc added the discuss-priority Discuss at the next ICU4X meeting label Apr 23, 2024
@Manishearth
Copy link
Member

Manishearth commented Apr 23, 2024

It's specifically the chaining of two Intos that's the problem here, I think. Ideally an API should never require that: there should be Into impls for integers as well.

It's rarely a real problem imo, and Into accepting functions are fine as long as you never need to feed them the output of a second into. Which you shouldn't need to.

@sffc
Copy link
Member Author

sffc commented Apr 24, 2024

Looking at the code, I'm surprised that the resolver looks at &3.into() as Into<PluralOperands> and decides to infer a FixedDecimal as the intermediate type when there is nothing suggesting that. Does it check every implementer of Into<PluralOperands> that's in scope and use it so long as it is unique? That seems really really brittle.

@Manishearth
Copy link
Member

Yes, sometimes, it doesn't always work, I usually don't rely on it except in specific contexts.

@robertbastian
Copy link
Member

Well don't call functions accepting Into<T> with x.into().

@Manishearth
Copy link
Member

Yeah like I said going through Into twice is known brittle and nobody really does it,you should have a single bridging Into impl if possible

@sffc
Copy link
Member Author

sffc commented Apr 24, 2024

We all agree that clients shouldn't do this. My separate position is that functions should prefer accepting concrete types over things like Into or IntoIterator but we don't need to rehash that now. We should also consider adding the "bridging impls", but we can open a separate issue for that.

I guess the question for us at the moment is, given that we have had this docs example for quite some time, do we care that it breaks in 1.5?

@Manishearth
Copy link
Member

IMO no, but I think we should invest in adding bridging impls.

@sffc
Copy link
Member Author

sffc commented Apr 25, 2024

Discussion: the call site is fragile and should be re-written anyway; it is only in a tutorial, not a docs test, which lowers the risk. This should be a Clippy lint. So this PR can proceed.

LGTM: @Manishearth @robertbastian @sffc

@sffc
Copy link
Member Author

sffc commented Apr 30, 2024

We already have impl From<{int}> for PluralOperands so I changed the tutorials to just pass the number straight in.

@sffc sffc requested a review from robertbastian April 30, 2024 15:51
@sffc
Copy link
Member Author

sffc commented Apr 30, 2024

@robertbastian If you LGTM this PR, including the tutorial change, I will merge it.

@sffc sffc removed the discuss-priority Discuss at the next ICU4X meeting label Apr 30, 2024
@sffc
Copy link
Member Author

sffc commented May 17, 2024

Waiting on review from @eggrobin

@robertbastian robertbastian merged commit 782a01a into unicode-org:main May 23, 2024
30 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants