rustc_trait_selection::infer::outlives::test_type_match

Function extract_verify_if_eq

Source
pub fn extract_verify_if_eq<'tcx>(
    tcx: TyCtxt<'tcx>,
    verify_if_eq_b: &Binder<TyCtxt<'tcx>, VerifyIfEq<'tcx>>,
    test_ty: Ty<'tcx>,
) -> Option<Region<'tcx>>
Expand description

Given a “verify-if-eq” type test like:

exists<'a...> {
    verify_if_eq(some_type, bound_region)
}

and the type test_ty that the type test is being tested against, returns:

  • None if some_type cannot be made equal to test_ty, no matter the values of the variables in exists.
  • Some(r) with a suitable bound (typically the value of bound_region, modulo any bound existential variables, which will be instantiated) for the type under test.

NB: This function uses a simplistic, syntactic version of type equality. In other words, it may spuriously return None even if the type-under-test is in fact equal to some_type. In practice, though, this is used on types that are either projections like T::Item or T and it works fine, but it could have trouble when complex types with higher-ranked binders and the like are used. This is a particular challenge since this function is invoked very late in inference and hence cannot make use of the normal inference machinery.