@@ -93,7 +93,10 @@ impl<'tcx> NormalizesToTermHack<'tcx> {
93
93
pub struct InspectCandidate < ' a , ' tcx > {
94
94
goal : & ' a InspectGoal < ' a , ' tcx > ,
95
95
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
+ > ,
97
100
final_state : inspect:: CanonicalState < ' tcx , ( ) > ,
98
101
result : QueryResult < ' tcx > ,
99
102
shallow_certainty : Certainty ,
@@ -141,23 +144,15 @@ impl<'a, 'tcx> InspectCandidate<'a, 'tcx> {
141
144
let infcx = self . goal . infcx ;
142
145
let param_env = self . goal . goal . param_env ;
143
146
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...
161
156
let ( ) = canonical:: instantiate_canonical_state (
162
157
infcx,
163
158
span,
@@ -174,7 +169,7 @@ impl<'a, 'tcx> InspectCandidate<'a, 'tcx> {
174
169
}
175
170
176
171
instantiated_goals
177
- . into_iter ( )
172
+ . iter ( )
178
173
. map ( |( source, goal) | match goal. predicate . kind ( ) . no_bound_vars ( ) {
179
174
Some ( ty:: PredicateKind :: NormalizesTo ( ty:: NormalizesTo { alias, term } ) ) => {
180
175
let unconstrained_term = match term. unpack ( ) {
@@ -240,27 +235,24 @@ impl<'a, 'tcx> InspectGoal<'a, 'tcx> {
240
235
fn candidates_recur (
241
236
& ' a self ,
242
237
candidates : & mut Vec < InspectCandidate < ' a , ' tcx > > ,
243
- nested_goals : & mut Vec < (
244
- GoalSource ,
245
- inspect:: CanonicalState < ' tcx , Goal < ' tcx , ty:: Predicate < ' tcx > > > ,
246
- ) > ,
247
238
probe : & inspect:: Probe < ' tcx > ,
248
239
) {
249
- let mut shallow_certainty = None ;
240
+ let mut shallow_certainty_and_goals = None ;
250
241
for step in & probe. steps {
251
- match step {
252
- & inspect:: ProbeStep :: AddGoal ( source, goal) => nested_goals. push ( ( source, goal) ) ,
242
+ match * step {
253
243
inspect:: ProbeStep :: NestedProbe ( ref probe) => {
254
244
// Nested probes have to prove goals added in their parent
255
245
// but do not leak them, so we truncate the added goals
256
246
// 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) ;
260
248
}
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
+ ) ;
263
254
}
255
+ inspect:: ProbeStep :: AddGoal ( ..) => { }
264
256
inspect:: ProbeStep :: EvaluateGoals ( _) => ( ) ,
265
257
}
266
258
}
@@ -278,11 +270,11 @@ impl<'a, 'tcx> InspectGoal<'a, 'tcx> {
278
270
| inspect:: ProbeKind :: OpaqueTypeStorageLookup { result } => {
279
271
// We only add a candidate if `shallow_certainty` was set, which means
280
272
// 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 {
282
274
candidates. push ( InspectCandidate {
283
275
goal : self ,
284
276
kind : probe. kind ,
285
- nested_goals : nested_goals . clone ( ) ,
277
+ nested_goals,
286
278
final_state : probe. final_state ,
287
279
result,
288
280
shallow_certainty,
@@ -310,8 +302,7 @@ impl<'a, 'tcx> InspectGoal<'a, 'tcx> {
310
302
}
311
303
} ;
312
304
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 ) ;
315
306
316
307
candidates
317
308
}
0 commit comments