@@ -89,10 +89,8 @@ impl<'tcx> NormalizesToTermHack<'tcx> {
8989pub struct InspectCandidate < ' a , ' tcx > {
9090 goal : & ' a InspectGoal < ' a , ' tcx > ,
9191 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 > > > ,
9493 final_state : inspect:: CanonicalState < TyCtxt < ' tcx > , ( ) > ,
95- impl_args : Option < inspect:: CanonicalState < TyCtxt < ' tcx > , ty:: GenericArgsRef < ' tcx > > > ,
9694 result : QueryResult < ' tcx > ,
9795 shallow_certainty : Certainty ,
9896}
@@ -148,7 +146,7 @@ impl<'a, 'tcx> InspectCandidate<'a, 'tcx> {
148146 #[ instrument(
149147 level = "debug" ,
150148 skip_all,
151- fields( goal = ?self . goal. goal, nested_goals = ?self . nested_goals )
149+ fields( goal = ?self . goal. goal, steps = ?self . steps )
152150 ) ]
153151 pub fn instantiate_nested_goals_and_opt_impl_args (
154152 & self ,
@@ -157,22 +155,35 @@ impl<'a, 'tcx> InspectCandidate<'a, 'tcx> {
157155 let infcx = self . goal . infcx ;
158156 let param_env = self . goal . goal . param_env ;
159157 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,
166165 canonical:: instantiate_canonical_state (
167166 infcx,
168167 span,
169168 param_env,
170169 & mut orig_values,
171- * goal,
170+ goal,
172171 ) ,
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 :: EvaluateGoals ( _)
184+ | inspect:: ProbeStep :: NestedProbe ( _) => unreachable ! ( ) ,
185+ }
186+ }
176187
177188 let ( ) = canonical:: instantiate_canonical_state (
178189 infcx,
@@ -182,24 +193,16 @@ impl<'a, 'tcx> InspectCandidate<'a, 'tcx> {
182193 self . final_state ,
183194 ) ;
184195
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-
196196 if let Some ( term_hack) = self . goal . normalizes_to_term_hack {
197197 // FIXME: We ignore the expected term of `NormalizesTo` goals
198198 // when computing the result of its candidates. This is
199199 // scuffed.
200200 let _ = term_hack. constrain ( infcx, span, param_env) ;
201201 }
202202
203+ let opt_impl_args =
204+ opt_impl_args. map ( |impl_args| impl_args. fold_with ( & mut EagerResolver :: new ( infcx) ) ) ;
205+
203206 let goals = instantiated_goals
204207 . into_iter ( )
205208 . map ( |( source, goal) | match goal. predicate . kind ( ) . no_bound_vars ( ) {
@@ -249,7 +252,7 @@ impl<'a, 'tcx> InspectCandidate<'a, 'tcx> {
249252 } )
250253 . collect ( ) ;
251254
252- ( goals, impl_args )
255+ ( goals, opt_impl_args )
253256 }
254257
255258 /// Visit all nested goals of this candidate, rolling back
@@ -279,17 +282,20 @@ impl<'a, 'tcx> InspectGoal<'a, 'tcx> {
279282 fn candidates_recur (
280283 & ' a self ,
281284 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 > > ,
285+ steps : & mut Vec < & ' a inspect:: ProbeStep < TyCtxt < ' tcx > > > ,
286+ probe : & ' a inspect:: Probe < TyCtxt < ' tcx > > ,
287287 ) {
288288 let mut shallow_certainty = None ;
289- let mut impl_args = None ;
290289 for step in & probe. steps {
291290 match * step {
292- inspect:: ProbeStep :: AddGoal ( source, goal) => nested_goals. push ( ( source, goal) ) ,
291+ inspect:: ProbeStep :: AddGoal ( ..) | inspect:: ProbeStep :: RecordImplArgs { .. } => {
292+ steps. push ( step)
293+ }
294+ inspect:: ProbeStep :: MakeCanonicalResponse { shallow_certainty : c } => {
295+ assert_eq ! ( shallow_certainty. replace( c) , None ) ;
296+ }
297+ // We ignore evaluate goals steps for no.
298+ inspect:: ProbeStep :: EvaluateGoals ( _) => { }
293299 inspect:: ProbeStep :: NestedProbe ( ref probe) => {
294300 match probe. kind {
295301 // These never assemble candidates for the goal we're trying to solve.
@@ -305,19 +311,12 @@ impl<'a, 'tcx> InspectGoal<'a, 'tcx> {
305311 // Nested probes have to prove goals added in their parent
306312 // but do not leak them, so we truncate the added goals
307313 // afterwards.
308- let num_goals = nested_goals . len ( ) ;
309- self . candidates_recur ( candidates, nested_goals , probe) ;
310- nested_goals . truncate ( num_goals ) ;
314+ let num_steps = steps . len ( ) ;
315+ self . candidates_recur ( candidates, steps , probe) ;
316+ steps . truncate ( num_steps ) ;
311317 }
312318 }
313319 }
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- inspect:: ProbeStep :: EvaluateGoals ( _) => ( ) ,
321320 }
322321 }
323322
@@ -339,11 +338,10 @@ impl<'a, 'tcx> InspectGoal<'a, 'tcx> {
339338 candidates. push ( InspectCandidate {
340339 goal : self ,
341340 kind : probe. kind ,
342- nested_goals : nested_goals . clone ( ) ,
341+ steps : steps . clone ( ) ,
343342 final_state : probe. final_state ,
344- result,
345343 shallow_certainty,
346- impl_args ,
344+ result ,
347345 } ) ;
348346 }
349347 }
0 commit comments