@@ -89,10 +89,8 @@ impl<'tcx> NormalizesToTermHack<'tcx> {
89
89
pub struct InspectCandidate < ' a , ' tcx > {
90
90
goal : & ' a InspectGoal < ' a , ' tcx > ,
91
91
kind : inspect:: ProbeKind < TyCtxt < ' tcx > > ,
92
- nested_goals :
93
- Vec < ( GoalSource , inspect:: CanonicalState < TyCtxt < ' tcx > , Goal < ' tcx , ty:: Predicate < ' tcx > > > ) > ,
92
+ steps : Vec < & ' a inspect:: ProbeStep < TyCtxt < ' tcx > > > ,
94
93
final_state : inspect:: CanonicalState < TyCtxt < ' tcx > , ( ) > ,
95
- impl_args : Option < inspect:: CanonicalState < TyCtxt < ' tcx > , ty:: GenericArgsRef < ' tcx > > > ,
96
94
result : QueryResult < ' tcx > ,
97
95
shallow_certainty : Certainty ,
98
96
}
@@ -148,7 +146,7 @@ impl<'a, 'tcx> InspectCandidate<'a, 'tcx> {
148
146
#[ instrument(
149
147
level = "debug" ,
150
148
skip_all,
151
- fields( goal = ?self . goal. goal, nested_goals = ?self . nested_goals )
149
+ fields( goal = ?self . goal. goal, steps = ?self . steps )
152
150
) ]
153
151
pub fn instantiate_nested_goals_and_opt_impl_args (
154
152
& self ,
@@ -157,22 +155,34 @@ impl<'a, 'tcx> InspectCandidate<'a, 'tcx> {
157
155
let infcx = self . goal . infcx ;
158
156
let param_env = self . goal . goal . param_env ;
159
157
let mut orig_values = self . goal . orig_values . to_vec ( ) ;
160
- let instantiated_goals: Vec < _ > = self
161
- . nested_goals
162
- . iter ( )
163
- . map ( |( source, goal) | {
164
- (
165
- * source,
158
+
159
+ let mut instantiated_goals = vec ! [ ] ;
160
+ let mut opt_impl_args = None ;
161
+ for step in & self . steps {
162
+ match * * step {
163
+ inspect:: ProbeStep :: AddGoal ( source, goal) => instantiated_goals. push ( (
164
+ source,
166
165
canonical:: instantiate_canonical_state (
167
166
infcx,
168
167
span,
169
168
param_env,
170
169
& mut orig_values,
171
- * goal,
170
+ goal,
172
171
) ,
173
- )
174
- } )
175
- . collect ( ) ;
172
+ ) ) ,
173
+ inspect:: ProbeStep :: RecordImplArgs { impl_args } => {
174
+ opt_impl_args = Some ( canonical:: instantiate_canonical_state (
175
+ infcx,
176
+ span,
177
+ param_env,
178
+ & mut orig_values,
179
+ impl_args,
180
+ ) ) ;
181
+ }
182
+ inspect:: ProbeStep :: MakeCanonicalResponse { .. }
183
+ | inspect:: ProbeStep :: NestedProbe ( _) => unreachable ! ( ) ,
184
+ }
185
+ }
176
186
177
187
let ( ) = canonical:: instantiate_canonical_state (
178
188
infcx,
@@ -182,24 +192,16 @@ impl<'a, 'tcx> InspectCandidate<'a, 'tcx> {
182
192
self . final_state ,
183
193
) ;
184
194
185
- let impl_args = self . impl_args . map ( |impl_args| {
186
- canonical:: instantiate_canonical_state (
187
- infcx,
188
- span,
189
- param_env,
190
- & mut orig_values,
191
- impl_args,
192
- )
193
- . fold_with ( & mut EagerResolver :: new ( infcx) )
194
- } ) ;
195
-
196
195
if let Some ( term_hack) = self . goal . normalizes_to_term_hack {
197
196
// FIXME: We ignore the expected term of `NormalizesTo` goals
198
197
// when computing the result of its candidates. This is
199
198
// scuffed.
200
199
let _ = term_hack. constrain ( infcx, span, param_env) ;
201
200
}
202
201
202
+ let opt_impl_args =
203
+ opt_impl_args. map ( |impl_args| impl_args. fold_with ( & mut EagerResolver :: new ( infcx) ) ) ;
204
+
203
205
let goals = instantiated_goals
204
206
. into_iter ( )
205
207
. map ( |( source, goal) | match goal. predicate . kind ( ) . no_bound_vars ( ) {
@@ -249,7 +251,7 @@ impl<'a, 'tcx> InspectCandidate<'a, 'tcx> {
249
251
} )
250
252
. collect ( ) ;
251
253
252
- ( goals, impl_args )
254
+ ( goals, opt_impl_args )
253
255
}
254
256
255
257
/// Visit all nested goals of this candidate, rolling back
@@ -279,17 +281,18 @@ impl<'a, 'tcx> InspectGoal<'a, 'tcx> {
279
281
fn candidates_recur (
280
282
& ' a self ,
281
283
candidates : & mut Vec < InspectCandidate < ' a , ' tcx > > ,
282
- nested_goals : & mut Vec < (
283
- GoalSource ,
284
- inspect:: CanonicalState < TyCtxt < ' tcx > , Goal < ' tcx , ty:: Predicate < ' tcx > > > ,
285
- ) > ,
286
- probe : & inspect:: Probe < TyCtxt < ' tcx > > ,
284
+ steps : & mut Vec < & ' a inspect:: ProbeStep < TyCtxt < ' tcx > > > ,
285
+ probe : & ' a inspect:: Probe < TyCtxt < ' tcx > > ,
287
286
) {
288
287
let mut shallow_certainty = None ;
289
- let mut impl_args = None ;
290
288
for step in & probe. steps {
291
289
match * step {
292
- inspect:: ProbeStep :: AddGoal ( source, goal) => nested_goals. push ( ( source, goal) ) ,
290
+ inspect:: ProbeStep :: AddGoal ( ..) | inspect:: ProbeStep :: RecordImplArgs { .. } => {
291
+ steps. push ( step)
292
+ }
293
+ inspect:: ProbeStep :: MakeCanonicalResponse { shallow_certainty : c } => {
294
+ assert_eq ! ( shallow_certainty. replace( c) , None ) ;
295
+ }
293
296
inspect:: ProbeStep :: NestedProbe ( ref probe) => {
294
297
match probe. kind {
295
298
// These never assemble candidates for the goal we're trying to solve.
@@ -305,18 +308,12 @@ impl<'a, 'tcx> InspectGoal<'a, 'tcx> {
305
308
// Nested probes have to prove goals added in their parent
306
309
// but do not leak them, so we truncate the added goals
307
310
// afterwards.
308
- let num_goals = nested_goals . len ( ) ;
309
- self . candidates_recur ( candidates, nested_goals , probe) ;
310
- nested_goals . truncate ( num_goals ) ;
311
+ let num_steps = steps . len ( ) ;
312
+ self . candidates_recur ( candidates, steps , probe) ;
313
+ steps . truncate ( num_steps ) ;
311
314
}
312
315
}
313
316
}
314
- inspect:: ProbeStep :: MakeCanonicalResponse { shallow_certainty : c } => {
315
- assert_eq ! ( shallow_certainty. replace( c) , None ) ;
316
- }
317
- inspect:: ProbeStep :: RecordImplArgs { impl_args : i } => {
318
- assert_eq ! ( impl_args. replace( i) , None ) ;
319
- }
320
317
}
321
318
}
322
319
@@ -338,11 +335,10 @@ impl<'a, 'tcx> InspectGoal<'a, 'tcx> {
338
335
candidates. push ( InspectCandidate {
339
336
goal : self ,
340
337
kind : probe. kind ,
341
- nested_goals : nested_goals . clone ( ) ,
338
+ steps : steps . clone ( ) ,
342
339
final_state : probe. final_state ,
343
- result,
344
340
shallow_certainty,
345
- impl_args ,
341
+ result ,
346
342
} ) ;
347
343
}
348
344
}
0 commit comments