@@ -980,6 +980,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
980
980
obligation. predicate, obligation. cause. span
981
981
) ;
982
982
let source_map = self . tcx . sess . source_map ( ) ;
983
+ let hir = self . tcx . hir ( ) ;
983
984
984
985
// Attempt to detect an async-await error by looking at the obligation causes, looking
985
986
// for a generator to be present.
@@ -1063,7 +1064,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
1063
1064
let span = self . tcx . def_span ( generator_did) ;
1064
1065
1065
1066
// Do not ICE on closure typeck (#66868).
1066
- if self . tcx . hir ( ) . as_local_hir_id ( generator_did) . is_none ( ) {
1067
+ if hir. as_local_hir_id ( generator_did) . is_none ( ) {
1067
1068
return false ;
1068
1069
}
1069
1070
@@ -1089,12 +1090,10 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
1089
1090
}
1090
1091
} ;
1091
1092
1092
- let generator_body = self
1093
- . tcx
1094
- . hir ( )
1093
+ let generator_body = hir
1095
1094
. as_local_hir_id ( generator_did)
1096
- . and_then ( |hir_id| self . tcx . hir ( ) . maybe_body_owned_by ( hir_id) )
1097
- . map ( |body_id| self . tcx . hir ( ) . body ( body_id) ) ;
1095
+ . and_then ( |hir_id| hir. maybe_body_owned_by ( hir_id) )
1096
+ . map ( |body_id| hir. body ( body_id) ) ;
1098
1097
let mut visitor = AwaitsVisitor :: default ( ) ;
1099
1098
if let Some ( body) = generator_body {
1100
1099
visitor. visit_body ( body) ;
@@ -1104,50 +1103,46 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
1104
1103
// Look for a type inside the generator interior that matches the target type to get
1105
1104
// a span.
1106
1105
let target_ty_erased = self . tcx . erase_regions ( & target_ty) ;
1106
+ let ty_matches = |ty| -> bool {
1107
+ // Careful: the regions for types that appear in the
1108
+ // generator interior are not generally known, so we
1109
+ // want to erase them when comparing (and anyway,
1110
+ // `Send` and other bounds are generally unaffected by
1111
+ // the choice of region). When erasing regions, we
1112
+ // also have to erase late-bound regions. This is
1113
+ // because the types that appear in the generator
1114
+ // interior generally contain "bound regions" to
1115
+ // represent regions that are part of the suspended
1116
+ // generator frame. Bound regions are preserved by
1117
+ // `erase_regions` and so we must also call
1118
+ // `erase_late_bound_regions`.
1119
+ let ty_erased = self . tcx . erase_late_bound_regions ( & ty:: Binder :: bind ( ty) ) ;
1120
+ let ty_erased = self . tcx . erase_regions ( & ty_erased) ;
1121
+ let eq = ty:: TyS :: same_type ( ty_erased, target_ty_erased) ;
1122
+ debug ! (
1123
+ "maybe_note_obligation_cause_for_async_await: ty_erased={:?} \
1124
+ target_ty_erased={:?} eq={:?}",
1125
+ ty_erased, target_ty_erased, eq
1126
+ ) ;
1127
+ eq
1128
+ } ;
1107
1129
let target_span = tables
1108
1130
. generator_interior_types
1109
1131
. iter ( )
1110
- . find ( |ty:: GeneratorInteriorTypeCause { ty, .. } | {
1111
- // Careful: the regions for types that appear in the
1112
- // generator interior are not generally known, so we
1113
- // want to erase them when comparing (and anyway,
1114
- // `Send` and other bounds are generally unaffected by
1115
- // the choice of region). When erasing regions, we
1116
- // also have to erase late-bound regions. This is
1117
- // because the types that appear in the generator
1118
- // interior generally contain "bound regions" to
1119
- // represent regions that are part of the suspended
1120
- // generator frame. Bound regions are preserved by
1121
- // `erase_regions` and so we must also call
1122
- // `erase_late_bound_regions`.
1123
- let ty_erased = self . tcx . erase_late_bound_regions ( & ty:: Binder :: bind ( * ty) ) ;
1124
- let ty_erased = self . tcx . erase_regions ( & ty_erased) ;
1125
- let eq = ty:: TyS :: same_type ( ty_erased, target_ty_erased) ;
1126
- debug ! (
1127
- "maybe_note_obligation_cause_for_async_await: ty_erased={:?} \
1128
- target_ty_erased={:?} eq={:?}",
1129
- ty_erased, target_ty_erased, eq
1130
- ) ;
1131
- eq
1132
- } )
1132
+ . find ( |ty:: GeneratorInteriorTypeCause { ty, .. } | ty_matches ( ty) )
1133
1133
. map ( |cause| {
1134
1134
// Check to see if any awaited expressions have the target type.
1135
1135
let from_awaited_ty = visitor
1136
1136
. awaits
1137
1137
. into_iter ( )
1138
- . map ( |id| self . tcx . hir ( ) . expect_expr ( id) )
1139
- . find ( |expr| {
1140
- let ty = tables. expr_ty_adjusted ( & expr) ;
1141
- // Compare types using the same logic as above.
1142
- let ty_erased = self . tcx . erase_late_bound_regions ( & ty:: Binder :: bind ( ty) ) ;
1143
- let ty_erased = self . tcx . erase_regions ( & ty_erased) ;
1144
- let eq = ty:: TyS :: same_type ( ty_erased, target_ty_erased) ;
1138
+ . map ( |id| hir. expect_expr ( id) )
1139
+ . find ( |await_expr| {
1140
+ let ty = tables. expr_ty_adjusted ( & await_expr) ;
1145
1141
debug ! (
1146
- "maybe_note_obligation_cause_for_async_await: await_expr={:?} \
1147
- await_ty_erased={:?} target_ty_erased={:?} eq={:?}",
1148
- expr, ty_erased, target_ty_erased, eq
1142
+ "maybe_note_obligation_cause_for_async_await: await_expr={:?}" ,
1143
+ await_expr
1149
1144
) ;
1150
- eq
1145
+ ty_matches ( ty )
1151
1146
} )
1152
1147
. map ( |expr| expr. span ) ;
1153
1148
let ty:: GeneratorInteriorTypeCause { span, scope_span, expr, .. } = cause;
@@ -1669,11 +1664,8 @@ impl<'v> Visitor<'v> for AwaitsVisitor {
1669
1664
}
1670
1665
1671
1666
fn visit_expr ( & mut self , ex : & ' v hir:: Expr < ' v > ) {
1672
- match ex. kind {
1673
- hir:: ExprKind :: Yield ( _, hir:: YieldSource :: Await { expr : Some ( id) } ) => {
1674
- self . awaits . push ( id)
1675
- }
1676
- _ => ( ) ,
1667
+ if let hir:: ExprKind :: Yield ( _, hir:: YieldSource :: Await { expr : Some ( id) } ) = ex. kind {
1668
+ self . awaits . push ( id)
1677
1669
}
1678
1670
hir:: intravisit:: walk_expr ( self , ex)
1679
1671
}
0 commit comments