Skip to content

Commit 00795a9

Browse files
committed
Fix style nits
1 parent df0a16b commit 00795a9

File tree

1 file changed

+37
-45
lines changed

1 file changed

+37
-45
lines changed

src/librustc_trait_selection/traits/error_reporting/suggestions.rs

+37-45
Original file line numberDiff line numberDiff line change
@@ -1095,6 +1095,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
10951095
obligation.predicate, obligation.cause.span
10961096
);
10971097
let source_map = self.tcx.sess.source_map();
1098+
let hir = self.tcx.hir();
10981099

10991100
// Attempt to detect an async-await error by looking at the obligation causes, looking
11001101
// for a generator to be present.
@@ -1178,7 +1179,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
11781179
let span = self.tcx.def_span(generator_did);
11791180

11801181
// Do not ICE on closure typeck (#66868).
1181-
if self.tcx.hir().as_local_hir_id(generator_did).is_none() {
1182+
if hir.as_local_hir_id(generator_did).is_none() {
11821183
return false;
11831184
}
11841185

@@ -1204,12 +1205,10 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
12041205
}
12051206
};
12061207

1207-
let generator_body = self
1208-
.tcx
1209-
.hir()
1208+
let generator_body = hir
12101209
.as_local_hir_id(generator_did)
1211-
.and_then(|hir_id| self.tcx.hir().maybe_body_owned_by(hir_id))
1212-
.map(|body_id| self.tcx.hir().body(body_id));
1210+
.and_then(|hir_id| hir.maybe_body_owned_by(hir_id))
1211+
.map(|body_id| hir.body(body_id));
12131212
let mut visitor = AwaitsVisitor::default();
12141213
if let Some(body) = generator_body {
12151214
visitor.visit_body(body);
@@ -1219,50 +1218,46 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
12191218
// Look for a type inside the generator interior that matches the target type to get
12201219
// a span.
12211220
let target_ty_erased = self.tcx.erase_regions(&target_ty);
1221+
let ty_matches = |ty| -> bool {
1222+
// Careful: the regions for types that appear in the
1223+
// generator interior are not generally known, so we
1224+
// want to erase them when comparing (and anyway,
1225+
// `Send` and other bounds are generally unaffected by
1226+
// the choice of region). When erasing regions, we
1227+
// also have to erase late-bound regions. This is
1228+
// because the types that appear in the generator
1229+
// interior generally contain "bound regions" to
1230+
// represent regions that are part of the suspended
1231+
// generator frame. Bound regions are preserved by
1232+
// `erase_regions` and so we must also call
1233+
// `erase_late_bound_regions`.
1234+
let ty_erased = self.tcx.erase_late_bound_regions(&ty::Binder::bind(ty));
1235+
let ty_erased = self.tcx.erase_regions(&ty_erased);
1236+
let eq = ty::TyS::same_type(ty_erased, target_ty_erased);
1237+
debug!(
1238+
"maybe_note_obligation_cause_for_async_await: ty_erased={:?} \
1239+
target_ty_erased={:?} eq={:?}",
1240+
ty_erased, target_ty_erased, eq
1241+
);
1242+
eq
1243+
};
12221244
let target_span = tables
12231245
.generator_interior_types
12241246
.iter()
1225-
.find(|ty::GeneratorInteriorTypeCause { ty, .. }| {
1226-
// Careful: the regions for types that appear in the
1227-
// generator interior are not generally known, so we
1228-
// want to erase them when comparing (and anyway,
1229-
// `Send` and other bounds are generally unaffected by
1230-
// the choice of region). When erasing regions, we
1231-
// also have to erase late-bound regions. This is
1232-
// because the types that appear in the generator
1233-
// interior generally contain "bound regions" to
1234-
// represent regions that are part of the suspended
1235-
// generator frame. Bound regions are preserved by
1236-
// `erase_regions` and so we must also call
1237-
// `erase_late_bound_regions`.
1238-
let ty_erased = self.tcx.erase_late_bound_regions(&ty::Binder::bind(*ty));
1239-
let ty_erased = self.tcx.erase_regions(&ty_erased);
1240-
let eq = ty::TyS::same_type(ty_erased, target_ty_erased);
1241-
debug!(
1242-
"maybe_note_obligation_cause_for_async_await: ty_erased={:?} \
1243-
target_ty_erased={:?} eq={:?}",
1244-
ty_erased, target_ty_erased, eq
1245-
);
1246-
eq
1247-
})
1247+
.find(|ty::GeneratorInteriorTypeCause { ty, .. }| ty_matches(ty))
12481248
.map(|cause| {
12491249
// Check to see if any awaited expressions have the target type.
12501250
let from_awaited_ty = visitor
12511251
.awaits
12521252
.into_iter()
1253-
.map(|id| self.tcx.hir().expect_expr(id))
1254-
.find(|expr| {
1255-
let ty = tables.expr_ty_adjusted(&expr);
1256-
// Compare types using the same logic as above.
1257-
let ty_erased = self.tcx.erase_late_bound_regions(&ty::Binder::bind(ty));
1258-
let ty_erased = self.tcx.erase_regions(&ty_erased);
1259-
let eq = ty::TyS::same_type(ty_erased, target_ty_erased);
1253+
.map(|id| hir.expect_expr(id))
1254+
.find(|await_expr| {
1255+
let ty = tables.expr_ty_adjusted(&await_expr);
12601256
debug!(
1261-
"maybe_note_obligation_cause_for_async_await: await_expr={:?} \
1262-
await_ty_erased={:?} target_ty_erased={:?} eq={:?}",
1263-
expr, ty_erased, target_ty_erased, eq
1257+
"maybe_note_obligation_cause_for_async_await: await_expr={:?}",
1258+
await_expr
12641259
);
1265-
eq
1260+
ty_matches(ty)
12661261
})
12671262
.map(|expr| expr.span);
12681263
let ty::GeneratorInteriorTypeCause { span, scope_span, expr, .. } = cause;
@@ -1791,11 +1786,8 @@ impl<'v> Visitor<'v> for AwaitsVisitor {
17911786
}
17921787

17931788
fn visit_expr(&mut self, ex: &'v hir::Expr<'v>) {
1794-
match ex.kind {
1795-
hir::ExprKind::Yield(_, hir::YieldSource::Await { expr: Some(id) }) => {
1796-
self.awaits.push(id)
1797-
}
1798-
_ => (),
1789+
if let hir::ExprKind::Yield(_, hir::YieldSource::Await { expr: Some(id) }) = ex.kind {
1790+
self.awaits.push(id)
17991791
}
18001792
hir::intravisit::walk_expr(self, ex)
18011793
}

0 commit comments

Comments
 (0)