1
Fork 0

Fix style nits

This commit is contained in:
Tyler Mandry 2020-04-07 18:50:27 -07:00
parent df0a16b29f
commit 00795a9940

View file

@ -1095,6 +1095,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
obligation.predicate, obligation.cause.span obligation.predicate, obligation.cause.span
); );
let source_map = self.tcx.sess.source_map(); let source_map = self.tcx.sess.source_map();
let hir = self.tcx.hir();
// Attempt to detect an async-await error by looking at the obligation causes, looking // Attempt to detect an async-await error by looking at the obligation causes, looking
// for a generator to be present. // for a generator to be present.
@ -1178,7 +1179,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
let span = self.tcx.def_span(generator_did); let span = self.tcx.def_span(generator_did);
// Do not ICE on closure typeck (#66868). // Do not ICE on closure typeck (#66868).
if self.tcx.hir().as_local_hir_id(generator_did).is_none() { if hir.as_local_hir_id(generator_did).is_none() {
return false; return false;
} }
@ -1204,12 +1205,10 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
} }
}; };
let generator_body = self let generator_body = hir
.tcx
.hir()
.as_local_hir_id(generator_did) .as_local_hir_id(generator_did)
.and_then(|hir_id| self.tcx.hir().maybe_body_owned_by(hir_id)) .and_then(|hir_id| hir.maybe_body_owned_by(hir_id))
.map(|body_id| self.tcx.hir().body(body_id)); .map(|body_id| hir.body(body_id));
let mut visitor = AwaitsVisitor::default(); let mut visitor = AwaitsVisitor::default();
if let Some(body) = generator_body { if let Some(body) = generator_body {
visitor.visit_body(body); visitor.visit_body(body);
@ -1219,10 +1218,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for 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_ty_erased = self.tcx.erase_regions(&target_ty);
let target_span = tables let ty_matches = |ty| -> bool {
.generator_interior_types
.iter()
.find(|ty::GeneratorInteriorTypeCause { ty, .. }| {
// Careful: the regions for types that appear in the // Careful: the regions for types that appear in the
// generator interior are not generally known, so we // generator interior are not generally known, so we
// want to erase them when comparing (and anyway, // want to erase them when comparing (and anyway,
@ -1235,7 +1231,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
// generator frame. Bound regions are preserved by // generator frame. Bound regions are preserved by
// `erase_regions` and so we must also call // `erase_regions` and so we must also call
// `erase_late_bound_regions`. // `erase_late_bound_regions`.
let ty_erased = self.tcx.erase_late_bound_regions(&ty::Binder::bind(*ty)); let ty_erased = self.tcx.erase_late_bound_regions(&ty::Binder::bind(ty));
let ty_erased = self.tcx.erase_regions(&ty_erased); let ty_erased = self.tcx.erase_regions(&ty_erased);
let eq = ty::TyS::same_type(ty_erased, target_ty_erased); let eq = ty::TyS::same_type(ty_erased, target_ty_erased);
debug!( debug!(
@ -1244,25 +1240,24 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
ty_erased, target_ty_erased, eq ty_erased, target_ty_erased, eq
); );
eq eq
}) };
let target_span = tables
.generator_interior_types
.iter()
.find(|ty::GeneratorInteriorTypeCause { ty, .. }| ty_matches(ty))
.map(|cause| { .map(|cause| {
// Check to see if any awaited expressions have the target type. // Check to see if any awaited expressions have the target type.
let from_awaited_ty = visitor let from_awaited_ty = visitor
.awaits .awaits
.into_iter() .into_iter()
.map(|id| self.tcx.hir().expect_expr(id)) .map(|id| hir.expect_expr(id))
.find(|expr| { .find(|await_expr| {
let ty = tables.expr_ty_adjusted(&expr); let ty = tables.expr_ty_adjusted(&await_expr);
// Compare types using the same logic as above.
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!( debug!(
"maybe_note_obligation_cause_for_async_await: await_expr={:?} \ "maybe_note_obligation_cause_for_async_await: await_expr={:?}",
await_ty_erased={:?} target_ty_erased={:?} eq={:?}", await_expr
expr, ty_erased, target_ty_erased, eq
); );
eq ty_matches(ty)
}) })
.map(|expr| expr.span); .map(|expr| expr.span);
let ty::GeneratorInteriorTypeCause { span, scope_span, expr, .. } = cause; let ty::GeneratorInteriorTypeCause { span, scope_span, expr, .. } = cause;
@ -1791,12 +1786,9 @@ impl<'v> Visitor<'v> for AwaitsVisitor {
} }
fn visit_expr(&mut self, ex: &'v hir::Expr<'v>) { fn visit_expr(&mut self, ex: &'v hir::Expr<'v>) {
match ex.kind { if let hir::ExprKind::Yield(_, hir::YieldSource::Await { expr: Some(id) }) = ex.kind {
hir::ExprKind::Yield(_, hir::YieldSource::Await { expr: Some(id) }) => {
self.awaits.push(id) self.awaits.push(id)
} }
_ => (),
}
hir::intravisit::walk_expr(self, ex) hir::intravisit::walk_expr(self, ex)
} }
} }