erase regions instead of using `builtin_deref`

The reason we were invoking `builtin_deref` was to enable comparisons
when the type was `&T`. For the reasons outlined in the comment, those
comparisons failed because the regions disagreed.
This commit is contained in:
Nicholas Matsakis 2019-12-11 13:23:07 -05:00
parent f0b51145c5
commit 5cd9f22464
1 changed files with 18 additions and 7 deletions

View File

@ -2260,15 +2260,26 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
// Look for a type inside the generator interior that matches the target type to get // Look for a type inside the generator interior that matches the target type to get
// a span. // a span.
let target_ty_erased = self.tcx.erase_regions(&target_ty);
let target_span = tables.generator_interior_types.iter() let target_span = tables.generator_interior_types.iter()
.find(|ty::GeneratorInteriorTypeCause { ty, .. }| { .find(|ty::GeneratorInteriorTypeCause { ty, .. }| {
let ty = ty.builtin_deref(false).map(|ty_and_mut| ty_and_mut.ty).unwrap_or(ty); // Careful: the regions for types that appear in the
let target_ty = target_ty.builtin_deref(false) // generator interior are not generally known, so we
.map(|ty_and_mut| ty_and_mut.ty) // want to erase them when comparing (and anyway,
.unwrap_or(target_ty); // `Send` and other bounds are generally unaffected by
let eq = ty::TyS::same_type(ty, target_ty); // the choice of region). When erasing regions, we
debug!("maybe_note_obligation_cause_for_async_await: ty={:?} \ // also have to erase late-bound regions. This is
target_ty={:?} eq={:?}", ty, target_ty, eq); // because the types that appear in the generator
// interior generally contain "bound regions" to
// represent regions that are part of the suspended
// generator frame. Bound regions are preserved by
// `erase_regions` and so we must also call
// `erase_late_bound_regions`.
let ty_erased = self.tcx.erase_late_bound_regions(&ty::Binder::bind(*ty));
let ty_erased = self.tcx.erase_regions(&ty_erased);
let eq = ty::TyS::same_type(ty_erased, target_ty_erased);
debug!("maybe_note_obligation_cause_for_async_await: ty_erased={:?} \
target_ty_erased={:?} eq={:?}", ty_erased, target_ty_erased, eq);
eq eq
}) })
.map(|ty::GeneratorInteriorTypeCause { span, scope_span, .. }| .map(|ty::GeneratorInteriorTypeCause { span, scope_span, .. }|