@@ -2260,15 +2260,26 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
22602260
22612261 // Look for a type inside the generator interior that matches the target type to get
22622262 // a span.
2263+ let target_ty_erased = self . tcx . erase_regions ( & target_ty) ;
22632264 let target_span = tables. generator_interior_types . iter ( )
22642265 . find ( |ty:: GeneratorInteriorTypeCause { ty, .. } | {
2265- let ty = ty. builtin_deref ( false ) . map ( |ty_and_mut| ty_and_mut. ty ) . unwrap_or ( ty) ;
2266- let target_ty = target_ty. builtin_deref ( false )
2267- . map ( |ty_and_mut| ty_and_mut. ty )
2268- . unwrap_or ( target_ty) ;
2269- let eq = ty:: TyS :: same_type ( ty, target_ty) ;
2270- debug ! ( "maybe_note_obligation_cause_for_async_await: ty={:?} \
2271- target_ty={:?} eq={:?}", ty, target_ty, eq) ;
2266+ // Careful: the regions for types that appear in the
2267+ // generator interior are not generally known, so we
2268+ // want to erase them when comparing (and anyway,
2269+ // `Send` and other bounds are generally unaffected by
2270+ // the choice of region). When erasing regions, we
2271+ // also have to erase late-bound regions. This is
2272+ // because the types that appear in the generator
2273+ // interior generally contain "bound regions" to
2274+ // represent regions that are part of the suspended
2275+ // generator frame. Bound regions are preserved by
2276+ // `erase_regions` and so we must also call
2277+ // `erase_late_bound_regions`.
2278+ let ty_erased = self . tcx . erase_late_bound_regions ( & ty:: Binder :: bind ( * ty) ) ;
2279+ let ty_erased = self . tcx . erase_regions ( & ty_erased) ;
2280+ let eq = ty:: TyS :: same_type ( ty_erased, target_ty_erased) ;
2281+ debug ! ( "maybe_note_obligation_cause_for_async_await: ty_erased={:?} \
2282+ target_ty_erased={:?} eq={:?}", ty_erased, target_ty_erased, eq) ;
22722283 eq
22732284 } )
22742285 . map ( |ty:: GeneratorInteriorTypeCause { span, scope_span, .. } |
0 commit comments