Alias types (original) (raw)

Alias types

Alias types are used in chalk to handle a number of distinct Rust concepts:

What all these aliases have in common is that they let the user write the name of one type that turns out to be equivalent to another, although the equivalent type is not always known:

How aliases work

All aliases have a few parts:

Equating an alias

Alias types are integrated specially into unification. Whenever there is an attempt to unify an Alias type A with some other type T, we generate anAliasEq that must be solved:

AliasEq(A = T)

The rules for how to solve an AliasEq goal will be generated by lowering the alias definition, and depend a bit on the kind of alias. We describe that lowering in theclauses section.

Alias placeholders

For each kind of alias (except for explicit type aliases), there is also a corresponding placeholder variant in the TyKind enum. In those cases where we cannot normalize the alias to something specific, it can be equated to the placeholder type (see e.g. AssociatedType, which is the placeholder variant for associated type projections). Note that placeholders are_application types_ -- unlike an alias, a placeholder is only known to be equal with itself, just like an application type.