@@ -123,9 +123,11 @@ impl<'tcx> QueryJob<'tcx> {
123
123
let mut cycle = Vec :: new ( ) ;
124
124
125
125
while let Some ( job) = current_job {
126
- cycle. insert ( 0 , job. info . clone ( ) ) ;
126
+ cycle. push ( job. info . clone ( ) ) ;
127
127
128
128
if ptr:: eq ( & * job, self ) {
129
+ cycle. reverse ( ) ;
130
+
129
131
// This is the end of the cycle
130
132
// The span entry we included was for the usage
131
133
// of the cycle itself, and not part of the cycle
@@ -368,13 +370,11 @@ fn remove_cycle<'tcx>(
368
370
// Reverse the stack so earlier entries require later entries
369
371
stack. reverse ( ) ;
370
372
371
- // Extract the spans and queries into separate arrays
372
- let mut spans: Vec < _ > = stack. iter ( ) . map ( |e| e. 0 ) . collect ( ) ;
373
- let queries = stack. into_iter ( ) . map ( |e| e. 1 ) ;
373
+ // The stack is a vector of pairs of spans and queries
374
+ let ( mut spans, queries) : ( Vec < _ > , Vec < _ > ) = stack. into_iter ( ) . unzip ( ) ;
374
375
375
376
// Shift the spans so that queries are matched with the span for their waitee
376
- let last = spans. pop ( ) . unwrap ( ) ;
377
- spans. insert ( 0 , last) ;
377
+ spans. rotate_right ( 1 ) ;
378
378
379
379
// Zip them back together
380
380
let mut stack: Vec < _ > = spans. into_iter ( ) . zip ( queries) . collect ( ) ;
@@ -414,10 +414,10 @@ fn remove_cycle<'tcx>(
414
414
stable_hasher. finish ( )
415
415
} ) . unwrap ( ) . as_ptr ( ) ;
416
416
417
- // Shift the stack until our entry point is first
418
- while stack[ 0 ] . 1 . as_ptr ( ) != entry_point {
419
- let last = stack . pop ( ) . unwrap ( ) ;
420
- stack. insert ( 0 , last ) ;
417
+ // Shift the stack so that our entry point is first
418
+ let entry_point_pos = stack. iter ( ) . position ( | ( _ , query ) | query . as_ptr ( ) == entry_point) ;
419
+ if let Some ( pos ) = entry_point_pos {
420
+ stack. rotate_right ( pos ) ;
421
421
}
422
422
423
423
// Create the cycle error
0 commit comments