@@ -148,6 +148,8 @@ pub fn find_method<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
148148pub fn specializes < ' a , ' tcx > ( tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
149149 impl1_def_id : DefId ,
150150 impl2_def_id : DefId ) -> bool {
151+ debug ! ( "specializes({:?}, {:?})" , impl1_def_id, impl2_def_id) ;
152+
151153 if let Some ( r) = tcx. specializes_cache . borrow ( ) . check ( impl1_def_id, impl2_def_id) {
152154 return r;
153155 }
@@ -177,21 +179,22 @@ pub fn specializes<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
177179 }
178180
179181 // 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 ) ;
183185 let impl1_trait_ref = tcx. impl_trait_ref ( impl1_def_id)
184186 . unwrap ( )
185187 . subst ( tcx, & penv. free_substs ) ;
186188
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| {
188191 // Normalize the trait reference, adding any obligations
189192 // that arise into the impl1 assumptions.
190193 let Normalized { value : impl1_trait_ref, obligations : normalization_obligations } = {
191194 let selcx = & mut SelectionContext :: new ( & infcx) ;
192195 traits:: normalize ( selcx, ObligationCause :: dummy ( ) , & impl1_trait_ref)
193196 } ;
194- penv . caller_bounds . extend ( normalization_obligations. into_iter ( ) . map ( |o| {
197+ infcx . parameter_environment . caller_bounds . extend ( normalization_obligations. into_iter ( ) . map ( |o| {
195198 match tcx. lift_to_global ( & o. predicate ) {
196199 Some ( predicate) => predicate,
197200 None => {
@@ -200,9 +203,6 @@ pub fn specializes<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
200203 }
201204 } ) ) ;
202205
203- // Install the parameter environment, taking the predicates of impl1 as assumptions:
204- infcx. parameter_environment = penv;
205-
206206 // Attempt to prove that impl2 applies, given all of the above.
207207 fulfill_implication ( & infcx, impl1_trait_ref, impl2_def_id) . is_ok ( )
208208 } ) ;
0 commit comments