@@ -142,16 +142,13 @@ pub fn overlapping_impls(
142
142
Some ( overlap)
143
143
}
144
144
145
- fn with_fresh_ty_vars < ' cx , ' tcx > (
146
- selcx : & mut SelectionContext < ' cx , ' tcx > ,
147
- param_env : ty:: ParamEnv < ' tcx > ,
148
- impl_def_id : DefId ,
149
- ) -> ty:: ImplHeader < ' tcx > {
150
- let tcx = selcx. tcx ( ) ;
151
- let impl_args = selcx. infcx . fresh_args_for_item ( DUMMY_SP , impl_def_id) ;
145
+ fn fresh_impl_header < ' tcx > ( infcx : & InferCtxt < ' tcx > , impl_def_id : DefId ) -> ty:: ImplHeader < ' tcx > {
146
+ let tcx = infcx. tcx ;
147
+ let impl_args = infcx. fresh_args_for_item ( DUMMY_SP , impl_def_id) ;
152
148
153
- let header = ty:: ImplHeader {
149
+ ty:: ImplHeader {
154
150
impl_def_id,
151
+ impl_args,
155
152
self_ty : tcx. type_of ( impl_def_id) . instantiate ( tcx, impl_args) ,
156
153
trait_ref : tcx. impl_trait_ref ( impl_def_id) . map ( |i| i. instantiate ( tcx, impl_args) ) ,
157
154
predicates : tcx
@@ -160,10 +157,18 @@ fn with_fresh_ty_vars<'cx, 'tcx>(
160
157
. iter ( )
161
158
. map ( |( c, _) | c. as_predicate ( ) )
162
159
. collect ( ) ,
163
- } ;
160
+ }
161
+ }
162
+
163
+ fn fresh_impl_header_normalized < ' tcx > (
164
+ infcx : & InferCtxt < ' tcx > ,
165
+ param_env : ty:: ParamEnv < ' tcx > ,
166
+ impl_def_id : DefId ,
167
+ ) -> ty:: ImplHeader < ' tcx > {
168
+ let header = fresh_impl_header ( infcx, impl_def_id) ;
164
169
165
170
let InferOk { value : mut header, obligations } =
166
- selcx . infcx . at ( & ObligationCause :: dummy ( ) , param_env) . normalize ( header) ;
171
+ infcx. at ( & ObligationCause :: dummy ( ) , param_env) . normalize ( header) ;
167
172
168
173
header. predicates . extend ( obligations. into_iter ( ) . map ( |o| o. predicate ) ) ;
169
174
header
@@ -206,12 +211,13 @@ fn overlap<'tcx>(
206
211
// empty environment.
207
212
let param_env = ty:: ParamEnv :: empty ( ) ;
208
213
209
- let impl1_header = with_fresh_ty_vars ( selcx, param_env, impl1_def_id) ;
210
- let impl2_header = with_fresh_ty_vars ( selcx, param_env, impl2_def_id) ;
214
+ let impl1_header = fresh_impl_header_normalized ( selcx. infcx , param_env, impl1_def_id) ;
215
+ let impl2_header = fresh_impl_header_normalized ( selcx. infcx , param_env, impl2_def_id) ;
211
216
212
217
// Equate the headers to find their intersection (the general type, with infer vars,
213
218
// that may apply both impls).
214
- let mut obligations = equate_impl_headers ( selcx. infcx , & impl1_header, & impl2_header) ?;
219
+ let mut obligations =
220
+ equate_impl_headers ( selcx. infcx , param_env, & impl1_header, & impl2_header) ?;
215
221
debug ! ( "overlap: unification check succeeded" ) ;
216
222
217
223
obligations. extend (
@@ -312,20 +318,22 @@ fn overlap<'tcx>(
312
318
#[ instrument( level = "debug" , skip( infcx) , ret) ]
313
319
fn equate_impl_headers < ' tcx > (
314
320
infcx : & InferCtxt < ' tcx > ,
321
+ param_env : ty:: ParamEnv < ' tcx > ,
315
322
impl1 : & ty:: ImplHeader < ' tcx > ,
316
323
impl2 : & ty:: ImplHeader < ' tcx > ,
317
324
) -> Option < PredicateObligations < ' tcx > > {
318
- let result = match ( impl1. trait_ref , impl2. trait_ref ) {
319
- ( Some ( impl1_ref) , Some ( impl2_ref) ) => infcx
320
- . at ( & ObligationCause :: dummy ( ) , ty:: ParamEnv :: empty ( ) )
321
- . eq ( DefineOpaqueTypes :: Yes , impl1_ref, impl2_ref) ,
322
- ( None , None ) => infcx. at ( & ObligationCause :: dummy ( ) , ty:: ParamEnv :: empty ( ) ) . eq (
323
- DefineOpaqueTypes :: Yes ,
324
- impl1. self_ty ,
325
- impl2. self_ty ,
326
- ) ,
327
- _ => bug ! ( "mk_eq_impl_headers given mismatched impl kinds" ) ,
328
- } ;
325
+ let result =
326
+ match ( impl1. trait_ref , impl2. trait_ref ) {
327
+ ( Some ( impl1_ref) , Some ( impl2_ref) ) => infcx
328
+ . at ( & ObligationCause :: dummy ( ) , param_env)
329
+ . eq ( DefineOpaqueTypes :: Yes , impl1_ref, impl2_ref) ,
330
+ ( None , None ) => infcx. at ( & ObligationCause :: dummy ( ) , param_env) . eq (
331
+ DefineOpaqueTypes :: Yes ,
332
+ impl1. self_ty ,
333
+ impl2. self_ty ,
334
+ ) ,
335
+ _ => bug ! ( "mk_eq_impl_headers given mismatched impl kinds" ) ,
336
+ } ;
329
337
330
338
result. map ( |infer_ok| infer_ok. obligations ) . ok ( )
331
339
}
0 commit comments