@@ -93,7 +93,10 @@ impl<'tcx> NormalizesToTermHack<'tcx> {
9393pub struct InspectCandidate < ' a , ' tcx > {
9494 goal : & ' a InspectGoal < ' a , ' tcx > ,
9595 kind : inspect:: ProbeKind < ' tcx > ,
96- nested_goals : Vec < ( GoalSource , inspect:: CanonicalState < ' tcx , Goal < ' tcx , ty:: Predicate < ' tcx > > > ) > ,
96+ nested_goals : inspect:: CanonicalState <
97+ ' tcx ,
98+ & ' tcx ty:: List < ( GoalSource , Goal < ' tcx , ty:: Predicate < ' tcx > > ) > ,
99+ > ,
97100 final_state : inspect:: CanonicalState < ' tcx , ( ) > ,
98101 result : QueryResult < ' tcx > ,
99102 shallow_certainty : Certainty ,
@@ -141,23 +144,15 @@ impl<'a, 'tcx> InspectCandidate<'a, 'tcx> {
141144 let infcx = self . goal . infcx ;
142145 let param_env = self . goal . goal . param_env ;
143146 let mut orig_values = self . goal . orig_values . to_vec ( ) ;
144- let instantiated_goals: Vec < _ > = self
145- . nested_goals
146- . iter ( )
147- . map ( |( source, goal) | {
148- (
149- * source,
150- canonical:: instantiate_canonical_state (
151- infcx,
152- span,
153- param_env,
154- & mut orig_values,
155- * goal,
156- ) ,
157- )
158- } )
159- . collect ( ) ;
160-
147+ let instantiated_goals = canonical:: instantiate_canonical_state (
148+ infcx,
149+ span,
150+ param_env,
151+ & mut orig_values,
152+ self . nested_goals ,
153+ ) ;
154+ // FIXME: Should we truncate orig_values back down? Any new infer vars
155+ // between `nested_goals` and `final_state` are definitely unrelated...
161156 let ( ) = canonical:: instantiate_canonical_state (
162157 infcx,
163158 span,
@@ -174,7 +169,7 @@ impl<'a, 'tcx> InspectCandidate<'a, 'tcx> {
174169 }
175170
176171 instantiated_goals
177- . into_iter ( )
172+ . iter ( )
178173 . map ( |( source, goal) | match goal. predicate . kind ( ) . no_bound_vars ( ) {
179174 Some ( ty:: PredicateKind :: NormalizesTo ( ty:: NormalizesTo { alias, term } ) ) => {
180175 let unconstrained_term = match term. unpack ( ) {
@@ -240,27 +235,24 @@ impl<'a, 'tcx> InspectGoal<'a, 'tcx> {
240235 fn candidates_recur (
241236 & ' a self ,
242237 candidates : & mut Vec < InspectCandidate < ' a , ' tcx > > ,
243- nested_goals : & mut Vec < (
244- GoalSource ,
245- inspect:: CanonicalState < ' tcx , Goal < ' tcx , ty:: Predicate < ' tcx > > > ,
246- ) > ,
247238 probe : & inspect:: Probe < ' tcx > ,
248239 ) {
249- let mut shallow_certainty = None ;
240+ let mut shallow_certainty_and_goals = None ;
250241 for step in & probe. steps {
251- match step {
252- & inspect:: ProbeStep :: AddGoal ( source, goal) => nested_goals. push ( ( source, goal) ) ,
242+ match * step {
253243 inspect:: ProbeStep :: NestedProbe ( ref probe) => {
254244 // Nested probes have to prove goals added in their parent
255245 // but do not leak them, so we truncate the added goals
256246 // afterwards.
257- let num_goals = nested_goals. len ( ) ;
258- self . candidates_recur ( candidates, nested_goals, probe) ;
259- nested_goals. truncate ( num_goals) ;
247+ self . candidates_recur ( candidates, probe) ;
260248 }
261- inspect:: ProbeStep :: MakeCanonicalResponse { shallow_certainty : c } => {
262- assert_eq ! ( shallow_certainty. replace( * c) , None ) ;
249+ inspect:: ProbeStep :: MakeCanonicalResponse { shallow_certainty, added_goals } => {
250+ assert_eq ! (
251+ shallow_certainty_and_goals. replace( ( shallow_certainty, added_goals) ) ,
252+ None
253+ ) ;
263254 }
255+ inspect:: ProbeStep :: AddGoal ( ..) => { }
264256 inspect:: ProbeStep :: EvaluateGoals ( _) => ( ) ,
265257 }
266258 }
@@ -278,11 +270,11 @@ impl<'a, 'tcx> InspectGoal<'a, 'tcx> {
278270 | inspect:: ProbeKind :: OpaqueTypeStorageLookup { result } => {
279271 // We only add a candidate if `shallow_certainty` was set, which means
280272 // that we ended up calling `evaluate_added_goals_and_make_canonical_response`.
281- if let Some ( shallow_certainty) = shallow_certainty {
273+ if let Some ( ( shallow_certainty, nested_goals ) ) = shallow_certainty_and_goals {
282274 candidates. push ( InspectCandidate {
283275 goal : self ,
284276 kind : probe. kind ,
285- nested_goals : nested_goals . clone ( ) ,
277+ nested_goals,
286278 final_state : probe. final_state ,
287279 result,
288280 shallow_certainty,
@@ -310,8 +302,7 @@ impl<'a, 'tcx> InspectGoal<'a, 'tcx> {
310302 }
311303 } ;
312304
313- let mut nested_goals = vec ! [ ] ;
314- self . candidates_recur ( & mut candidates, & mut nested_goals, & last_eval_step. evaluation ) ;
305+ self . candidates_recur ( & mut candidates, & last_eval_step. evaluation ) ;
315306
316307 candidates
317308 }
0 commit comments