Skip to content

Commit 0f5dae0

Browse files
committed
switch to use VerifyBound instead of RegionTest
1 parent 2392a09 commit 0f5dae0

File tree

2 files changed

+27
-72
lines changed

2 files changed

+27
-72
lines changed

src/librustc_mir/borrow_check/nll/region_infer/mod.rs

Lines changed: 24 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use borrow_check::nll::type_check::free_region_relations::UniversalRegionRelatio
1616
use borrow_check::nll::type_check::Locations;
1717
use rustc::hir::def_id::DefId;
1818
use rustc::infer::canonical::QueryRegionConstraint;
19-
use rustc::infer::region_constraints::{GenericKind, VarInfos};
19+
use rustc::infer::region_constraints::{GenericKind, VarInfos, VerifyBound};
2020
use rustc::infer::{InferCtxt, NLLRegionVariableOrigin, RegionVariableOrigin};
2121
use rustc::mir::{
2222
ClosureOutlivesRequirement, ClosureOutlivesSubject, ClosureRegionRequirements, Local, Location,
@@ -160,33 +160,7 @@ pub struct TypeTest<'tcx> {
160160

161161
/// A test which, if met by the region `'x`, proves that this type
162162
/// constraint is satisfied.
163-
pub test: RegionTest,
164-
}
165-
166-
/// A "test" that can be applied to some "subject region" `'x`. These are used to
167-
/// describe type constraints. Tests do not presently affect the
168-
/// region values that get inferred for each variable; they only
169-
/// examine the results *after* inference. This means they can
170-
/// conveniently include disjuction ("a or b must be true").
171-
#[derive(Clone, Debug)]
172-
pub enum RegionTest {
173-
/// The subject region `'x` must by outlived by the given region.
174-
///
175-
/// This test comes from e.g. a where clause like `T: 'a`, which
176-
/// implies that we know that `T: 'a`. Therefore, if we are trying
177-
/// to prove that `T: 'x`, we can do so by showing that `'a: 'x`.
178-
IsOutlivedBy(RegionVid),
179-
180-
/// Any of the given tests are true.
181-
///
182-
/// This test comes from e.g. a where clause like `T: 'a + 'b`,
183-
/// which implies that we know that `T: 'a` and that `T:
184-
/// 'b`. Therefore, if we are trying to prove that `T: 'x`, we can
185-
/// do so by showing that `'a: 'x` *or* `'b: 'x`.
186-
Any(Vec<RegionTest>),
187-
188-
/// All of the given tests are true.
189-
All(Vec<RegionTest>),
163+
pub verify_bound: VerifyBound<'tcx>,
190164
}
191165

