@@ -66,8 +66,8 @@ fn precompute_borrows_out_of_scope<'a, 'tcx>(
66
66
let mut visited = FxHashSet ( ) ;
67
67
visited. insert ( location) ;
68
68
69
- debug ! ( "borrow {:?} starts at {:?}" , borrow_index , location ) ;
70
-
69
+ debug ! ( "borrow {:?} (region: {:?}) starts at {:?}" ,
70
+ borrow_index , borrow_region , location ) ;
71
71
while let Some ( location) = stack. pop ( ) {
72
72
// If region does not contain a point at the location, then add to list and skip
73
73
// successor locations.
@@ -80,15 +80,25 @@ fn precompute_borrows_out_of_scope<'a, 'tcx>(
80
80
continue ;
81
81
}
82
82
83
- // Add successors to locations to visit, if not visited before.
84
83
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
+ }
90
94
}
91
95
}
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
+ }
92
102
}
93
103
}
94
104
}
0 commit comments