@@ -91,7 +91,10 @@ impl<'tcx> NormalizesToTermHack<'tcx> {
9191pub struct InspectCandidate < ' a , ' tcx > {
9292 goal : & ' a InspectGoal < ' a , ' tcx > ,
9393 kind : inspect:: ProbeKind < ' tcx > ,
94- nested_goals : Vec < ( GoalSource , inspect:: CanonicalState < ' tcx , Goal < ' tcx , ty:: Predicate < ' tcx > > > ) > ,
94+ nested_goals : inspect:: CanonicalState <
95+ ' tcx ,
96+ & ' tcx ty:: List < ( GoalSource , Goal < ' tcx , ty:: Predicate < ' tcx > > ) > ,
97+ > ,
9598 final_state : inspect:: CanonicalState < ' tcx , ( ) > ,
9699 result : QueryResult < ' tcx > ,
97100 shallow_certainty : Certainty ,
@@ -139,23 +142,15 @@ impl<'a, 'tcx> InspectCandidate<'a, 'tcx> {
139142 let infcx = self . goal . infcx ;
140143 let param_env = self . goal . goal . param_env ;
141144 let mut orig_values = self . goal . orig_values . to_vec ( ) ;
142- let instantiated_goals: Vec < _ > = self
143- . nested_goals
144- . iter ( )
145- . map ( |( source, goal) | {
146- (
147- * source,
148- canonical:: instantiate_canonical_state (
149- infcx,
150- span,
151- param_env,
152- & mut orig_values,
153- * goal,
154- ) ,
155- )
156- } )
157- . collect ( ) ;
158-
145+ let instantiated_goals = canonical:: instantiate_canonical_state (
146+ infcx,
147+ span,
148+ param_env,
149+ & mut orig_values,
150+ self . nested_goals ,
151+ ) ;
152+ // FIXME: Should we truncate orig_values back down? Any new infer vars
153+ // between `nested_goals` and `final_state` are definitely unrelated...
159154 let ( ) = canonical:: instantiate_canonical_state (
160155 infcx,
161156 span,
@@ -172,7 +167,7 @@ impl<'a, 'tcx> InspectCandidate<'a, 'tcx> {
172167 }
173168
174169 instantiated_goals
175- . into_iter ( )
170+ . iter ( )
176171 . map ( |( source, goal) | match goal. predicate . kind ( ) . no_bound_vars ( ) {
177172 Some ( ty:: PredicateKind :: NormalizesTo ( ty:: NormalizesTo { alias, term } ) ) => {
178173 let unconstrained_term = match term. unpack ( ) {
@@ -238,27 +233,24 @@ impl<'a, 'tcx> InspectGoal<'a, 'tcx> {
238233 fn candidates_recur (
239234 & ' a self ,
240235 candidates : & mut Vec < InspectCandidate < ' a , ' tcx > > ,
241- nested_goals : & mut Vec < (
242- GoalSource ,
243- inspect:: CanonicalState < ' tcx , Goal < ' tcx , ty:: Predicate < ' tcx > > > ,
244- ) > ,
245236 probe : & inspect:: Probe < ' tcx > ,
246237 ) {
247- let mut shallow_certainty = None ;
238+ let mut shallow_certainty_and_goals = None ;
248239 for step in & probe. steps {
249- match step {
250- & inspect:: ProbeStep :: AddGoal ( source, goal) => nested_goals. push ( ( source, goal) ) ,
240+ match * step {
251241 inspect:: ProbeStep :: NestedProbe ( ref probe) => {
252242 // Nested probes have to prove goals added in their parent
253243 // but do not leak them, so we truncate the added goals
254244 // afterwards.
255- let num_goals = nested_goals. len ( ) ;
256- self . candidates_recur ( candidates, nested_goals, probe) ;
257- nested_goals. truncate ( num_goals) ;
245+ self . candidates_recur ( candidates, probe) ;
258246 }
259- inspect:: ProbeStep :: MakeCanonicalResponse { shallow_certainty : c } => {
260- assert_eq ! ( shallow_certainty. replace( * c) , None ) ;
247+ inspect:: ProbeStep :: MakeCanonicalResponse { shallow_certainty, added_goals } => {
248+ assert_eq ! (
249+ shallow_certainty_and_goals. replace( ( shallow_certainty, added_goals) ) ,
250+ None
251+ ) ;
261252 }
253+ inspect:: ProbeStep :: AddGoal ( ..) => { }
262254 inspect:: ProbeStep :: EvaluateGoals ( _) => ( ) ,
263255 }
264256 }
@@ -276,11 +268,11 @@ impl<'a, 'tcx> InspectGoal<'a, 'tcx> {
276268 | inspect:: ProbeKind :: OpaqueTypeStorageLookup { result } => {
277269 // We only add a candidate if `shallow_certainty` was set, which means
278270 // that we ended up calling `evaluate_added_goals_and_make_canonical_response`.
279- if let Some ( shallow_certainty) = shallow_certainty {
271+ if let Some ( ( shallow_certainty, nested_goals ) ) = shallow_certainty_and_goals {
280272 candidates. push ( InspectCandidate {
281273 goal : self ,
282274 kind : probe. kind ,
283- nested_goals : nested_goals . clone ( ) ,
275+ nested_goals,
284276 final_state : probe. final_state ,
285277 result,
286278 shallow_certainty,
@@ -308,8 +300,7 @@ impl<'a, 'tcx> InspectGoal<'a, 'tcx> {
308300 }
309301 } ;
310302
311- let mut nested_goals = vec ! [ ] ;
312- self . candidates_recur ( & mut candidates, & mut nested_goals, & last_eval_step. evaluation ) ;
303+ self . candidates_recur ( & mut candidates, & last_eval_step. evaluation ) ;
313304
314305 candidates
315306 }
0 commit comments