Skip to content

Commit 9d0960a

Browse files
committed
Fix HIR visit order
Fixes #61442 When rustc::middle::region::ScopeTree ccomputes its yield_in_scope field, it relies on the HIR visitor order to properly compute which types must be live across yield points. In order for the computed scopes to agree with the generated MIR, we must ensure that expressions evaluated before a yield point are visited before the 'yield' expression. However, the visitor order for ExprKind::AssignOp was incorrect. The left-hand side of a compund assignment expression is evaluated before the right-hand side, but the right-hand expression was being visited before the left-hand expression. If the left-hand expression caused a new type to be introduced (e.g. through a deref-coercion), the new type would be incorrectly seen as occuring *after* the yield point, instead of before. This leads to a mismatch between the computed generator types and the MIR, since the MIR will correctly see the type as being live across the yield point. To fix this, we correct the visitor order for ExprKind::AssignOp to reflect the actual evaulation order.
1 parent 4a365a2 commit 9d0960a

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

src/librustc/hir/intravisit.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1055,8 +1055,8 @@ pub fn walk_expr<'v, V: Visitor<'v>>(visitor: &mut V, expression: &'v Expr) {
10551055
visitor.visit_expr(left_hand_expression)
10561056
}
10571057
ExprKind::AssignOp(_, ref left_expression, ref right_expression) => {
1058+
visitor.visit_expr(left_expression);
10581059
visitor.visit_expr(right_expression);
1059-
visitor.visit_expr(left_expression)
10601060
}
10611061
ExprKind::Field(ref subexpression, ident) => {
10621062
visitor.visit_expr(subexpression);
+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#![feature(generators)]
2+
3+
fn foo() {
4+
let _x = static || {
5+
let mut s = String::new();
6+
s += { yield; "" };
7+
};
8+
}
9+
10+
fn main() {
11+
foo()
12+
}

0 commit comments

Comments
 (0)