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.
This commit is contained in:
parent
4a365a29d6
commit
9d0960a6f8
2 changed files with 13 additions and 1 deletions
|
|
@ -1055,8 +1055,8 @@ pub fn walk_expr<'v, V: Visitor<'v>>(visitor: &mut V, expression: &'v Expr) {
|
|||
visitor.visit_expr(left_hand_expression)
|
||||
}
|
||||
ExprKind::AssignOp(_, ref left_expression, ref right_expression) => {
|
||||
visitor.visit_expr(left_expression);
|
||||
visitor.visit_expr(right_expression);
|
||||
visitor.visit_expr(left_expression)
|
||||
}
|
||||
ExprKind::Field(ref subexpression, ident) => {
|
||||
visitor.visit_expr(subexpression);
|
||||
|
|
|
|||
12
src/test/run-pass/issues/issue-61442.rs
Normal file
12
src/test/run-pass/issues/issue-61442.rs
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
#![feature(generators)]
|
||||
|
||||
fn foo() {
|
||||
let _x = static || {
|
||||
let mut s = String::new();
|
||||
s += { yield; "" };
|
||||
};
|
||||
}
|
||||
|
||||
fn main() {
|
||||
foo()
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue