1
1
use std:: ops:: ControlFlow ;
2
2
3
- use rustc_hir:: def_id:: DefId ;
4
- use rustc_infer:: infer:: { DefineOpaqueTypes , InferCtxt , InferOk } ;
3
+ use rustc_infer:: infer:: InferCtxt ;
5
4
use rustc_infer:: traits:: solve:: inspect:: ProbeKind ;
6
5
use rustc_infer:: traits:: solve:: { CandidateSource , Certainty , Goal } ;
7
6
use rustc_infer:: traits:: {
8
7
BuiltinImplSource , ImplSource , ImplSourceUserDefinedData , Obligation , ObligationCause ,
9
- PolyTraitObligation , PredicateObligation , Selection , SelectionError , SelectionResult ,
8
+ PolyTraitObligation , Selection , SelectionError , SelectionResult ,
10
9
} ;
11
10
use rustc_macros:: extension;
12
11
use rustc_span:: Span ;
@@ -112,12 +111,14 @@ fn candidate_should_be_dropped_in_favor_of<'tcx>(
112
111
CandidateSource :: BuiltinImpl ( BuiltinImplSource :: Object { .. } ) ,
113
112
) => false ,
114
113
(
115
- CandidateSource :: Impl ( _) | CandidateSource :: ParamEnv ( _) | CandidateSource :: AliasBound ,
114
+ CandidateSource :: Impl ( _, _)
115
+ | CandidateSource :: ParamEnv ( _)
116
+ | CandidateSource :: AliasBound ,
116
117
CandidateSource :: BuiltinImpl ( BuiltinImplSource :: Object { .. } ) ,
117
118
) => true ,
118
119
119
120
// Prefer specializing candidates over specialized candidates.
120
- ( CandidateSource :: Impl ( victim_def_id) , CandidateSource :: Impl ( other_def_id) ) => {
121
+ ( CandidateSource :: Impl ( victim_def_id, _ ) , CandidateSource :: Impl ( other_def_id, _ ) ) => {
121
122
victim. goal ( ) . infcx ( ) . tcx . specializes ( ( other_def_id, victim_def_id) )
122
123
}
123
124
@@ -133,32 +134,34 @@ fn to_selection<'tcx>(
133
134
return None ;
134
135
}
135
136
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
- } ;
137
+ let nested = cand
138
+ . instantiate_nested_goals ( span)
139
+ . into_iter ( )
140
+ . map ( |nested| {
141
+ Obligation :: new (
142
+ nested. infcx ( ) . tcx ,
143
+ ObligationCause :: dummy_with_span ( span) ,
144
+ nested. goal ( ) . param_env ,
145
+ nested. goal ( ) . predicate ,
146
+ )
147
+ } )
148
+ . collect ( ) ;
149
149
150
150
Some ( match cand. kind ( ) {
151
151
ProbeKind :: TraitCandidate { source, result : _ } => match source {
152
- CandidateSource :: Impl ( impl_def_id) => {
153
- // FIXME: Remove this in favor of storing this in the tree
154
- // 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 ( ) )
152
+ CandidateSource :: Impl ( impl_def_id, impl_args ) => {
153
+ ImplSource :: UserDefined ( ImplSourceUserDefinedData {
154
+ impl_def_id ,
155
+ args : cand. instantiate_impl_args (
156
+ impl_args . expect ( "expected impl args to be recorded" ) ,
157
+ span ,
158
+ ) ,
159
+ nested ,
160
+ } )
161
161
}
162
+ CandidateSource :: BuiltinImpl ( builtin) => ImplSource :: Builtin ( builtin, nested) ,
163
+ CandidateSource :: ParamEnv ( _) => ImplSource :: Param ( nested) ,
164
+ CandidateSource :: AliasBound => ImplSource :: Builtin ( BuiltinImplSource :: Misc , nested) ,
162
165
CandidateSource :: CoherenceUnknowable => {
163
166
span_bug ! ( span, "didn't expect to select an unknowable candidate" )
164
167
}
@@ -173,40 +176,3 @@ fn to_selection<'tcx>(
173
176
}
174
177
} )
175
178
}
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