@@ -99,14 +99,13 @@ pub fn translate_substs<'tcx>(
99
99
return source_substs;
100
100
}
101
101
102
- fulfill_implication ( infcx, param_env, source_trait_ref, target_impl) . unwrap_or_else (
103
- |( ) | {
102
+ fulfill_implication ( infcx, param_env, source_trait_ref, source_impl , target_impl)
103
+ . unwrap_or_else ( |( ) | {
104
104
bug ! (
105
105
"When translating substitutions from {source_impl:?} to {target_impl:?}, \
106
106
the expected specialization failed to hold"
107
107
)
108
- } ,
109
- )
108
+ } )
110
109
}
111
110
specialization_graph:: Node :: Trait ( ..) => source_trait_ref. substs ,
112
111
} ;
@@ -153,20 +152,9 @@ pub(super) fn specializes(tcx: TyCtxt<'_>, (impl1_def_id, impl2_def_id): (DefId,
153
152
154
153
// Create an infcx, taking the predicates of impl1 as assumptions:
155
154
let infcx = tcx. infer_ctxt ( ) . build ( ) ;
156
- let impl1_trait_ref =
157
- match traits:: fully_normalize ( & infcx, ObligationCause :: dummy ( ) , penv, impl1_trait_ref) {
158
- Ok ( impl1_trait_ref) => impl1_trait_ref,
159
- Err ( _errors) => {
160
- tcx. sess . delay_span_bug (
161
- tcx. def_span ( impl1_def_id) ,
162
- format ! ( "failed to fully normalize {impl1_trait_ref}" ) ,
163
- ) ;
164
- impl1_trait_ref
165
- }
166
- } ;
167
155
168
156
// Attempt to prove that impl2 applies, given all of the above.
169
- fulfill_implication ( & infcx, penv, impl1_trait_ref, impl2_def_id) . is_ok ( )
157
+ fulfill_implication ( & infcx, penv, impl1_trait_ref, impl1_def_id , impl2_def_id) . is_ok ( )
170
158
}
171
159
172
160
/// Attempt to fulfill all obligations of `target_impl` after unification with
@@ -178,13 +166,30 @@ fn fulfill_implication<'tcx>(
178
166
infcx : & InferCtxt < ' tcx > ,
179
167
param_env : ty:: ParamEnv < ' tcx > ,
180
168
source_trait_ref : ty:: TraitRef < ' tcx > ,
169
+ source_impl : DefId ,
181
170
target_impl : DefId ,
182
171
) -> Result < SubstsRef < ' tcx > , ( ) > {
183
172
debug ! (
184
173
"fulfill_implication({:?}, trait_ref={:?} |- {:?} applies)" ,
185
174
param_env, source_trait_ref, target_impl
186
175
) ;
187
176
177
+ let source_trait_ref = match traits:: fully_normalize (
178
+ & infcx,
179
+ ObligationCause :: dummy ( ) ,
180
+ param_env,
181
+ source_trait_ref,
182
+ ) {
183
+ Ok ( source_trait_ref) => source_trait_ref,
184
+ Err ( _errors) => {
185
+ infcx. tcx . sess . delay_span_bug (
186
+ infcx. tcx . def_span ( source_impl) ,
187
+ format ! ( "failed to fully normalize {source_trait_ref}" ) ,
188
+ ) ;
189
+ source_trait_ref
190
+ }
191
+ } ;
192
+
188
193
let source_trait = ImplSubject :: Trait ( source_trait_ref) ;
189
194
190
195
let selcx = & mut SelectionContext :: new ( & infcx) ;
@@ -194,7 +199,7 @@ fn fulfill_implication<'tcx>(
194
199
195
200
// do the impls unify? If not, no specialization.
196
201
let Ok ( InferOk { obligations : more_obligations, .. } ) =
197
- infcx. at ( & ObligationCause :: dummy ( ) , param_env, ) . eq ( DefineOpaqueTypes :: No , source_trait, target_trait)
202
+ infcx. at ( & ObligationCause :: dummy ( ) , param_env) . eq ( DefineOpaqueTypes :: No , source_trait, target_trait)
198
203
else {
199
204
debug ! (
200
205
"fulfill_implication: {:?} does not unify with {:?}" ,
0 commit comments