@@ -93,6 +93,7 @@ pub struct InspectCandidate<'a, 'tcx> {
9393 kind : inspect:: ProbeKind < ' tcx > ,
9494 nested_goals : Vec < ( GoalSource , inspect:: CanonicalState < ' tcx , Goal < ' tcx , ty:: Predicate < ' tcx > > > ) > ,
9595 final_state : inspect:: CanonicalState < ' tcx , ( ) > ,
96+ impl_args : Option < inspect:: CanonicalState < ' tcx , ty:: GenericArgsRef < ' tcx > > > ,
9697 result : QueryResult < ' tcx > ,
9798 shallow_certainty : Certainty ,
9899}
@@ -135,7 +136,20 @@ impl<'a, 'tcx> InspectCandidate<'a, 'tcx> {
135136
136137 /// Instantiate the nested goals for the candidate without rolling back their
137138 /// 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.
138141 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 > > ) {
139153 let infcx = self . goal . infcx ;
140154 let param_env = self . goal . goal . param_env ;
141155 let mut orig_values = self . goal . orig_values . to_vec ( ) ;
@@ -164,14 +178,25 @@ impl<'a, 'tcx> InspectCandidate<'a, 'tcx> {
164178 self . final_state ,
165179 ) ;
166180
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+
167192 if let Some ( term_hack) = self . goal . normalizes_to_term_hack {
168193 // FIXME: We ignore the expected term of `NormalizesTo` goals
169194 // when computing the result of its candidates. This is
170195 // scuffed.
171196 let _ = term_hack. constrain ( infcx, span, param_env) ;
172197 }
173198
174- instantiated_goals
199+ let goals = instantiated_goals
175200 . into_iter ( )
176201 . map ( |( source, goal) | match goal. predicate . kind ( ) . no_bound_vars ( ) {
177202 Some ( ty:: PredicateKind :: NormalizesTo ( ty:: NormalizesTo { alias, term } ) ) => {
@@ -208,7 +233,9 @@ impl<'a, 'tcx> InspectCandidate<'a, 'tcx> {
208233 source,
209234 ) ,
210235 } )
211- . collect ( )
236+ . collect ( ) ;
237+
238+ ( goals, impl_args)
212239 }
213240
214241 /// Visit all nested goals of this candidate, rolling back
@@ -245,9 +272,10 @@ impl<'a, 'tcx> InspectGoal<'a, 'tcx> {
245272 probe : & inspect:: Probe < ' tcx > ,
246273 ) {
247274 let mut shallow_certainty = None ;
275+ let mut impl_args = None ;
248276 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) ) ,
251279 inspect:: ProbeStep :: NestedProbe ( ref probe) => {
252280 // Nested probes have to prove goals added in their parent
253281 // but do not leak them, so we truncate the added goals
@@ -257,7 +285,10 @@ impl<'a, 'tcx> InspectGoal<'a, 'tcx> {
257285 nested_goals. truncate ( num_goals) ;
258286 }
259287 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 ) ;
261292 }
262293 inspect:: ProbeStep :: EvaluateGoals ( _) => ( ) ,
263294 }
@@ -284,6 +315,7 @@ impl<'a, 'tcx> InspectGoal<'a, 'tcx> {
284315 final_state : probe. final_state ,
285316 result,
286317 shallow_certainty,
318+ impl_args,
287319 } ) ;
288320 }
289321 }
0 commit comments