Rust: Resolve as paths to trait
#21253
Open
+8,575
−8,445
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
Currently path resolution doesn't resolve paths of the form
<SomeType as SomeTrait>.The solution
The most precise resolution would be the impl block that makes
SomeTypeimplementSomeTrait. While not impossible, that requires an understanding of types that's currently left for type inference.This PR takes a simple approach and resolves such a path to the trait after
as. This makes a path like<Foo as Bar>::bazequivalent toBar::bazand a path like<Self as Bar>::Assocequivalent toBar::Assoc. Hence such paths can be treated uniformly in type inference when that is convenient. The tests show an example where that removes spurious results.DCA
The DCA results seem fine. We gain a few extra calls and types.
There is an increase in inconsistencies. I've investigated some, and while they look like real inconsistencies it doesn't seem like the changes in this PR are the root cause.
Here's one example. Inside a impl block we'd currently have an ill-formed
TypeMentioninconsistency atSelf::Itembelowand after this PR we'd also have an inconsistency for
Self::Itemin the case belowThis is because
Self::Itemis now (correctly) handled as anAliasPathTypeMentionsince the right-hand side of the alias is now resolved. This causes it to no longer be picked up by this inconsistency exception. This seems desirable as this does in fact reflect a real ill-formed type mention (both before and after this PR).