-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Fix inference for projections with associated traits with multiple bounds; fixes #34792 #34912
Conversation
r? @pnkfelix (rust_highfive has picked a reviewer for you, use r? to override) |
r? @eddyb |
I recall someone saying that this might require a crater test. Is that still the case? |
@doomrobo Indeed, although you first need to fix the two |
@@ -1170,22 +1172,20 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> { | |||
debug!("assemble_candidates_for_projected_tys: trait_def_id={:?}", | |||
trait_def_id); | |||
|
|||
let result = self.probe(|this, snapshot| { | |||
self.probe(|this, snapshot| { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't need to be a probe, I believe in_snapshot
will do.
Hmm. It appears that the error messages for Here is the gist for the first one. The second differs in the same way. I have no intuitions so far, but I'm looking into it. |
cc @nikomatsakis @jonathandturner What could cause those errors? It looks like the |
☔ The latest upstream changes (presumably #35091) made this pull request unmergeable. Please resolve the merge conflicts. |
Closing due to inactivity, but feel free to resubmit with a rebase! |
The problem was due to the fact that no particular trait bound was specified when a projection was matched with a trait bound, even when multiple bounds existed. The compiler consistently picked the first bound on the associated type that it found that was able to match the type's obligation (which, in the regression test, is
<F as Foo>
or<Self as Foo>
).The fix involved modifying the
SelectionCandidate::ProjectionCandidate
variant to carry a trait ref to refer to its matching bound. And instead of stopping on the first match we find, we add all matching bounds to thecandidates
vector. Also in the winnowing step, aProjectionCandidate
cannot trump anotherProjectionCandidate
unless they are identical.