[−][src]Function rustc_typeck::check::fixup_opaque_types

pub(in check) fn fixup_opaque_types<'tcx, T>(
    tcx: TyCtxt<'tcx>,
    val: T
) -> T where
    T: TypeFoldable<'tcx>, 

Inspects the substs of opaque types, replacing any inference variables with proper generic parameter from the identity substs.

This is run after we normalize the function signature, to fix any inference variables introduced by the projection of associated types. This ensures that any opaque types used in the signature continue to refer to generic parameters, allowing them to be considered for defining uses in the function body

For example, consider this code.

trait MyTrait {
    type MyItem;
    fn use_it(self) -> Self::MyItem
}
impl<T, I> MyTrait for T where T: Iterator<Item = I> {
    type MyItem = impl Iterator<Item = I>;
    fn use_it(self) -> Self::MyItem {
        self
    }
}

When we normalize the signature of use_it from the impl block, we will normalize Self::MyItem to the opaque type impl Iterator<Item = I> However, this projection result may contain inference variables, due to the way that projection works. We didn't have any inference variables in the signature to begin with - leaving them in will cause us to incorrectly conclude that we don't have a defining use of MyItem. By mapping inference variables back to the actual generic parameters, we will correctly see that we have a defining use of MyItem