Skip to content

Commit e181b40

Browse files
No need to pass region bound pairs to resolve_regions_with_wf_tys
1 parent 791a53f commit e181b40

File tree

1 file changed

+14
-22
lines changed

1 file changed

+14
-22
lines changed

compiler/rustc_hir_analysis/src/check/wfcheck.rs

+14-22
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,8 @@ use rustc_hir as hir;
88
use rustc_hir::def_id::{DefId, LocalDefId, LocalModDefId};
99
use rustc_hir::lang_items::LangItem;
1010
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::OutlivesEnvironment;
1312
use rustc_infer::infer::{self, InferCtxt, TyCtxtInferExt};
14-
use rustc_middle::mir::ConstraintCategory;
1513
use rustc_middle::query::Providers;
1614
use rustc_middle::ty::trait_def::TraitSpecializationKind;
1715
use rustc_middle::ty::{
@@ -677,10 +675,12 @@ fn ty_known_to_outlive<'tcx>(
677675
ty: Ty<'tcx>,
678676
region: ty::Region<'tcx>,
679677
) -> bool {
680-
resolve_regions_with_wf_tys(tcx, id, param_env, wf_tys, |infcx, region_bound_pairs| {
681-
let origin = infer::RelateParamBound(DUMMY_SP, ty, None);
682-
let outlives = &mut TypeOutlives::new(infcx, tcx, region_bound_pairs, None, param_env);
683-
outlives.type_must_outlive(origin, ty, region, ConstraintCategory::BoringNoLocation);
678+
test_region_obligations(tcx, id, param_env, wf_tys, |infcx| {
679+
infcx.register_region_obligation(infer::RegionObligation {
680+
sub_region: region,
681+
sup_type: ty,
682+
origin: infer::RelateParamBound(DUMMY_SP, ty, None),
683+
});
684684
})
685685
}
686686

@@ -694,40 +694,32 @@ fn region_known_to_outlive<'tcx>(
694694
region_a: ty::Region<'tcx>,
695695
region_b: ty::Region<'tcx>,
696696
) -> bool {
697-
resolve_regions_with_wf_tys(tcx, id, param_env, wf_tys, |mut infcx, _| {
698-
use rustc_infer::infer::outlives::obligations::TypeOutlivesDelegate;
699-
let origin = infer::RelateRegionParamBound(DUMMY_SP);
700-
// `region_a: region_b` -> `region_b <= region_a`
701-
infcx.push_sub_region_constraint(
702-
origin,
703-
region_b,
704-
region_a,
705-
ConstraintCategory::BoringNoLocation,
706-
);
697+
test_region_obligations(tcx, id, param_env, wf_tys, |infcx| {
698+
infcx.sub_regions(infer::RelateRegionParamBound(DUMMY_SP), region_b, region_a);
707699
})
708700
}
709701

710702
/// Given a known `param_env` and a set of well formed types, set up an
711703
/// `InferCtxt`, call the passed function (to e.g. set up region constraints
712704
/// to be tested), then resolve region and return errors
713-
fn resolve_regions_with_wf_tys<'tcx>(
705+
fn test_region_obligations<'tcx>(
714706
tcx: TyCtxt<'tcx>,
715707
id: LocalDefId,
716708
param_env: ty::ParamEnv<'tcx>,
717709
wf_tys: &FxIndexSet<Ty<'tcx>>,
718-
add_constraints: impl for<'a> FnOnce(&'a InferCtxt<'tcx>, &'a RegionBoundPairs<'tcx>),
710+
add_constraints: impl FnOnce(&InferCtxt<'tcx>),
719711
) -> bool {
720712
// Unfortunately, we have to use a new `InferCtxt` each call, because
721713
// region constraints get added and solved there and we need to test each
722714
// call individually.
723715
let infcx = tcx.infer_ctxt().build();
716+
717+
add_constraints(&infcx);
718+
724719
let outlives_environment = OutlivesEnvironment::with_bounds(
725720
param_env,
726721
infcx.implied_bounds_tys(param_env, id, wf_tys.clone()),
727722
);
728-
let region_bound_pairs = outlives_environment.region_bound_pairs();
729-
730-
add_constraints(&infcx, region_bound_pairs);
731723

732724
let errors = infcx.resolve_regions(&outlives_environment);
733725
debug!(?errors, "errors");

0 commit comments

Comments
 (0)