@@ -376,15 +376,7 @@ struct RegionResolutionVisitor<'tcx> {
376
376
// up their indices.
377
377
pessimistic_yield : bool ,
378
378
// Stores scopes when pessimistic_yield is true.
379
- // Each time we encounter an ExprKind::AssignOp, we push
380
- // a new Vec into the outermost Vec. This inner Vec is used
381
- // to store any scopes we encounter when visiting the inner expressions
382
- // of the AssignOp. Once we finish visiting the inner expressions, we pop
383
- // off the inner Vec, and process the Scopes it contains.
384
- // This allows us to handle nested AssignOps - while a terrible idea,
385
- // they are valid Rust, so we need to handle them.
386
- fixup_scopes : Vec < Vec < Scope > > ,
387
-
379
+ fixup_scopes : Vec < Scope > ,
388
380
// Generated scope tree:
389
381
scope_tree : ScopeTree ,
390
382
@@ -1020,29 +1012,28 @@ fn resolve_expr<'tcx>(visitor: &mut RegionResolutionVisitor<'tcx>, expr: &'tcx h
1020
1012
let body = visitor. tcx . hir ( ) . body ( body) ;
1021
1013
visitor. visit_body ( body) ;
1022
1014
} ,
1023
- hir:: ExprKind :: AssignOp ( _, ref left_expression , ref right_expression ) => {
1015
+ hir:: ExprKind :: AssignOp ( _, ref left_expr , ref right_expr ) => {
1024
1016
debug ! ( "resolve_expr - enabling pessimistic_yield, was previously {}" ,
1025
1017
prev_pessimistic) ;
1026
1018
1027
- visitor. fixup_scopes . push ( vec ! [ ] ) ;
1019
+ let start_point = visitor. fixup_scopes . len ( ) ;
1028
1020
visitor. pessimistic_yield = true ;
1029
1021
1030
1022
// If the actual execution order turns out to be right-to-left,
1031
1023
// then we're fine. However, if the actual execution order is left-to-right,
1032
1024
// then we'll assign too low a count to any `yield` expressions
1033
1025
// we encounter in 'right_expression' - they should really occur after all of the
1034
1026
// expressions in 'left_expression'.
1035
- visitor. visit_expr ( & right_expression) ;
1036
-
1027
+ visitor. visit_expr ( & right_expr) ;
1037
1028
visitor. pessimistic_yield = prev_pessimistic;
1038
1029
1039
- let target_scopes = visitor. fixup_scopes . pop ( ) . unwrap ( ) ;
1040
1030
debug ! ( "resolve_expr - restoring pessimistic_yield to {}" , prev_pessimistic) ;
1041
-
1042
-
1043
- visitor. visit_expr ( & left_expression) ;
1031
+ visitor. visit_expr ( & left_expr) ;
1044
1032
debug ! ( "resolve_expr - fixing up counts to {}" , visitor. expr_and_pat_count) ;
1045
1033
1034
+ // Remove and process any scopes pushed by the visitor
1035
+ let target_scopes = visitor. fixup_scopes . drain ( start_point..) ;
1036
+
1046
1037
for scope in target_scopes {
1047
1038
let mut yield_data = visitor. scope_tree . yield_in_scope . get_mut ( & scope) . unwrap ( ) ;
1048
1039
let count = yield_data. expr_and_pat_count ;
@@ -1083,7 +1074,7 @@ fn resolve_expr<'tcx>(visitor: &mut RegionResolutionVisitor<'tcx>, expr: &'tcx h
1083
1074
visitor. scope_tree . yield_in_scope . insert ( scope, data) ;
1084
1075
if visitor. pessimistic_yield {
1085
1076
debug ! ( "resolve_expr in pessimistic_yield - marking scope {:?} for fixup" , scope) ;
1086
- visitor. fixup_scopes . last_mut ( ) . unwrap ( ) . push ( scope) ;
1077
+ visitor. fixup_scopes . push ( scope) ;
1087
1078
}
1088
1079
1089
1080
// Keep traversing up while we can.
0 commit comments