File tree 5 files changed +52
-5
lines changed
rustc_error_messages/locales/en-US 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
23
23
query_system_cycle_which_requires = ...which requires { $desc } ...
24
24
25
25
query_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<'_> {
109
109
// when accessing the `ImplicitCtxt`.
110
110
tls:: with_related_context ( * * self , move |current_icx| {
111
111
if depth_limit && !self . recursion_limit ( ) . value_within_limit ( current_icx. query_depth ) {
112
- self . depth_limit_error ( ) ;
112
+ self . depth_limit_error ( token ) ;
113
113
}
114
114
115
115
// 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 {
77
77
78
78
#[ derive( SessionDiagnostic ) ]
79
79
#[ 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 {
59
59
}
60
60
}
61
61
62
+ #[ derive( Clone ) ]
62
63
pub struct QueryJobInfo {
63
64
pub query : QueryStackFrame ,
64
65
pub job : QueryJob ,
@@ -116,10 +117,10 @@ impl QueryJob {
116
117
}
117
118
}
118
119
119
- #[ cfg( not( parallel_compiler) ) ]
120
120
impl QueryJobId {
121
121
#[ cold]
122
122
#[ inline( never) ]
123
+ #[ cfg( not( parallel_compiler) ) ]
123
124
pub ( super ) fn find_cycle_in_stack (
124
125
& self ,
125
126
query_map : QueryMap ,
@@ -156,6 +157,27 @@ impl QueryJobId {
156
157
157
158
panic ! ( "did not find a cycle" )
158
159
}
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
+ }
159
181
}
160
182
161
183
#[ cfg( parallel_compiler) ]
Original file line number Diff line number Diff line change @@ -123,7 +123,18 @@ pub trait QueryContext: HasDepContext {
123
123
compute : impl FnOnce ( ) -> R ,
124
124
) -> R ;
125
125
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 } ) ;
128
139
}
129
140
}
You can’t perform that action at this time.
0 commit comments