Move traits::query::outlives_bounds::explicit_outlives_bounds to infer::outlives.

This commit is contained in:
Camille GILLOT 2020-02-10 20:39:11 +01:00
parent 98444ca53e
commit 796ca64e9a
4 changed files with 29 additions and 23 deletions

View File

@ -1,11 +1,13 @@
use crate::infer::{GenericKind, InferCtxt};
use crate::traits::query::outlives_bounds::{self, OutlivesBound};
use crate::traits::query::OutlivesBound;
use rustc::ty::free_region_map::FreeRegionMap;
use rustc::ty::{self, Ty};
use rustc_data_structures::fx::FxHashMap;
use rustc_hir as hir;
use rustc_span::Span;
use super::explicit_outlives_bounds;
/// The `OutlivesEnvironment` collects information about what outlives
/// what in a given type-checking setting. For example, if we have a
/// where-clause like `where T: 'a` in scope, then the
@ -76,7 +78,7 @@ impl<'a, 'tcx> OutlivesEnvironment<'tcx> {
region_bound_pairs_accum: vec![],
};
env.add_outlives_bounds(None, outlives_bounds::explicit_outlives_bounds(param_env));
env.add_outlives_bounds(None, explicit_outlives_bounds(param_env));
env
}

View File

@ -3,3 +3,25 @@
pub mod env;
pub mod obligations;
pub mod verify;
use rustc::traits::query::OutlivesBound;
use rustc::ty;
pub fn explicit_outlives_bounds<'tcx>(
param_env: ty::ParamEnv<'tcx>,
) -> impl Iterator<Item = OutlivesBound<'tcx>> + 'tcx {
debug!("explicit_outlives_bounds()");
param_env.caller_bounds.into_iter().filter_map(move |predicate| match predicate {
ty::Predicate::Projection(..)
| ty::Predicate::Trait(..)
| ty::Predicate::Subtype(..)
| ty::Predicate::WellFormed(..)
| ty::Predicate::ObjectSafe(..)
| ty::Predicate::ClosureKind(..)
| ty::Predicate::TypeOutlives(..)
| ty::Predicate::ConstEvaluatable(..) => None,
ty::Predicate::RegionOutlives(ref data) => data
.no_bound_vars()
.map(|ty::OutlivesPredicate(r_a, r_b)| OutlivesBound::RegionSubRegion(r_b, r_a)),
})
}

View File

@ -82,22 +82,3 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> {
result.value
}
}
pub fn explicit_outlives_bounds<'tcx>(
param_env: ty::ParamEnv<'tcx>,
) -> impl Iterator<Item = OutlivesBound<'tcx>> + 'tcx {
debug!("explicit_outlives_bounds()");
param_env.caller_bounds.into_iter().filter_map(move |predicate| match predicate {
ty::Predicate::Projection(..)
| ty::Predicate::Trait(..)
| ty::Predicate::Subtype(..)
| ty::Predicate::WellFormed(..)
| ty::Predicate::ObjectSafe(..)
| ty::Predicate::ClosureKind(..)
| ty::Predicate::TypeOutlives(..)
| ty::Predicate::ConstEvaluatable(..) => None,
ty::Predicate::RegionOutlives(ref data) => data
.no_bound_vars()
.map(|ty::OutlivesPredicate(r_a, r_b)| OutlivesBound::RegionSubRegion(r_b, r_a)),
})
}

View File

@ -1,11 +1,12 @@
use rustc::mir::ConstraintCategory;
use rustc::traits::query::OutlivesBound;
use rustc::ty::free_region_map::FreeRegionRelations;
use rustc::ty::{self, RegionVid, Ty, TyCtxt};
use rustc_data_structures::transitive_relation::TransitiveRelation;
use rustc_infer::infer::canonical::QueryRegionConstraints;
use rustc_infer::infer::outlives;
use rustc_infer::infer::region_constraints::GenericKind;
use rustc_infer::infer::InferCtxt;
use rustc_infer::traits::query::outlives_bounds::{self, OutlivesBound};
use rustc_infer::traits::query::type_op::{self, TypeOp};
use rustc_span::DUMMY_SP;
use std::rc::Rc;
@ -266,7 +267,7 @@ impl UniversalRegionRelationsBuilder<'cx, 'tcx> {
// Insert the facts we know from the predicates. Why? Why not.
let param_env = self.param_env;
self.add_outlives_bounds(outlives_bounds::explicit_outlives_bounds(param_env));
self.add_outlives_bounds(outlives::explicit_outlives_bounds(param_env));
// Finally:
// - outlives is reflexive, so `'r: 'r` for every region `'r`