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
@@ -280,7 +283,7 @@ impl<'tcx> FnCtxt<'_, 'tcx> {
280
283
// type variable. These will typically default to `!`, unless
281
284
// we find later that they are *also* reachable from some
282
285
// other type variable outside this set.
283
- let mut roots_reachable_from_diverging = FxHashSet :: default ( ) ;
286
+ let mut roots_reachable_from_diverging = DepthFirstSearch :: new ( & coercion_graph ) ;
284
287
let mut diverging_vids = vec ! [ ] ;
285
288
let mut non_diverging_vids = vec ! [ ] ;
286
289
for unsolved_vid in unsolved_vids {
@@ -293,16 +296,21 @@ impl<'tcx> FnCtxt<'_, 'tcx> {
293
296
) ;
294
297
if diverging_roots. contains ( & root_vid) {
295
298
diverging_vids. push ( unsolved_vid) ;
299
+ roots_reachable_from_diverging. push_start_node ( root_vid) ;
300
+
296
301
debug ! (
297
302
"calculate_diverging_fallback: root_vid={:?} reaches {:?}" ,
298
303
root_vid,
299
304
coercion_graph. depth_first_search( root_vid) . collect:: <Vec <_>>( )
300
305
) ;
301
- roots_reachable_from_diverging. extend ( coercion_graph. depth_first_search ( root_vid) ) ;
306
+
307
+ // drain the iterator to visit all nodes reachable from this node
308
+ roots_reachable_from_diverging. complete_search ( ) ;
302
309
} else {
303
310
non_diverging_vids. push ( unsolved_vid) ;
304
311
}
305
312
}
313
+
306
314
debug ! (
307
315
"calculate_diverging_fallback: roots_reachable_from_diverging={:?}" ,
308
316
roots_reachable_from_diverging,
@@ -312,13 +320,14 @@ impl<'tcx> FnCtxt<'_, 'tcx> {
312
320
// diverging variable, and then compute the set reachable from
313
321
// N0, which we call N. These are the *non-diverging* type
314
322
// variables. (Note that this set consists of "root variables".)
315
- let mut roots_reachable_from_non_diverging = FxHashSet :: default ( ) ;
323
+ let mut roots_reachable_from_non_diverging = DepthFirstSearch :: new ( & coercion_graph ) ;
316
324
for & non_diverging_vid in & non_diverging_vids {
317
325
let root_vid = self . infcx . root_var ( non_diverging_vid) ;
318
- if roots_reachable_from_diverging. contains ( & root_vid) {
326
+ if roots_reachable_from_diverging. visited ( root_vid) {
319
327
continue ;
320
328
}
321
- roots_reachable_from_non_diverging. extend ( coercion_graph. depth_first_search ( root_vid) ) ;
329
+ roots_reachable_from_non_diverging. push_start_node ( root_vid) ;
330
+ roots_reachable_from_non_diverging. complete_search ( ) ;
322
331
}
323
332
debug ! (
324
333
"calculate_diverging_fallback: roots_reachable_from_non_diverging={:?}" ,
@@ -334,7 +343,7 @@ impl<'tcx> FnCtxt<'_, 'tcx> {
334
343
let root_vid = self . infcx . root_var ( diverging_vid) ;
335
344
let can_reach_non_diverging = coercion_graph
336
345
. depth_first_search ( root_vid)
337
- . any ( |n| roots_reachable_from_non_diverging. contains ( & n) ) ;
346
+ . any ( |n| roots_reachable_from_non_diverging. visited ( n) ) ;
338
347
if can_reach_non_diverging {
339
348
debug ! ( "fallback to (): {:?}" , diverging_vid) ;
340
349
diverging_fallback. insert ( diverging_ty, self . tcx . types . unit ) ;
0 commit comments