Fix inference for projections with associated traits with multiple bounds; fixes #34792 #34912
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.