-
Notifications
You must be signed in to change notification settings - Fork 13k
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
use evaluate_obligation
to decide when to do unsized coercions
#50753
Comments
It looks like the only reason this is done in a loop right now is to check for the unsized tuple coercion, which is currently unstable. As @nikomatsakis pointed out on Discord, that check can probably be done during trait selection instead. I'll take a look and hopefully open a PR soon. |
The loop predates unsized tuples, so that's not it. I added the loop because:
All of this would work itself out within the trait system, as each kind of coercion would potentially result in a candidate, and the list of candidates would be refined until no ambiguities remain, and any errors caused by further evaluating an unambiguous candidate could be presented to the user. EDIT: I missed one important bit. Among those coercions, but with higher priority, would be unifying the two types. That is, |
@mikeyhew Still interested in tackling this by chance? Mainly out of curiosity, since I'm too busy with other PRs right now, and it would be a while until I could get to this... |
@alexreg I actually tried replacing the loop with |
@mikeyhew Hmm, sounds tricky. Maybe @eddyb or @nikomatsakis could advise? |
I wasn't able to come up with a reasonable solution to this (yet?), but I would like to provide some context for future reference to those who might delve into this. There are two ways in which this loop bypasses the trait system.
Without the My opinion is that in order to address this some deeper change to inference/coercion system is needed because I don't see a way to emulate a) or b) as a user of trait system. Ideally it's possible to tinker inference so that a) and b) are not needed, but I don't know how much truth there is to that idea. |
As part of the coercion logic, we sometimes invoke
coerce_unsized
:rust/src/librustc_typeck/check/coercion.rs
Line 457 in cb1ce7d
This would e.g. coerce from
&[T; 32]
to&[T]
or fromArc<T>
toArc<dyn Trait>
whereT: Trait
. To decide whether or not we are going to do this, we want to check ifArc<T>: CoerceUnsized<Arc<dyn Trait>>
is implemented (or something like that). We do this in this funky little loop here:rust/src/librustc_typeck/check/coercion.rs
Lines 538 to 552 in cb1ce7d
This kind of pulls out all the (transitive) requires to prove
CoerceUnsized
and ignores the rest. However, if we ever hope to define coercions in terms of the trait system, what we really ought to be doing is using anevaluate_obligation
check.Hopefully we can get away with this backwards compatibly.
@eddyb told me at some point -- iirc -- that the reason this loop exists is for diagnostics. So making this change may require some work on that point.
cc @leodasvacas @mikeyhew
The text was updated successfully, but these errors were encountered: