Fix opaque types resulting from projections in function signature#66178
Merged
bors merged 7 commits intorust-lang:masterfrom Nov 26, 2019
Merged
Fix opaque types resulting from projections in function signature#66178bors merged 7 commits intorust-lang:masterfrom
bors merged 7 commits intorust-lang:masterfrom
Conversation
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
When we normalize the types in a function signature, we may end up
resolving a projection to an opaque type (e.g.
Self::MyTypewhenwe have
type MyType = impl SomeTrait). When the projection isresolved, we will instantiate the generic parameters into fresh
inference variables.
While we do want to normalize projections to opaque types, we don't want
to replace the explicit generic parameters (e.g.
Tinimpl MyTrait<T>) with inference variables. We want the opaque type in thefunction signature to be eligible to be a defining use of that opaque
type - adding inference variables prevents this, since the opaque type
substs now appears to refer to some specific type, rather than a generic
type.
To resolve this issue, we inspect the opaque types in the function
signature after normalization. Any inference variables in the substs are
replaced with the corresponding generic parameter in the identity substs
(e.g.
Tinimpl MyTrait<T>). Note that normalization is the only waythat we can end up with inference variables in opaque substs in a
function signature - users have no way of getting inference variables
into a function signature.
Note that all of this refers to the opaque type (ty::Opaque) and its
subst - not to the underlying type.
Fixes #59342