-
Notifications
You must be signed in to change notification settings - Fork 128
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
Type inference breakage in 0.7.5 on ArrayString::as_ref #276
Comments
https://predr.ag/blog/semver-in-rust-tooling-breakage-and-edge-cases/ It is not generally considered breaking to add trait implementations. Rust is designed for this additivity. As a general rule AsRef is a conversion trait and users should prefer to use it only for constrained conversions, not open code it: for those cases use the (many) alternatives that are not ambiguous in type. |
Yes, I fully agree. (And I was live at FOSDEM to see Predrag give that great talk!) Breaking changes are not black/white. Calling every instance where type inference may break a major change in the semver sense would not be viable. Still, in this case, it did break a build and it took me more than an hour to fully understand what was going on. (Didn't happen in my own code, but I was trying to build a debian package of some software that uses arrayvec as a dependency. The build failure happened deep within a build pipeline, in a container with a different debian version installed, etc pp.) And be assured that I'm not complaining. All I want is to raise a bit of awareness, so maybe the next person with the same issue can find the solution a little bit faster. That's why me report concluded with "it may be best to just document this change". And to be honest, I'm not even sure about the best place for such documentation, otherwise I would have proposed some specific change. Perhaps you could add "This may break type inference if you use as_ref without type annotations." to the release notes of 0.7.5? Anyway, this is a minor issue. Thanks for your work on arrayvec, it's a nice library! (EDIT: And it's also fine if you just close this report without any change!) |
This code compiles with arrayvec 0.7.4:
However, with arrayvec 0.7.5 and 0.7.6, I get the following error:
This is because there are now two
AsRef
impls, namely:Before, only the first existed, so the compiler could infer that
as_ref
must be a&str
.But with the second implementation, it became ambiguous, and now the compiler needs a type annotation.
I'm not sure how to best handle this:
As the fix for affected users is quite simple (add a type annotation), it may be best to just document this change?
The text was updated successfully, but these errors were encountered: