Skip to content

Fix opaque types resulting from projections in function signature#66178

Merged
bors merged 7 commits intorust-lang:masterfrom
Aaron1011:fix/opaque-normalize
Nov 26, 2019
Merged

Fix opaque types resulting from projections in function signature#66178
bors merged 7 commits intorust-lang:masterfrom
Aaron1011:fix/opaque-normalize

Conversation

@Aaron1011
Copy link
Contributor

When we normalize the types in a function signature, we may end up
resolving a projection to an opaque type (e.g. Self::MyType when
we have type MyType = impl SomeTrait). When the projection is
resolved, 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. T in impl MyTrait<T>) with inference variables. We want the opaque type in the
function 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. T in impl MyTrait<T>). Note that normalization is the only way
that 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

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

F-type_alias_impl_trait `#[feature(type_alias_impl_trait)]` merged-by-bors This PR was explicitly merged by bors. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.

Development

Successfully merging this pull request may close these issues.

Existential types for traits without generic type parameters make rustc panic

7 participants