File tree Expand file tree Collapse file tree 5 files changed +52
-5
lines changed
rustc_error_messages/locales/en-US Expand file tree Collapse file tree 5 files changed +52
-5
lines changed Original file line number Diff line number Diff line change @@ -23,3 +23,5 @@ query_system_cycle_recursive_trait_alias = trait aliases cannot be recursive
2323query_system_cycle_which_requires = ...which requires { $desc } ...
2424
2525query_system_query_overflow = queries overflow the depth limit!
26+
27+ query_system_layout_of_depth = Query depth increased by { $depth } when { $desc } !
Original file line number Diff line number Diff line change @@ -109,7 +109,7 @@ impl QueryContext for QueryCtxt<'_> {
109109 // when accessing the `ImplicitCtxt`.
110110 tls:: with_related_context ( * * self , move |current_icx| {
111111 if depth_limit && !self . recursion_limit ( ) . value_within_limit ( current_icx. query_depth ) {
112- self . depth_limit_error ( ) ;
112+ self . depth_limit_error ( token ) ;
113113 }
114114
115115 // Update the `ImplicitCtxt` to point to our new query job.
Original file line number Diff line number Diff line change @@ -77,4 +77,16 @@ pub struct IncrementCompilation {
7777
7878#[ derive( SessionDiagnostic ) ]
7979#[ diag( query_system:: query_overflow) ]
80- pub struct QueryOverflow ;
80+ pub struct QueryOverflow {
81+ #[ subdiagnostic]
82+ pub layout_of_depth : Option < LayoutOfDepth > ,
83+ }
84+
85+ #[ derive( SessionSubdiagnostic ) ]
86+ #[ note( query_system:: layout_of_depth) ]
87+ pub struct LayoutOfDepth {
88+ #[ primary_span]
89+ pub span : Span ,
90+ pub desc : String ,
91+ pub depth : usize ,
92+ }
Original file line number Diff line number Diff line change @@ -59,6 +59,7 @@ impl QueryJobId {
5959 }
6060}
6161
62+ #[ derive( Clone ) ]
6263pub struct QueryJobInfo {
6364 pub query : QueryStackFrame ,
6465 pub job : QueryJob ,
@@ -116,10 +117,10 @@ impl QueryJob {
116117 }
117118}
118119
119- #[ cfg( not( parallel_compiler) ) ]
120120impl QueryJobId {
121121 #[ cold]
122122 #[ inline( never) ]
123+ #[ cfg( not( parallel_compiler) ) ]
123124 pub ( super ) fn find_cycle_in_stack (
124125 & self ,
125126 query_map : QueryMap ,
@@ -156,6 +157,27 @@ impl QueryJobId {
156157
157158 panic ! ( "did not find a cycle" )
158159 }
160+
161+ #[ cold]
162+ #[ inline( never) ]
163+ pub ( super ) fn try_find_layout_root (
164+ & self ,
165+ query_map : QueryMap ,
166+ ) -> Option < ( QueryJobInfo , usize ) > {
167+ let mut last_layout = None ;
168+ let mut current_id = Some ( * self ) ;
169+ let mut depth = 0 ;
170+
171+ while let Some ( id) = current_id {
172+ let info = query_map. get ( & id) . unwrap ( ) ;
173+ if info. query . name == "layout_of" {
174+ depth += 1 ;
175+ last_layout = Some ( ( info. clone ( ) , depth) ) ;
176+ }
177+ current_id = info. job . parent ;
178+ }
179+ last_layout
180+ }
159181}
160182
161183#[ cfg( parallel_compiler) ]
Original file line number Diff line number Diff line change @@ -123,7 +123,18 @@ pub trait QueryContext: HasDepContext {
123123 compute : impl FnOnce ( ) -> R ,
124124 ) -> R ;
125125
126- fn depth_limit_error ( & self ) {
127- self . dep_context ( ) . sess ( ) . emit_fatal ( crate :: error:: QueryOverflow ) ;
126+ fn depth_limit_error ( & self , job : QueryJobId ) {
127+ let sess = self . dep_context ( ) . sess ( ) ;
128+ let mut layout_of_depth = None ;
129+ if let Some ( map) = self . try_collect_active_jobs ( ) {
130+ if let Some ( ( info, depth) ) = job. try_find_layout_root ( map) {
131+ layout_of_depth = Some ( crate :: error:: LayoutOfDepth {
132+ span : info. job . span ,
133+ desc : info. query . description ,
134+ depth,
135+ } ) ;
136+ }
137+ }
138+ sess. emit_fatal ( crate :: error:: QueryOverflow { layout_of_depth } ) ;
128139 }
129140}
You can’t perform that action at this time.
0 commit comments