Skip to content

Commit 62b1e65

Browse files
committed
Ensure that all statements in block are visited not just successors of a block.
1 parent 9c63714 commit 62b1e65

File tree

1 file changed

+18
-8
lines changed

1 file changed

+18
-8
lines changed

src/librustc_mir/dataflow/impls/borrows.rs

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@ fn precompute_borrows_out_of_scope<'a, 'tcx>(
6666
let mut visited = FxHashSet();
6767
visited.insert(location);
6868

69-
debug!("borrow {:?} starts at {:?}", borrow_index, location);
70-
69+
debug!("borrow {:?} (region: {:?}) starts at {:?}",
70+
borrow_index, borrow_region, location);
7171
while let Some(location) = stack.pop() {
7272
// If region does not contain a point at the location, then add to list and skip
7373
// successor locations.
@@ -80,15 +80,25 @@ fn precompute_borrows_out_of_scope<'a, 'tcx>(
8080
continue;
8181
}
8282

83-
// Add successors to locations to visit, if not visited before.
8483
let bb_data = &mir[location.block];
85-
if let Some(ref terminator) = bb_data.terminator {
86-
for block in terminator.successors() {
87-
let loc = block.start_location();
88-
if visited.insert(loc) {
89-
stack.push(loc);
84+
// If this is the last statement in the block, then add the
85+
// terminator successors next.
86+
if location.statement_index == bb_data.statements.len() - 1 {
87+
// Add successors to locations to visit, if not visited before.
88+
if let Some(ref terminator) = bb_data.terminator {
89+
for block in terminator.successors() {
90+
let loc = block.start_location();
91+
if visited.insert(loc) {
92+
stack.push(loc);
93+
}
9094
}
9195
}
96+
} else {
97+
// Visit next statement in block.
98+
let loc = location.successor_within_block();
99+
if visited.insert(loc) {
100+
stack.push(loc);
101+
}
92102
}
93103
}
94104
}

0 commit comments

Comments
 (0)