@@ -303,12 +303,12 @@ fn cycle_check<'tcx>(query: Lrc<QueryJob<'tcx>>,
303
303
stack : & mut Vec < ( Span , Lrc < QueryJob < ' tcx > > ) > ,
304
304
visited : & mut FxHashSet < * const QueryJob < ' tcx > >
305
305
) -> Option < Option < Waiter < ' tcx > > > {
306
- if visited. contains ( & query. as_ptr ( ) ) {
306
+ if ! visited. insert ( query. as_ptr ( ) ) {
307
307
return if let Some ( p) = stack. iter ( ) . position ( |q| q. 1 . as_ptr ( ) == query. as_ptr ( ) ) {
308
308
// We detected a query cycle, fix up the initial span and return Some
309
309
310
310
// Remove previous stack entries
311
- stack. splice ( 0 ..p, iter :: empty ( ) ) ;
311
+ stack. drain ( 0 ..p) ;
312
312
// Replace the span for the first query with the cycle cause
313
313
stack[ 0 ] . 0 = span;
314
314
Some ( None )
@@ -317,8 +317,7 @@ fn cycle_check<'tcx>(query: Lrc<QueryJob<'tcx>>,
317
317
}
318
318
}
319
319
320
- // Mark this query is visited and add it to the stack
321
- visited. insert ( query. as_ptr ( ) ) ;
320
+ // Query marked as visited is added it to the stack
322
321
stack. push ( ( span, query. clone ( ) ) ) ;
323
322
324
323
// Visit all the waiters
@@ -343,7 +342,7 @@ fn connected_to_root<'tcx>(
343
342
visited : & mut FxHashSet < * const QueryJob < ' tcx > >
344
343
) -> bool {
345
344
// We already visited this or we're deliberately ignoring it
346
- if visited. contains ( & query. as_ptr ( ) ) {
345
+ if ! visited. insert ( query. as_ptr ( ) ) {
347
346
return false ;
348
347
}
349
348
@@ -352,8 +351,6 @@ fn connected_to_root<'tcx>(
352
351
return true ;
353
352
}
354
353
355
- visited. insert ( query. as_ptr ( ) ) ;
356
-
357
354
visit_waiters ( query, |_, successor| {
358
355
if connected_to_root ( successor, visited) {
359
356
Some ( None )
@@ -403,11 +400,9 @@ fn remove_cycle<'tcx>(
403
400
DUMMY_SP ,
404
401
& mut stack,
405
402
& mut visited) {
406
- // Reverse the stack so earlier entries require later entries
407
- stack. reverse ( ) ;
408
-
409
- // The stack is a vector of pairs of spans and queries
410
- let ( mut spans, queries) : ( Vec < _ > , Vec < _ > ) = stack. into_iter ( ) . unzip ( ) ;
403
+ // The stack is a vector of pairs of spans and queries; reverse it so that
404
+ // the earlier entries require later entries
405
+ let ( mut spans, queries) : ( Vec < _ > , Vec < _ > ) = stack. into_iter ( ) . rev ( ) . unzip ( ) ;
411
406
412
407
// Shift the spans so that queries are matched with the span for their waitee
413
408
spans. rotate_right ( 1 ) ;
@@ -424,7 +419,7 @@ fn remove_cycle<'tcx>(
424
419
425
420
// Find the queries in the cycle which are
426
421
// connected to queries outside the cycle
427
- let entry_points: Vec < _ > = stack. iter ( ) . filter_map ( |( span, query) | {
422
+ let entry_points = stack. iter ( ) . filter_map ( |( span, query) | {
428
423
if query. parent . is_none ( ) {
429
424
// This query is connected to the root (it has no query parent)
430
425
Some ( ( * span, query. clone ( ) , None ) )
@@ -449,10 +444,7 @@ fn remove_cycle<'tcx>(
449
444
Some ( ( * span, query. clone ( ) , Some ( waiter) ) )
450
445
}
451
446
}
452
- } ) . collect ( ) ;
453
-
454
- let entry_points: Vec < ( Span , Lrc < QueryJob < ' tcx > > , Option < ( Span , Lrc < QueryJob < ' tcx > > ) > ) >
455
- = entry_points;
447
+ } ) . collect :: < Vec < ( Span , Lrc < QueryJob < ' tcx > > , Option < ( Span , Lrc < QueryJob < ' tcx > > ) > ) > > ( ) ;
456
448
457
449
// Deterministically pick an entry point
458
450
let ( _, entry_point, usage) = pick_query ( tcx, & entry_points, |e| ( e. 0 , e. 1 . clone ( ) ) ) ;
0 commit comments