1
1
use crate :: check:: FnCtxt ;
2
2
use rustc_data_structures:: {
3
- fx:: FxHashMap , graph:: vec_graph:: VecGraph , graph:: WithSuccessors , stable_set:: FxHashSet ,
3
+ fx:: FxHashMap ,
4
+ graph:: WithSuccessors ,
5
+ graph:: { iterate:: DepthFirstSearch , vec_graph:: VecGraph } ,
6
+ stable_set:: FxHashSet ,
4
7
} ;
5
8
use rustc_middle:: ty:: { self , Ty } ;
6
9
@@ -275,7 +278,7 @@ impl<'tcx> FnCtxt<'_, 'tcx> {
275
278
// type variable. These will typically default to `!`, unless
276
279
// we find later that they are *also* reachable from some
277
280
// other type variable outside this set.
278
- let mut roots_reachable_from_diverging = FxHashSet :: default ( ) ;
281
+ let mut roots_reachable_from_diverging = DepthFirstSearch :: new ( & coercion_graph ) ;
279
282
let mut diverging_vids = vec ! [ ] ;
280
283
let mut non_diverging_vids = vec ! [ ] ;
281
284
for unsolved_vid in unsolved_vids {
@@ -288,16 +291,21 @@ impl<'tcx> FnCtxt<'_, 'tcx> {
288
291
) ;
289
292
if diverging_roots. contains ( & root_vid) {
290
293
diverging_vids. push ( unsolved_vid) ;
294
+ roots_reachable_from_diverging. push_start_node ( root_vid) ;
295
+
291
296
debug ! (
292
297
"calculate_diverging_fallback: root_vid={:?} reaches {:?}" ,
293
298
root_vid,
294
299
coercion_graph. depth_first_search( root_vid) . collect:: <Vec <_>>( )
295
300
) ;
296
- roots_reachable_from_diverging. extend ( coercion_graph. depth_first_search ( root_vid) ) ;
301
+
302
+ // drain the iterator to visit all nodes reachable from this node
303
+ roots_reachable_from_diverging. complete_search ( ) ;
297
304
} else {
298
305
non_diverging_vids. push ( unsolved_vid) ;
299
306
}
300
307
}
308
+
301
309
debug ! (
302
310
"calculate_diverging_fallback: roots_reachable_from_diverging={:?}" ,
303
311
roots_reachable_from_diverging,
@@ -307,13 +315,14 @@ impl<'tcx> FnCtxt<'_, 'tcx> {
307
315
// diverging variable, and then compute the set reachable from
308
316
// N0, which we call N. These are the *non-diverging* type
309
317
// variables. (Note that this set consists of "root variables".)
310
- let mut roots_reachable_from_non_diverging = FxHashSet :: default ( ) ;
318
+ let mut roots_reachable_from_non_diverging = DepthFirstSearch :: new ( & coercion_graph ) ;
311
319
for & non_diverging_vid in & non_diverging_vids {
312
320
let root_vid = self . infcx . root_var ( non_diverging_vid) ;
313
- if roots_reachable_from_diverging. contains ( & root_vid) {
321
+ if roots_reachable_from_diverging. visited ( root_vid) {
314
322
continue ;
315
323
}
316
- roots_reachable_from_non_diverging. extend ( coercion_graph. depth_first_search ( root_vid) ) ;
324
+ roots_reachable_from_non_diverging. push_start_node ( root_vid) ;
325
+ roots_reachable_from_non_diverging. complete_search ( ) ;
317
326
}
318
327
debug ! (
319
328
"calculate_diverging_fallback: roots_reachable_from_non_diverging={:?}" ,
@@ -329,7 +338,7 @@ impl<'tcx> FnCtxt<'_, 'tcx> {
329
338
let root_vid = self . infcx . root_var ( diverging_vid) ;
330
339
let can_reach_non_diverging = coercion_graph
331
340
. depth_first_search ( root_vid)
332
- . any ( |n| roots_reachable_from_non_diverging. contains ( & n) ) ;
341
+ . any ( |n| roots_reachable_from_non_diverging. visited ( n) ) ;
333
342
if can_reach_non_diverging {
334
343
debug ! ( "fallback to (): {:?}" , diverging_vid) ;
335
344
diverging_fallback. insert ( diverging_ty, self . tcx . types . unit ) ;
0 commit comments