@@ -93,6 +93,7 @@ pub struct InspectCandidate<'a, 'tcx> {
93
93
kind : inspect:: ProbeKind < ' tcx > ,
94
94
nested_goals : Vec < ( GoalSource , inspect:: CanonicalState < ' tcx , Goal < ' tcx , ty:: Predicate < ' tcx > > > ) > ,
95
95
final_state : inspect:: CanonicalState < ' tcx , ( ) > ,
96
+ impl_args : Option < inspect:: CanonicalState < ' tcx , ty:: GenericArgsRef < ' tcx > > > ,
96
97
result : QueryResult < ' tcx > ,
97
98
shallow_certainty : Certainty ,
98
99
}
@@ -135,7 +136,20 @@ impl<'a, 'tcx> InspectCandidate<'a, 'tcx> {
135
136
136
137
/// Instantiate the nested goals for the candidate without rolling back their
137
138
/// inference constraints. This function modifies the state of the `infcx`.
139
+ ///
140
+ /// See [`Self::instantiate_nested_goals_and_opt_impl_args`] if you need the impl args too.
138
141
pub fn instantiate_nested_goals ( & self , span : Span ) -> Vec < InspectGoal < ' a , ' tcx > > {
142
+ self . instantiate_nested_goals_and_opt_impl_args ( span) . 0
143
+ }
144
+
145
+ /// Instantiate the nested goals for the candidate without rolling back their
146
+ /// inference constraints, and optionally the args of an impl if this candidate
147
+ /// came from a `CandidateSource::Impl`. This function modifies the state of the
148
+ /// `infcx`.
149
+ pub fn instantiate_nested_goals_and_opt_impl_args (
150
+ & self ,
151
+ span : Span ,
152
+ ) -> ( Vec < InspectGoal < ' a , ' tcx > > , Option < ty:: GenericArgsRef < ' tcx > > ) {
139
153
let infcx = self . goal . infcx ;
140
154
let param_env = self . goal . goal . param_env ;
141
155
let mut orig_values = self . goal . orig_values . to_vec ( ) ;
@@ -164,14 +178,25 @@ impl<'a, 'tcx> InspectCandidate<'a, 'tcx> {
164
178
self . final_state ,
165
179
) ;
166
180
181
+ let impl_args = self . impl_args . map ( |impl_args| {
182
+ canonical:: instantiate_canonical_state (
183
+ infcx,
184
+ span,
185
+ param_env,
186
+ & mut orig_values,
187
+ impl_args,
188
+ )
189
+ . fold_with ( & mut EagerResolver :: new ( infcx) )
190
+ } ) ;
191
+
167
192
if let Some ( term_hack) = self . goal . normalizes_to_term_hack {
168
193
// FIXME: We ignore the expected term of `NormalizesTo` goals
169
194
// when computing the result of its candidates. This is
170
195
// scuffed.
171
196
let _ = term_hack. constrain ( infcx, span, param_env) ;
172
197
}
173
198
174
- instantiated_goals
199
+ let goals = instantiated_goals
175
200
. into_iter ( )
176
201
. map ( |( source, goal) | match goal. predicate . kind ( ) . no_bound_vars ( ) {
177
202
Some ( ty:: PredicateKind :: NormalizesTo ( ty:: NormalizesTo { alias, term } ) ) => {
@@ -208,7 +233,9 @@ impl<'a, 'tcx> InspectCandidate<'a, 'tcx> {
208
233
source,
209
234
) ,
210
235
} )
211
- . collect ( )
236
+ . collect ( ) ;
237
+
238
+ ( goals, impl_args)
212
239
}
213
240
214
241
/// Visit all nested goals of this candidate, rolling back
@@ -245,9 +272,10 @@ impl<'a, 'tcx> InspectGoal<'a, 'tcx> {
245
272
probe : & inspect:: Probe < ' tcx > ,
246
273
) {
247
274
let mut shallow_certainty = None ;
275
+ let mut impl_args = None ;
248
276
for step in & probe. steps {
249
- match step {
250
- & inspect:: ProbeStep :: AddGoal ( source, goal) => nested_goals. push ( ( source, goal) ) ,
277
+ match * step {
278
+ inspect:: ProbeStep :: AddGoal ( source, goal) => nested_goals. push ( ( source, goal) ) ,
251
279
inspect:: ProbeStep :: NestedProbe ( ref probe) => {
252
280
// Nested probes have to prove goals added in their parent
253
281
// but do not leak them, so we truncate the added goals
@@ -257,7 +285,10 @@ impl<'a, 'tcx> InspectGoal<'a, 'tcx> {
257
285
nested_goals. truncate ( num_goals) ;
258
286
}
259
287
inspect:: ProbeStep :: MakeCanonicalResponse { shallow_certainty : c } => {
260
- assert_eq ! ( shallow_certainty. replace( * c) , None ) ;
288
+ assert_eq ! ( shallow_certainty. replace( c) , None ) ;
289
+ }
290
+ inspect:: ProbeStep :: RecordImplArgs { impl_args : i } => {
291
+ assert_eq ! ( impl_args. replace( i) , None ) ;
261
292
}
262
293
inspect:: ProbeStep :: EvaluateGoals ( _) => ( ) ,
263
294
}
@@ -284,6 +315,7 @@ impl<'a, 'tcx> InspectGoal<'a, 'tcx> {
284
315
final_state : probe. final_state ,
285
316
result,
286
317
shallow_certainty,
318
+ impl_args,
287
319
} ) ;
288
320
}
289
321
}
0 commit comments