192166
impl<'tcx> RegionInferenceContext<'tcx> {
@@ -571,7 +545,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
571545
for type_test in &self.type_tests {
572546
debug!("check_type_test: {:?}", type_test);
573547

574-
if self.eval_region_test(mir, type_test.lower_bound, &type_test.test) {
548+
if self.eval_verify_bound(mir, type_test.lower_bound, &type_test.verify_bound) {
575549
continue;
576550
}
577551

@@ -678,7 +652,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
678652
generic_kind,
679653
lower_bound,
680654
locations,
681-
test: _,
655+
verify_bound: _,
682656
} = type_test;
683657

684658
let generic_ty = generic_kind.to_ty(tcx);
@@ -705,7 +679,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
705679
// where `ur` is a local bound -- we are sometimes in a
706680
// position to prove things that our caller cannot. See
707681
// #53570 for an example.
708-
if self.eval_region_test(mir, ur, &type_test.test) {
682+
if self.eval_verify_bound(mir, ur, &type_test.verify_bound) {
709683
continue;
710684
}
711685

@@ -877,22 +851,32 @@ impl<'tcx> RegionInferenceContext<'tcx> {
877851

878852
/// Test if `test` is true when applied to `lower_bound` at
879853
/// `point`, and returns true or false.
880-
fn eval_region_test(&self, mir: &Mir<'tcx>, lower_bound: RegionVid, test: &RegionTest) -> bool {
854+
fn eval_verify_bound(
855+
&self,
856+
mir: &Mir<'tcx>,
857+
lower_bound: RegionVid,
858+
verify_bound: &VerifyBound<'tcx>,
859+
) -> bool {
881860
debug!(
882-
"eval_region_test(lower_bound={:?}, test={:?})",
883-
lower_bound, test
861+
"eval_verify_bound(lower_bound={:?}, verify_bound={:?})",
862+
lower_bound, verify_bound
884863
);
885864

886-
match test {
887-
RegionTest::IsOutlivedBy(r) => self.eval_outlives(mir, *r, lower_bound),
865+
match verify_bound {
866+
VerifyBound::IfEq(..) => false, // FIXME
867+
868+
VerifyBound::OutlivedBy(r) => {
869+
let r_vid = self.to_region_vid(r);
870+
self.eval_outlives(mir, r_vid, lower_bound)
871+
}
888872

889-
RegionTest::Any(tests) => tests
873+
VerifyBound::AnyBound(verify_bounds) => verify_bounds
890874
.iter()
891-
.any(|test| self.eval_region_test(mir, lower_bound, test)),
875+
.any(|verify_bound| self.eval_verify_bound(mir, lower_bound, verify_bound)),
892876

893-
RegionTest::All(tests) => tests
877+
VerifyBound::AllBounds(verify_bounds) => verify_bounds
894878
.iter()
895-
.all(|test| self.eval_region_test(mir, lower_bound, test)),
879+
.all(|verify_bound| self.eval_verify_bound(mir, lower_bound, verify_bound)),
896880
}
897881
}
898882

src/librustc_mir/borrow_check/nll/type_check/constraint_conversion.rs

Lines changed: 3 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
use borrow_check::location::LocationTable;
1212
use borrow_check::nll::constraints::{ConstraintCategory, ConstraintSet, OutlivesConstraint};
1313
use borrow_check::nll::facts::AllFacts;
14-
use borrow_check::nll::region_infer::{RegionTest, TypeTest};
14+
use borrow_check::nll::region_infer::TypeTest;
1515
use borrow_check::nll::type_check::Locations;
1616
use borrow_check::nll::universal_regions::UniversalRegions;
1717
use rustc::infer::canonical::QueryRegionConstraint;
@@ -140,44 +140,15 @@ impl<'a, 'gcx, 'tcx> ConstraintConversion<'a, 'gcx, 'tcx> {
140140
&self,
141141
generic_kind: GenericKind<'tcx>,
142142
region: ty::Region<'tcx>,
143-
bound: VerifyBound<'tcx>,
143+
verify_bound: VerifyBound<'tcx>,
144144
) -> TypeTest<'tcx> {
145145
let lower_bound = self.to_region_vid(region);
146146

147-
let test = self.verify_bound_to_region_test(&bound);
148-
149147
TypeTest {
150148
generic_kind,
151149
lower_bound,
152150
locations: self.locations,
153-
test,
154-
}
155-
}
156-
157-
fn verify_bound_to_region_test(&self, verify_bound: &VerifyBound<'tcx>) -> RegionTest {
158-
match verify_bound {
159-
VerifyBound::IfEq(..) => {
160-
// FIXME: always false right now
161-
RegionTest::Any(vec![])
162-
}
163-
164-
VerifyBound::OutlivedBy(r) => RegionTest::IsOutlivedBy(
165-
self.to_region_vid(r)
166-
),
167-
168-
VerifyBound::AnyBound(bounds) => RegionTest::Any(
169-
bounds
170-
.iter()
171-
.map(|b| self.verify_bound_to_region_test(b))
172-
.collect(),
173-
),
174-
175-
VerifyBound::AllBounds(bounds) => RegionTest::All(
176-
bounds
177-
.iter()
178-
.map(|b| self.verify_bound_to_region_test(b))
179-
.collect(),
180-
),
151+
verify_bound,
181152
}
182153
}
183154

0 commit comments

Comments
 (0)