@@ -376,15 +376,7 @@ struct RegionResolutionVisitor<'tcx> {
376376 // up their indices.
377377 pessimistic_yield : bool ,
378378 // 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 > ,
388380 // Generated scope tree:
389381 scope_tree : ScopeTree ,
390382
@@ -1020,29 +1012,28 @@ fn resolve_expr<'tcx>(visitor: &mut RegionResolutionVisitor<'tcx>, expr: &'tcx h
10201012 let body = visitor. tcx . hir ( ) . body ( body) ;
10211013 visitor. visit_body ( body) ;
10221014 } ,
1023- hir:: ExprKind :: AssignOp ( _, ref left_expression , ref right_expression ) => {
1015+ hir:: ExprKind :: AssignOp ( _, ref left_expr , ref right_expr ) => {
10241016 debug ! ( "resolve_expr - enabling pessimistic_yield, was previously {}" ,
10251017 prev_pessimistic) ;
10261018
1027- visitor. fixup_scopes . push ( vec ! [ ] ) ;
1019+ let start_point = visitor. fixup_scopes . len ( ) ;
10281020 visitor. pessimistic_yield = true ;
10291021
10301022 // If the actual execution order turns out to be right-to-left,
10311023 // then we're fine. However, if the actual execution order is left-to-right,
10321024 // then we'll assign too low a count to any `yield` expressions
10331025 // we encounter in 'right_expression' - they should really occur after all of the
10341026 // expressions in 'left_expression'.
1035- visitor. visit_expr ( & right_expression) ;
1036-
1027+ visitor. visit_expr ( & right_expr) ;
10371028 visitor. pessimistic_yield = prev_pessimistic;
10381029
1039- let target_scopes = visitor. fixup_scopes . pop ( ) . unwrap ( ) ;
10401030 debug ! ( "resolve_expr - restoring pessimistic_yield to {}" , prev_pessimistic) ;
1041-
1042-
1043- visitor. visit_expr ( & left_expression) ;
1031+ visitor. visit_expr ( & left_expr) ;
10441032 debug ! ( "resolve_expr - fixing up counts to {}" , visitor. expr_and_pat_count) ;
10451033
1034+ // Remove and process any scopes pushed by the visitor
1035+ let target_scopes = visitor. fixup_scopes . drain ( start_point..) ;
1036+
10461037 for scope in target_scopes {
10471038 let mut yield_data = visitor. scope_tree . yield_in_scope . get_mut ( & scope) . unwrap ( ) ;
10481039 let count = yield_data. expr_and_pat_count ;
@@ -1083,7 +1074,7 @@ fn resolve_expr<'tcx>(visitor: &mut RegionResolutionVisitor<'tcx>, expr: &'tcx h
10831074 visitor. scope_tree . yield_in_scope . insert ( scope, data) ;
10841075 if visitor. pessimistic_yield {
10851076 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) ;
10871078 }
10881079
10891080 // Keep traversing up while we can.
0 commit comments