@@ -1095,6 +1095,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
1095
1095
obligation. predicate, obligation. cause. span
1096
1096
) ;
1097
1097
let source_map = self . tcx . sess . source_map ( ) ;
1098
+ let hir = self . tcx . hir ( ) ;
1098
1099
1099
1100
// Attempt to detect an async-await error by looking at the obligation causes, looking
1100
1101
// for a generator to be present.
@@ -1178,7 +1179,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
1178
1179
let span = self . tcx . def_span ( generator_did) ;
1179
1180
1180
1181
// 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 ( ) {
1182
1183
return false ;
1183
1184
}
1184
1185
@@ -1204,12 +1205,10 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
1204
1205
}
1205
1206
} ;
1206
1207
1207
- let generator_body = self
1208
- . tcx
1209
- . hir ( )
1208
+ let generator_body = hir
1210
1209
. 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) ) ;
1213
1212
let mut visitor = AwaitsVisitor :: default ( ) ;
1214
1213
if let Some ( body) = generator_body {
1215
1214
visitor. visit_body ( body) ;
@@ -1219,50 +1218,46 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
1219
1218
// Look for a type inside the generator interior that matches the target type to get
1220
1219
// a span.
1221
1220
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
+ } ;
1222
1244
let target_span = tables
1223
1245
. generator_interior_types
1224
1246
. 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) )
1248
1248
. map ( |cause| {
1249
1249
// Check to see if any awaited expressions have the target type.
1250
1250
let from_awaited_ty = visitor
1251
1251
. awaits
1252
1252
. 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) ;
1260
1256
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
1264
1259
) ;
1265
- eq
1260
+ ty_matches ( ty )
1266
1261
} )
1267
1262
. map ( |expr| expr. span ) ;
1268
1263
let ty:: GeneratorInteriorTypeCause { span, scope_span, expr, .. } = cause;
@@ -1791,11 +1786,8 @@ impl<'v> Visitor<'v> for AwaitsVisitor {
1791
1786
}
1792
1787
1793
1788
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)
1799
1791
}
1800
1792
hir:: intravisit:: walk_expr ( self , ex)
1801
1793
}
0 commit comments