@@ -8,10 +8,8 @@ use rustc_hir as hir;
8
8
use rustc_hir:: def_id:: { DefId , LocalDefId , LocalModDefId } ;
9
9
use rustc_hir:: lang_items:: LangItem ;
10
10
use rustc_hir:: ItemKind ;
11
- use rustc_infer:: infer:: outlives:: env:: { OutlivesEnvironment , RegionBoundPairs } ;
12
- use rustc_infer:: infer:: outlives:: obligations:: TypeOutlives ;
11
+ use rustc_infer:: infer:: outlives:: env:: RegionCheckingAssumptions ;
13
12
use rustc_infer:: infer:: { self , InferCtxt , TyCtxtInferExt } ;
14
- use rustc_middle:: mir:: ConstraintCategory ;
15
13
use rustc_middle:: query:: Providers ;
16
14
use rustc_middle:: ty:: trait_def:: TraitSpecializationKind ;
17
15
use rustc_middle:: ty:: {
@@ -23,6 +21,7 @@ use rustc_session::parse::feature_err;
23
21
use rustc_span:: symbol:: { sym, Ident , Symbol } ;
24
22
use rustc_span:: { Span , DUMMY_SP } ;
25
23
use rustc_target:: spec:: abi:: Abi ;
24
+ use rustc_trait_selection:: regions:: InferCtxtRegionExt ;
26
25
use rustc_trait_selection:: traits:: error_reporting:: TypeErrCtxtExt ;
27
26
use rustc_trait_selection:: traits:: misc:: {
28
27
type_allowed_to_implement_const_param_ty, ConstParamTyImplementationError ,
@@ -126,9 +125,9 @@ where
126
125
}
127
126
}
128
127
129
- let outlives_env = OutlivesEnvironment :: with_bounds ( param_env, implied_bounds) ;
128
+ let assumptions = RegionCheckingAssumptions :: with_bounds ( param_env, implied_bounds) ;
130
129
131
- wfcx. ocx . resolve_regions_and_report_errors ( body_def_id, & outlives_env ) ?;
130
+ wfcx. ocx . resolve_regions_and_report_errors ( body_def_id, & assumptions ) ?;
132
131
infcx. tainted_by_errors ( ) . error_reported ( )
133
132
}
134
133
@@ -673,10 +672,12 @@ fn ty_known_to_outlive<'tcx>(
673
672
ty : Ty < ' tcx > ,
674
673
region : ty:: Region < ' tcx > ,
675
674
) -> bool {
676
- resolve_regions_with_wf_tys ( tcx, id, param_env, wf_tys, |infcx, region_bound_pairs| {
677
- let origin = infer:: RelateParamBound ( DUMMY_SP , ty, None ) ;
678
- let outlives = & mut TypeOutlives :: new ( infcx, tcx, region_bound_pairs, None , param_env) ;
679
- outlives. type_must_outlive ( origin, ty, region, ConstraintCategory :: BoringNoLocation ) ;
675
+ test_region_obligations ( tcx, id, param_env, wf_tys, |infcx| {
676
+ infcx. register_region_obligation ( infer:: RegionObligation {
677
+ sub_region : region,
678
+ sup_type : ty,
679
+ origin : infer:: RelateParamBound ( DUMMY_SP , ty, None ) ,
680
+ } ) ;
680
681
} )
681
682
}
682
683
@@ -690,42 +691,34 @@ fn region_known_to_outlive<'tcx>(
690
691
region_a : ty:: Region < ' tcx > ,
691
692
region_b : ty:: Region < ' tcx > ,
692
693
) -> bool {
693
- resolve_regions_with_wf_tys ( tcx, id, param_env, wf_tys, |mut infcx, _| {
694
- use rustc_infer:: infer:: outlives:: obligations:: TypeOutlivesDelegate ;
695
- let origin = infer:: RelateRegionParamBound ( DUMMY_SP ) ;
696
- // `region_a: region_b` -> `region_b <= region_a`
697
- infcx. push_sub_region_constraint (
698
- origin,
699
- region_b,
700
- region_a,
701
- ConstraintCategory :: BoringNoLocation ,
702
- ) ;
694
+ test_region_obligations ( tcx, id, param_env, wf_tys, |infcx| {
695
+ infcx. sub_regions ( infer:: RelateRegionParamBound ( DUMMY_SP ) , region_b, region_a) ;
703
696
} )
704
697
}
705
698
706
699
/// Given a known `param_env` and a set of well formed types, set up an
707
700
/// `InferCtxt`, call the passed function (to e.g. set up region constraints
708
701
/// to be tested), then resolve region and return errors
709
- fn resolve_regions_with_wf_tys < ' tcx > (
702
+ fn test_region_obligations < ' tcx > (
710
703
tcx : TyCtxt < ' tcx > ,
711
704
id : LocalDefId ,
712
705
param_env : ty:: ParamEnv < ' tcx > ,
713
706
wf_tys : & FxIndexSet < Ty < ' tcx > > ,
714
- add_constraints : impl for < ' a > FnOnce ( & ' a InferCtxt < ' tcx > , & ' a RegionBoundPairs < ' tcx > ) ,
707
+ add_constraints : impl FnOnce ( & InferCtxt < ' tcx > ) ,
715
708
) -> bool {
716
709
// Unfortunately, we have to use a new `InferCtxt` each call, because
717
710
// region constraints get added and solved there and we need to test each
718
711
// call individually.
719
712
let infcx = tcx. infer_ctxt ( ) . build ( ) ;
720
- let outlives_environment = OutlivesEnvironment :: with_bounds (
713
+
714
+ add_constraints ( & infcx) ;
715
+
716
+ let outlives_environment = RegionCheckingAssumptions :: with_bounds (
721
717
param_env,
722
718
infcx. implied_bounds_tys ( param_env, id, wf_tys. clone ( ) ) ,
723
719
) ;
724
- let region_bound_pairs = outlives_environment. region_bound_pairs ( ) ;
725
-
726
- add_constraints ( & infcx, region_bound_pairs) ;
727
720
728
- let errors = infcx. resolve_regions ( & outlives_environment) ;
721
+ let errors = infcx. resolve_regions_normalizing_outlives_obligations ( & outlives_environment) ;
729
722
debug ! ( ?errors, "errors" ) ;
730
723
731
724
// If we were able to prove that the type outlives the region without
0 commit comments