@@ -252,6 +252,11 @@ pub struct ScopeTree {
252
252
/// stores the `Span` of the last one and the number of expressions
253
253
/// which came before it in a generator body.
254
254
yield_in_scope : FxHashMap < Scope , ( Span , usize ) > ,
255
+
256
+ /// The number of visit_expr calls done in the body.
257
+ /// Used to sanity check visit_expr call count when
258
+ /// calculating geneartor interiors.
259
+ body_expr_count : FxHashMap < hir:: BodyId , usize > ,
255
260
}
256
261
257
262
#[ derive( Debug , Copy , Clone ) ]
@@ -619,6 +624,13 @@ impl<'tcx> ScopeTree {
619
624
pub fn yield_in_scope ( & self , scope : Scope ) -> Option < ( Span , usize ) > {
620
625
self . yield_in_scope . get ( & scope) . cloned ( )
621
626
}
627
+
628
+ /// Gives the number of expressions visited in a body.
629
+ /// Used to sanity check visit_expr call count when
630
+ /// calculating geneartor interiors.
631
+ pub fn body_expr_count ( & self , body_id : hir:: BodyId ) -> Option < usize > {
632
+ self . body_expr_count . get ( & body_id) . map ( |r| * r)
633
+ }
622
634
}
623
635
624
636
/// Records the lifetime of a local variable as `cx.var_parent`
@@ -1166,6 +1178,10 @@ impl<'a, 'tcx> Visitor<'tcx> for RegionResolutionVisitor<'a, 'tcx> {
1166
1178
resolve_local ( self , None , Some ( & body. value ) ) ;
1167
1179
}
1168
1180
1181
+ if body. is_generator {
1182
+ self . scope_tree . body_expr_count . insert ( body_id, self . expr_count ) ;
1183
+ }
1184
+
1169
1185
// Restore context we had at the start.
1170
1186
self . expr_count = outer_ec;
1171
1187
self . cx = outer_cx;
0 commit comments