8
8
// option. This file may not be copied, modified, or distributed
9
9
// except according to those terms.
10
10
11
- use middle:: free_region:: FreeRegionMap ;
12
11
use rustc:: infer:: { self , InferOk , TypeOrigin } ;
13
12
use rustc:: ty;
14
13
use rustc:: traits:: { self , Reveal } ;
@@ -21,6 +20,7 @@ use syntax_pos::Span;
21
20
22
21
use CrateCtxt ;
23
22
use super :: assoc;
23
+ use super :: { Inherited , FnCtxt } ;
24
24
25
25
/// Checks that a method from an impl conforms to the signature of
26
26
/// the same method as declared in the trait.
@@ -313,9 +313,6 @@ pub fn compare_impl_method<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
313
313
return ;
314
314
}
315
315
316
- tcx. infer_ctxt ( None , None , Reveal :: NotSpecializable ) . enter ( |mut infcx| {
317
- let mut fulfillment_cx = traits:: FulfillmentContext :: new ( ) ;
318
-
319
316
// Create obligations for each predicate declared by the impl
320
317
// definition in the context of the trait's parameter
321
318
// environment. We can't just use `impl_env.caller_bounds`,
@@ -341,10 +338,14 @@ pub fn compare_impl_method<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
341
338
// the new hybrid bounds we computed.
342
339
let normalize_cause = traits:: ObligationCause :: misc ( impl_m_span, impl_m_body_id) ;
343
340
let trait_param_env = impl_param_env. with_caller_bounds ( hybrid_preds. predicates ) ;
344
- let trait_param_env =
345
- traits:: normalize_param_env_or_error ( tcx, trait_param_env, normalize_cause. clone ( ) ) ;
346
- // FIXME(@jroesch) this seems ugly, but is a temporary change
347
- infcx. parameter_environment = trait_param_env;
341
+ let trait_param_env = traits:: normalize_param_env_or_error ( tcx,
342
+ trait_param_env,
343
+ normalize_cause. clone ( ) ) ;
344
+
345
+ tcx. infer_ctxt ( None , Some ( trait_param_env) , Reveal :: NotSpecializable ) . enter ( |infcx| {
346
+ let inh = Inherited :: new ( ccx, infcx) ;
347
+ let infcx = & inh. infcx ;
348
+ let fulfillment_cx = & inh. fulfillment_cx ;
348
349
349
350
debug ! ( "compare_impl_method: caller_bounds={:?}" ,
350
351
infcx. parameter_environment. caller_bounds) ;
@@ -365,7 +366,7 @@ pub fn compare_impl_method<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
365
366
code : traits:: ObligationCauseCode :: CompareImplMethodObligation ,
366
367
} ;
367
368
368
- fulfillment_cx. register_predicate_obligation (
369
+ fulfillment_cx. borrow_mut ( ) . register_predicate_obligation (
369
370
& infcx,
370
371
traits:: Obligation :: new ( cause, predicate) ) ;
371
372
}
@@ -387,30 +388,36 @@ pub fn compare_impl_method<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
387
388
let tcx = infcx. tcx ;
388
389
let origin = TypeOrigin :: MethodCompatCheck ( impl_m_span) ;
389
390
390
- let ( impl_sig, _) = infcx. replace_late_bound_regions_with_fresh_var ( impl_m_span,
391
- infer:: HigherRankedType ,
392
- & impl_m. fty . sig ) ;
393
- let impl_sig = impl_sig. subst ( tcx, impl_to_skol_substs) ;
394
- let impl_sig = assoc:: normalize_associated_types_in ( & infcx,
395
- & mut fulfillment_cx,
396
- impl_m_span,
397
- impl_m_body_id,
398
- & impl_sig) ;
391
+ let ( impl_sig, _) =
392
+ infcx. replace_late_bound_regions_with_fresh_var ( impl_m_span,
393
+ infer:: HigherRankedType ,
394
+ & impl_m. fty . sig ) ;
395
+ let impl_sig =
396
+ impl_sig. subst ( tcx, impl_to_skol_substs) ;
397
+ let impl_sig =
398
+ assoc:: normalize_associated_types_in ( & infcx,
399
+ & mut fulfillment_cx. borrow_mut ( ) ,
400
+ impl_m_span,
401
+ impl_m_body_id,
402
+ & impl_sig) ;
399
403
let impl_fty = tcx. mk_fn_ptr ( tcx. mk_bare_fn ( ty:: BareFnTy {
400
404
unsafety : impl_m. fty . unsafety ,
401
405
abi : impl_m. fty . abi ,
402
406
sig : ty:: Binder ( impl_sig. clone ( ) ) ,
403
407
} ) ) ;
404
408
debug ! ( "compare_impl_method: impl_fty={:?}" , impl_fty) ;
405
409
406
- let trait_sig = tcx. liberate_late_bound_regions ( infcx. parameter_environment . free_id_outlive ,
407
- & trait_m. fty . sig ) ;
408
- let trait_sig = trait_sig. subst ( tcx, trait_to_skol_substs) ;
409
- let trait_sig = assoc:: normalize_associated_types_in ( & infcx,
410
- & mut fulfillment_cx,
411
- impl_m_span,
412
- impl_m_body_id,
413
- & trait_sig) ;
410
+ let trait_sig = tcx. liberate_late_bound_regions (
411
+ infcx. parameter_environment . free_id_outlive ,
412
+ & trait_m. fty . sig ) ;
413
+ let trait_sig =
414
+ trait_sig. subst ( tcx, trait_to_skol_substs) ;
415
+ let trait_sig =
416
+ assoc:: normalize_associated_types_in ( & infcx,
417
+ & mut fulfillment_cx. borrow_mut ( ) ,
418
+ impl_m_span,
419
+ impl_m_body_id,
420
+ & trait_sig) ;
414
421
let trait_fty = tcx. mk_fn_ptr ( tcx. mk_bare_fn ( ty:: BareFnTy {
415
422
unsafety : trait_m. fty . unsafety ,
416
423
abi : trait_m. fty . abi ,
@@ -454,25 +461,15 @@ pub fn compare_impl_method<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
454
461
455
462
// Check that all obligations are satisfied by the implementation's
456
463
// version.
457
- if let Err ( ref errors) = fulfillment_cx. select_all_or_error ( & infcx) {
464
+ if let Err ( ref errors) = fulfillment_cx. borrow_mut ( ) . select_all_or_error ( & infcx) {
458
465
infcx. report_fulfillment_errors ( errors) ;
459
466
return ;
460
467
}
461
468
462
469
// Finally, resolve all regions. This catches wily misuses of
463
- // lifetime parameters. We have to build up a plausible lifetime
464
- // environment based on what we find in the trait. We could also
465
- // include the obligations derived from the method argument types,
466
- // but I don't think it's necessary -- after all, those are still
467
- // in effect when type-checking the body, and all the
468
- // where-clauses in the header etc should be implied by the trait
469
- // anyway, so it shouldn't be needed there either. Anyway, we can
470
- // always add more relations later (it's backwards compat).
471
- let mut free_regions = FreeRegionMap :: new ( ) ;
472
- free_regions. relate_free_regions_from_predicates (
473
- & infcx. parameter_environment . caller_bounds ) ;
474
-
475
- infcx. resolve_regions_and_report_errors ( & free_regions, impl_m_body_id) ;
470
+ // lifetime parameters.
471
+ let fcx = FnCtxt :: new ( & inh, tcx. types . err , impl_m_body_id) ;
472
+ fcx. regionck_item ( impl_m_body_id, impl_m_span, & [ ] ) ;
476
473
} ) ;
477
474
478
475
fn check_region_bounds_on_impl_method < ' a , ' tcx > ( ccx : & CrateCtxt < ' a , ' tcx > ,
0 commit comments