@@ -130,6 +130,16 @@ impl LocalizedConstraintGraph {
130130 let location = liveness. location_from_point ( node. point ) ;
131131 visitor. on_node_traversed ( loan_idx, node) ;
132132
133+ // When we find a _new_ successor, we'd like to
134+ // - visit it eventually,
135+ // - and let the generic visitor know about it.
136+ let mut successor_found = |succ| {
137+ if !visited. contains ( & succ) {
138+ stack. push ( succ) ;
139+ visitor. on_successor_discovered ( node, succ) ;
140+ }
141+ } ;
142+
133143 // Then, we propagate the loan along the localized constraint graph. The outgoing
134144 // edges are computed lazily, from:
135145 // - the various physical edges present at this node,
@@ -144,10 +154,7 @@ impl LocalizedConstraintGraph {
144154 // 1. the typeck edges that flow from region to region *at this point*.
145155 for & succ in self . edges . get ( & node) . into_iter ( ) . flatten ( ) {
146156 let succ = LocalizedNode { region : succ, point : node. point } ;
147- if !visited. contains ( & succ) {
148- stack. push ( succ) ;
149- visitor. on_successor_discovered ( node, succ) ;
150- }
157+ successor_found ( succ) ;
151158 }
152159
153160 // 2a. the liveness edges that flow *forward*, from this node's point to its
@@ -163,10 +170,7 @@ impl LocalizedConstraintGraph {
163170 live_region_variances,
164171 is_universal_region,
165172 ) {
166- if !visited. contains ( & succ) {
167- stack. push ( succ) ;
168- visitor. on_successor_discovered ( node, succ) ;
169- }
173+ successor_found ( succ) ;
170174 }
171175 } else {
172176 // Inter-block edges, from the block's terminator to each successor block's
@@ -181,10 +185,7 @@ impl LocalizedConstraintGraph {
181185 live_region_variances,
182186 is_universal_region,
183187 ) {
184- if !visited. contains ( & succ) {
185- stack. push ( succ) ;
186- visitor. on_successor_discovered ( node, succ) ;
187- }
188+ successor_found ( succ) ;
188189 }
189190 }
190191 }
@@ -202,10 +203,7 @@ impl LocalizedConstraintGraph {
202203 live_regions,
203204 live_region_variances,
204205 ) {
205- if !visited. contains ( & succ) {
206- stack. push ( succ) ;
207- visitor. on_successor_discovered ( node, succ) ;
208- }
206+ successor_found ( succ) ;
209207 }
210208 } else {
211209 // Backward edges from the block entry point to the terminator of the
@@ -224,10 +222,7 @@ impl LocalizedConstraintGraph {
224222 live_regions,
225223 live_region_variances,
226224 ) {
227- if !visited. contains ( & succ) {
228- stack. push ( succ) ;
229- visitor. on_successor_discovered ( node, succ) ;
230- }
225+ successor_found ( succ) ;
231226 }
232227 }
233228 }
@@ -236,10 +231,7 @@ impl LocalizedConstraintGraph {
236231 // And finally, we have the logical edges, materialized at this point.
237232 for & logical_succ in self . logical_edges . get ( & node. region ) . into_iter ( ) . flatten ( ) {
238233 let succ = LocalizedNode { region : logical_succ, point : node. point } ;
239- if !visited. contains ( & succ) {
240- stack. push ( succ) ;
241- visitor. on_successor_discovered ( node, succ) ;
242- }
234+ successor_found ( succ) ;
243235 }
244236 }
245237 }
0 commit comments