@@ -148,6 +148,8 @@ pub fn find_method<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
148
148
pub fn specializes < ' a , ' tcx > ( tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
149
149
impl1_def_id : DefId ,
150
150
impl2_def_id : DefId ) -> bool {
151
+ debug ! ( "specializes({:?}, {:?})" , impl1_def_id, impl2_def_id) ;
152
+
151
153
if let Some ( r) = tcx. specializes_cache . borrow ( ) . check ( impl1_def_id, impl2_def_id) {
152
154
return r;
153
155
}
@@ -177,21 +179,22 @@ pub fn specializes<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
177
179
}
178
180
179
181
// create a parameter environment corresponding to a (skolemized) instantiation of impl1
180
- let mut penv = tcx. construct_parameter_environment ( DUMMY_SP ,
181
- impl1_def_id,
182
- region:: DUMMY_CODE_EXTENT ) ;
182
+ let penv = tcx. construct_parameter_environment ( DUMMY_SP ,
183
+ impl1_def_id,
184
+ region:: DUMMY_CODE_EXTENT ) ;
183
185
let impl1_trait_ref = tcx. impl_trait_ref ( impl1_def_id)
184
186
. unwrap ( )
185
187
. subst ( tcx, & penv. free_substs ) ;
186
188
187
- let result = tcx. infer_ctxt ( None , None , Reveal :: ExactMatch ) . enter ( |mut infcx| {
189
+ // Create a infcx, taking the predicates of impl1 as assumptions:
190
+ let result = tcx. infer_ctxt ( None , Some ( penv) , Reveal :: ExactMatch ) . enter ( |mut infcx| {
188
191
// Normalize the trait reference, adding any obligations
189
192
// that arise into the impl1 assumptions.
190
193
let Normalized { value : impl1_trait_ref, obligations : normalization_obligations } = {
191
194
let selcx = & mut SelectionContext :: new ( & infcx) ;
192
195
traits:: normalize ( selcx, ObligationCause :: dummy ( ) , & impl1_trait_ref)
193
196
} ;
194
- penv . caller_bounds . extend ( normalization_obligations. into_iter ( ) . map ( |o| {
197
+ infcx . parameter_environment . caller_bounds . extend ( normalization_obligations. into_iter ( ) . map ( |o| {
195
198
match tcx. lift_to_global ( & o. predicate ) {
196
199
Some ( predicate) => predicate,
197
200
None => {
@@ -200,9 +203,6 @@ pub fn specializes<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
200
203
}
201
204
} ) ) ;
202
205
203
- // Install the parameter environment, taking the predicates of impl1 as assumptions:
204
- infcx. parameter_environment = penv;
205
-
206
206
// Attempt to prove that impl2 applies, given all of the above.
207
207
fulfill_implication ( & infcx, impl1_trait_ref, impl2_def_id) . is_ok ( )
208
208
} ) ;
0 commit comments