Fix style nits
This commit is contained in:
parent
df0a16b29f
commit
00795a9940
1 changed files with 37 additions and 45 deletions
|
@ -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,50 +1218,46 @@ 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 ty_matches = |ty| -> bool {
|
||||||
|
// Careful: the regions for types that appear in the
|
||||||
|
// generator interior are not generally known, so we
|
||||||
|
// want to erase them when comparing (and anyway,
|
||||||
|
// `Send` and other bounds are generally unaffected by
|
||||||
|
// the choice of region). When erasing regions, we
|
||||||
|
// also have to erase late-bound regions. This is
|
||||||
|
// 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
|
||||||
|
};
|
||||||
let target_span = tables
|
let target_span = tables
|
||||||
.generator_interior_types
|
.generator_interior_types
|
||||||
.iter()
|
.iter()
|
||||||
.find(|ty::GeneratorInteriorTypeCause { ty, .. }| {
|
.find(|ty::GeneratorInteriorTypeCause { ty, .. }| ty_matches(ty))
|
||||||
// Careful: the regions for types that appear in the
|
|
||||||
// generator interior are not generally known, so we
|
|
||||||
// want to erase them when comparing (and anyway,
|
|
||||||
// `Send` and other bounds are generally unaffected by
|
|
||||||
// the choice of region). When erasing regions, we
|
|
||||||
// also have to erase late-bound regions. This is
|
|
||||||
// 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
|
|
||||||
})
|
|
||||||
.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,11 +1786,8 @@ 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)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue