@@ -133,45 +133,25 @@ impl<'a, 'tcx> InspectCandidate<'a, 'tcx> {
133133 /// Instantiate the nested goals for the candidate without rolling back their
134134 /// inference constraints. This function modifies the state of the `infcx`.
135135 ///
136- /// See [`Self::instantiate_nested_goals_and_opt_impl_args`] if you need the impl args too.
137- pub fn instantiate_nested_goals ( & self , span : Span ) -> Vec < InspectGoal < ' a , ' tcx > > {
138- self . instantiate_nested_goals_and_opt_impl_args ( span) . 0
139- }
140-
141- /// Instantiate the nested goals for the candidate without rolling back their
142- /// inference constraints, and optionally the args of an impl if this candidate
143- /// came from a `CandidateSource::Impl`. This function modifies the state of the
144- /// `infcx`.
136+ /// See [`Self::instantiate_impl_args`] if you need the impl args too.
145137 #[ instrument(
146138 level = "debug" ,
147139 skip_all,
148140 fields( goal = ?self . goal. goal, steps = ?self . steps)
149141 ) ]
150- pub fn instantiate_nested_goals_and_opt_impl_args (
151- & self ,
152- span : Span ,
153- ) -> ( Vec < InspectGoal < ' a , ' tcx > > , Option < ty:: GenericArgsRef < ' tcx > > ) {
142+ pub fn instantiate_nested_goals ( & self , span : Span ) -> Vec < InspectGoal < ' a , ' tcx > > {
154143 let infcx = self . goal . infcx ;
155144 let param_env = self . goal . goal . param_env ;
156145 let mut orig_values = self . goal . orig_values . to_vec ( ) ;
157146
158147 let mut instantiated_goals = vec ! [ ] ;
159- let mut opt_impl_args = None ;
160148 for step in & self . steps {
161149 match * * step {
162150 inspect:: ProbeStep :: AddGoal ( source, goal) => instantiated_goals. push ( (
163151 source,
164152 instantiate_canonical_state ( infcx, span, param_env, & mut orig_values, goal) ,
165153 ) ) ,
166- inspect:: ProbeStep :: RecordImplArgs { impl_args } => {
167- opt_impl_args = Some ( instantiate_canonical_state (
168- infcx,
169- span,
170- param_env,
171- & mut orig_values,
172- impl_args,
173- ) ) ;
174- }
154+ inspect:: ProbeStep :: RecordImplArgs { .. } => { }
175155 inspect:: ProbeStep :: MakeCanonicalResponse { .. }
176156 | inspect:: ProbeStep :: NestedProbe ( _) => unreachable ! ( ) ,
177157 }
@@ -187,14 +167,59 @@ impl<'a, 'tcx> InspectCandidate<'a, 'tcx> {
187167 let _ = term_hack. constrain ( infcx, span, param_env) ;
188168 }
189169
190- let opt_impl_args = opt_impl_args. map ( |impl_args| eager_resolve_vars ( infcx, impl_args) ) ;
191-
192- let goals = instantiated_goals
170+ instantiated_goals
193171 . into_iter ( )
194172 . map ( |( source, goal) | self . instantiate_proof_tree_for_nested_goal ( source, goal, span) )
195- . collect ( ) ;
173+ . collect ( )
174+ }
175+
176+ /// Instantiate the args of an impl if this candidate came from a
177+ /// `CandidateSource::Impl`. This function modifies the state of the
178+ /// `infcx`.
179+ #[ instrument(
180+ level = "debug" ,
181+ skip_all,
182+ fields( goal = ?self . goal. goal, steps = ?self . steps)
183+ ) ]
184+ pub fn instantiate_impl_args ( & self , span : Span ) -> ty:: GenericArgsRef < ' tcx > {
185+ let infcx = self . goal . infcx ;
186+ let param_env = self . goal . goal . param_env ;
187+ let mut orig_values = self . goal . orig_values . to_vec ( ) ;
188+
189+ for step in & self . steps {
190+ match * * step {
191+ inspect:: ProbeStep :: RecordImplArgs { impl_args } => {
192+ let impl_args = instantiate_canonical_state (
193+ infcx,
194+ span,
195+ param_env,
196+ & mut orig_values,
197+ impl_args,
198+ ) ;
199+
200+ let ( ) = instantiate_canonical_state (
201+ infcx,
202+ span,
203+ param_env,
204+ & mut orig_values,
205+ self . final_state ,
206+ ) ;
207+
208+ // No reason we couldn't support this, but we don't need to for select.
209+ assert ! (
210+ self . goal. normalizes_to_term_hack. is_none( ) ,
211+ "cannot use `instantiate_impl_args` with a `NormalizesTo` goal"
212+ ) ;
213+
214+ return eager_resolve_vars ( infcx, impl_args) ;
215+ }
216+ inspect:: ProbeStep :: AddGoal ( ..) => { }
217+ inspect:: ProbeStep :: MakeCanonicalResponse { .. }
218+ | inspect:: ProbeStep :: NestedProbe ( _) => unreachable ! ( ) ,
219+ }
220+ }
196221
197- ( goals , opt_impl_args )
222+ bug ! ( "expected impl args probe step for `instantiate_impl_args`" ) ;
198223 }
199224
200225 pub fn instantiate_proof_tree_for_nested_goal (
0 commit comments