11use std:: ops:: ControlFlow ;
22
3- use rustc_hir:: def_id:: DefId ;
4- use rustc_infer:: infer:: { DefineOpaqueTypes , InferCtxt , InferOk } ;
3+ use rustc_infer:: infer:: InferCtxt ;
54use rustc_infer:: traits:: solve:: inspect:: ProbeKind ;
65use rustc_infer:: traits:: solve:: { CandidateSource , Certainty , Goal } ;
76use rustc_infer:: traits:: {
87 BuiltinImplSource , ImplSource , ImplSourceUserDefinedData , Obligation , ObligationCause ,
9- PolyTraitObligation , PredicateObligation , Selection , SelectionError , SelectionResult ,
8+ PolyTraitObligation , Selection , SelectionError , SelectionResult ,
109} ;
1110use rustc_macros:: extension;
1211use rustc_span:: Span ;
@@ -133,32 +132,33 @@ fn to_selection<'tcx>(
133132 return None ;
134133 }
135134
136- let make_nested = || {
137- cand. instantiate_nested_goals ( span)
138- . into_iter ( )
139- . map ( |nested| {
140- Obligation :: new (
141- nested. infcx ( ) . tcx ,
142- ObligationCause :: dummy_with_span ( span) ,
143- nested. goal ( ) . param_env ,
144- nested. goal ( ) . predicate ,
145- )
146- } )
147- . collect ( )
148- } ;
135+ let ( nested, impl_args) = cand. instantiate_nested_goals_and_impl_args ( span) ;
136+ let nested = nested
137+ . into_iter ( )
138+ . map ( |nested| {
139+ Obligation :: new (
140+ nested. infcx ( ) . tcx ,
141+ ObligationCause :: dummy_with_span ( span) ,
142+ nested. goal ( ) . param_env ,
143+ nested. goal ( ) . predicate ,
144+ )
145+ } )
146+ . collect ( ) ;
149147
150148 Some ( match cand. kind ( ) {
151149 ProbeKind :: TraitCandidate { source, result : _ } => match source {
152150 CandidateSource :: Impl ( impl_def_id) => {
153151 // FIXME: Remove this in favor of storing this in the tree
154152 // For impl candidates, we do the rematch manually to compute the args.
155- ImplSource :: UserDefined ( rematch_impl ( cand. goal ( ) , impl_def_id, span) )
156- }
157- CandidateSource :: BuiltinImpl ( builtin) => ImplSource :: Builtin ( builtin, make_nested ( ) ) ,
158- CandidateSource :: ParamEnv ( _) => ImplSource :: Param ( make_nested ( ) ) ,
159- CandidateSource :: AliasBound => {
160- ImplSource :: Builtin ( BuiltinImplSource :: Misc , make_nested ( ) )
153+ ImplSource :: UserDefined ( ImplSourceUserDefinedData {
154+ impl_def_id,
155+ args : impl_args. expect ( "expected recorded impl args for impl candidate" ) ,
156+ nested,
157+ } )
161158 }
159+ CandidateSource :: BuiltinImpl ( builtin) => ImplSource :: Builtin ( builtin, nested) ,
160+ CandidateSource :: ParamEnv ( _) => ImplSource :: Param ( nested) ,
161+ CandidateSource :: AliasBound => ImplSource :: Builtin ( BuiltinImplSource :: Misc , nested) ,
162162 CandidateSource :: CoherenceUnknowable => {
163163 span_bug ! ( span, "didn't expect to select an unknowable candidate" )
164164 }
@@ -173,40 +173,3 @@ fn to_selection<'tcx>(
173173 }
174174 } )
175175}
176-
177- fn rematch_impl < ' tcx > (
178- goal : & inspect:: InspectGoal < ' _ , ' tcx > ,
179- impl_def_id : DefId ,
180- span : Span ,
181- ) -> ImplSourceUserDefinedData < ' tcx , PredicateObligation < ' tcx > > {
182- let infcx = goal. infcx ( ) ;
183- let goal_trait_ref = infcx
184- . enter_forall_and_leak_universe ( goal. goal ( ) . predicate . to_opt_poly_trait_pred ( ) . unwrap ( ) )
185- . trait_ref ;
186-
187- let args = infcx. fresh_args_for_item ( span, impl_def_id) ;
188- let impl_trait_ref =
189- infcx. tcx . impl_trait_ref ( impl_def_id) . unwrap ( ) . instantiate ( infcx. tcx , args) ;
190-
191- let InferOk { value : ( ) , obligations : mut nested } = infcx
192- . at ( & ObligationCause :: dummy_with_span ( span) , goal. goal ( ) . param_env )
193- . eq ( DefineOpaqueTypes :: Yes , goal_trait_ref, impl_trait_ref)
194- . expect ( "rematching impl failed" ) ;
195-
196- // FIXME(-Znext-solver=coinductive): We need to add supertraits here eventually.
197-
198- nested. extend (
199- infcx. tcx . predicates_of ( impl_def_id) . instantiate ( infcx. tcx , args) . into_iter ( ) . map (
200- |( clause, _) | {
201- Obligation :: new (
202- infcx. tcx ,
203- ObligationCause :: dummy_with_span ( span) ,
204- goal. goal ( ) . param_env ,
205- clause,
206- )
207- } ,
208- ) ,
209- ) ;
210-
211- ImplSourceUserDefinedData { impl_def_id, nested, args }
212- }
0 commit comments