@@ -91,7 +91,10 @@ impl<'tcx> NormalizesToTermHack<'tcx> {
91
91
pub struct InspectCandidate < ' a , ' tcx > {
92
92
goal : & ' a InspectGoal < ' a , ' tcx > ,
93
93
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
+ > ,
95
98
final_state : inspect:: CanonicalState < ' tcx , ( ) > ,
96
99
result : QueryResult < ' tcx > ,
97
100
shallow_certainty : Certainty ,
@@ -139,23 +142,15 @@ impl<'a, 'tcx> InspectCandidate<'a, 'tcx> {
139
142
let infcx = self . goal . infcx ;
140
143
let param_env = self . goal . goal . param_env ;
141
144
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...
159
154
let ( ) = canonical:: instantiate_canonical_state (
160
155
infcx,
161
156
span,
@@ -172,7 +167,7 @@ impl<'a, 'tcx> InspectCandidate<'a, 'tcx> {
172
167
}
173
168
174
169
instantiated_goals
175
- . into_iter ( )
170
+ . iter ( )
176
171
. map ( |( source, goal) | match goal. predicate . kind ( ) . no_bound_vars ( ) {
177
172
Some ( ty:: PredicateKind :: NormalizesTo ( ty:: NormalizesTo { alias, term } ) ) => {
178
173
let unconstrained_term = match term. unpack ( ) {
@@ -238,27 +233,24 @@ impl<'a, 'tcx> InspectGoal<'a, 'tcx> {
238
233
fn candidates_recur (
239
234
& ' a self ,
240
235
candidates : & mut Vec < InspectCandidate < ' a , ' tcx > > ,
241
- nested_goals : & mut Vec < (
242
- GoalSource ,
243
- inspect:: CanonicalState < ' tcx , Goal < ' tcx , ty:: Predicate < ' tcx > > > ,
244
- ) > ,
245
236
probe : & inspect:: Probe < ' tcx > ,
246
237
) {
247
- let mut shallow_certainty = None ;
238
+ let mut shallow_certainty_and_goals = None ;
248
239
for step in & probe. steps {
249
- match step {
250
- & inspect:: ProbeStep :: AddGoal ( source, goal) => nested_goals. push ( ( source, goal) ) ,
240
+ match * step {
251
241
inspect:: ProbeStep :: NestedProbe ( ref probe) => {
252
242
// Nested probes have to prove goals added in their parent
253
243
// but do not leak them, so we truncate the added goals
254
244
// 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) ;
258
246
}
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
+ ) ;
261
252
}
253
+ inspect:: ProbeStep :: AddGoal ( ..) => { }
262
254
inspect:: ProbeStep :: EvaluateGoals ( _) => ( ) ,
263
255
}
264
256
}
@@ -276,11 +268,11 @@ impl<'a, 'tcx> InspectGoal<'a, 'tcx> {
276
268
| inspect:: ProbeKind :: OpaqueTypeStorageLookup { result } => {
277
269
// We only add a candidate if `shallow_certainty` was set, which means
278
270
// 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 {
280
272
candidates. push ( InspectCandidate {
281
273
goal : self ,
282
274
kind : probe. kind ,
283
- nested_goals : nested_goals . clone ( ) ,
275
+ nested_goals,
284
276
final_state : probe. final_state ,
285
277
result,
286
278
shallow_certainty,
@@ -308,8 +300,7 @@ impl<'a, 'tcx> InspectGoal<'a, 'tcx> {
308
300
}
309
301
} ;
310
302
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 ) ;
313
304
314
305
candidates
315
306
}
0 commit comments