11use std:: io:: Write ;
2- use std:: iter;
32use std:: ops:: ControlFlow ;
43use std:: sync:: Arc ;
4+ use std:: { iter, mem} ;
55
66use rustc_data_structures:: fx:: { FxHashMap , FxHashSet } ;
77use rustc_errors:: { Diag , DiagCtxtHandle } ;
@@ -88,8 +88,8 @@ pub(crate) fn find_cycle_in_stack<'tcx>(
8888 panic ! ( "did not find a cycle" )
8989}
9090
91- /// Finds the job closest to the root with a `DepKind` matching the `DepKind` of `id` and returns
92- /// information about it.
91+ /// Finds the query job closest to the root that is for the same query method as `id`
92+ /// (but not necessarily the same query key), and returns information about it.
9393#[ cold]
9494#[ inline( never) ]
9595pub ( crate ) fn find_dep_kind_root < ' tcx > (
@@ -99,12 +99,14 @@ pub(crate) fn find_dep_kind_root<'tcx>(
9999) -> ( Span , String , usize ) {
100100 let mut depth = 1 ;
101101 let mut info = & job_map. map [ & id] ;
102- let dep_kind = info. frame . dep_kind ;
102+ // Two query stack frames are for the same query method if they have the same
103+ // `TaggedQueryKey` discriminant.
104+ let expected_query = mem:: discriminant ( & info. frame . tagged_key ) ;
103105 let mut last_info = info;
104106
105107 while let Some ( id) = info. job . parent {
106108 info = & job_map. map [ & id] ;
107- if info. frame . dep_kind == dep_kind {
109+ if mem :: discriminant ( & info. frame . tagged_key ) == expected_query {
108110 depth += 1 ;
109111 last_info = info;
110112 }
@@ -420,8 +422,8 @@ pub fn print_query_stack<'tcx>(
420422 if Some ( count_printed) < limit_frames || limit_frames. is_none ( ) {
421423 // Only print to stderr as many stack frames as `num_frames` when present.
422424 dcx. struct_failure_note ( format ! (
423- "#{} [{:? }] {}" ,
424- count_printed , query_info. frame. dep_kind , description
425+ "#{count_printed } [{query_name }] {description }" ,
426+ query_name = query_info. frame. tagged_key . query_name ( ) ,
425427 ) )
426428 . with_span ( query_info. job . span )
427429 . emit ( ) ;
@@ -431,8 +433,8 @@ pub fn print_query_stack<'tcx>(
431433 if let Some ( ref mut file) = file {
432434 let _ = writeln ! (
433435 file,
434- "#{} [{:? }] {}" ,
435- count_total , query_info. frame. dep_kind , description
436+ "#{count_total } [{query_name }] {description }" ,
437+ query_name = query_info. frame. tagged_key . query_name ( ) ,
436438 ) ;
437439 }
438440
0 commit comments