Skip to content

Commit 0bb3dc1

Browse files
Zoxcarielb1
authored andcommitted
Mark yields after visiting subexpressions. Never ignore yields for scopes in bindings.
1 parent 0bf7b55 commit 0bb3dc1

File tree

3 files changed

+18
-39
lines changed

3 files changed

+18
-39
lines changed

src/librustc/middle/region.rs

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -822,23 +822,6 @@ fn resolve_expr<'a, 'tcx>(visitor: &mut RegionResolutionVisitor<'a, 'tcx>, expr:
822822
// record_superlifetime(new_cx, expr.callee_id);
823823
}
824824

825-
hir::ExprYield(..) => {
826-
// Mark this expr's scope and all parent scopes as containing `yield`.
827-
let mut scope = Scope::Node(expr.hir_id.local_id);
828-
loop {
829-
visitor.scope_tree.yield_in_scope.insert(scope,
830-
(expr.span, visitor.expr_count));
831-
832-
// Keep traversing up while we can.
833-
match visitor.scope_tree.parent_map.get(&scope) {
834-
// Don't cross from closure bodies to their parent.
835-
Some(&Scope::CallSite(_)) => break,
836-
Some(&superscope) => scope = superscope,
837-
None => break
838-
}
839-
}
840-
}
841-
842825
_ => {}
843826
}
844827
}
@@ -854,6 +837,23 @@ fn resolve_expr<'a, 'tcx>(visitor: &mut RegionResolutionVisitor<'a, 'tcx>, expr:
854837
_ => intravisit::walk_expr(visitor, expr)
855838
}
856839

840+
if let hir::ExprYield(..) = expr.node {
841+
// Mark this expr's scope and all parent scopes as containing `yield`.
842+
let mut scope = Scope::Node(expr.hir_id.local_id);
843+
loop {
844+
visitor.scope_tree.yield_in_scope.insert(scope,
845+
(expr.span, visitor.expr_count));
846+
847+
// Keep traversing up while we can.
848+
match visitor.scope_tree.parent_map.get(&scope) {
849+
// Don't cross from closure bodies to their parent.
850+
Some(&Scope::CallSite(_)) => break,
851+
Some(&superscope) => scope = superscope,
852+
None => break
853+
}
854+
}
855+
}
856+
857857
visitor.cx = prev_cx;
858858
}
859859

src/librustc_typeck/check/generator_interior.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ impl<'a, 'gcx, 'tcx> InteriorVisitor<'a, 'gcx, 'tcx> {
3636
let live_across_yield = scope.map_or(Some(DUMMY_SP), |s| {
3737
self.region_scope_tree.yield_in_scope(s).and_then(|(span, expr_count)| {
3838
// Check if the span in the region comes after the expression
39-
if expr_count > self.expr_count {
39+
if expr.is_none() || expr_count >= self.expr_count {
4040
Some(span)
4141
} else {
4242
None

src/test/run-pass/generator/borrow-in-yield-expr.rs

Lines changed: 0 additions & 21 deletions
This file was deleted.

0 commit comments

Comments
 (0)