Make QueryOutlivesConstraint contain a ConstraintCategory
This commit is contained in:
parent
4d4e51e428
commit
a46376e247
6 changed files with 64 additions and 36 deletions
|
@ -2295,7 +2295,13 @@ impl<'tcx> ClosureRegionRequirementsExt<'tcx> for ClosureRegionRequirements<'tcx
|
||||||
outlives_requirement={:?}",
|
outlives_requirement={:?}",
|
||||||
region, outlived_region, outlives_requirement,
|
region, outlived_region, outlives_requirement,
|
||||||
);
|
);
|
||||||
ty::Binder::dummy(ty::OutlivesPredicate(region.into(), outlived_region))
|
(
|
||||||
|
ty::Binder::dummy(ty::OutlivesPredicate(
|
||||||
|
region.into(),
|
||||||
|
outlived_region,
|
||||||
|
)),
|
||||||
|
ConstraintCategory::BoringNoLocation,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
ClosureOutlivesSubject::Ty(ty) => {
|
ClosureOutlivesSubject::Ty(ty) => {
|
||||||
|
@ -2305,7 +2311,10 @@ impl<'tcx> ClosureRegionRequirementsExt<'tcx> for ClosureRegionRequirements<'tcx
|
||||||
outlives_requirement={:?}",
|
outlives_requirement={:?}",
|
||||||
ty, outlived_region, outlives_requirement,
|
ty, outlived_region, outlives_requirement,
|
||||||
);
|
);
|
||||||
ty::Binder::dummy(ty::OutlivesPredicate(ty.into(), outlived_region))
|
(
|
||||||
|
ty::Binder::dummy(ty::OutlivesPredicate(ty.into(), outlived_region)),
|
||||||
|
ConstraintCategory::BoringNoLocation,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
|
@ -98,10 +98,13 @@ impl<'a, 'tcx> ConstraintConversion<'a, 'tcx> {
|
||||||
// region constraints like `for<'a> 'a: 'b`. At some point
|
// region constraints like `for<'a> 'a: 'b`. At some point
|
||||||
// when we move to universes, we will, and this assertion
|
// when we move to universes, we will, and this assertion
|
||||||
// will start to fail.
|
// will start to fail.
|
||||||
let ty::OutlivesPredicate(k1, r2) = query_constraint.no_bound_vars().unwrap_or_else(|| {
|
let ty::OutlivesPredicate(k1, r2) =
|
||||||
|
query_constraint.0.no_bound_vars().unwrap_or_else(|| {
|
||||||
bug!("query_constraint {:?} contained bound vars", query_constraint,);
|
bug!("query_constraint {:?} contained bound vars", query_constraint,);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
let _constraint_category = query_constraint.1;
|
||||||
|
|
||||||
match k1.unpack() {
|
match k1.unpack() {
|
||||||
GenericArgKind::Lifetime(r1) => {
|
GenericArgKind::Lifetime(r1) => {
|
||||||
let r1_vid = self.to_region_vid(r1);
|
let r1_vid = self.to_region_vid(r1);
|
||||||
|
|
|
@ -2591,7 +2591,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
|
||||||
.enumerate()
|
.enumerate()
|
||||||
.filter_map(|(idx, constraint)| {
|
.filter_map(|(idx, constraint)| {
|
||||||
let ty::OutlivesPredicate(k1, r2) =
|
let ty::OutlivesPredicate(k1, r2) =
|
||||||
constraint.no_bound_vars().unwrap_or_else(|| {
|
constraint.0.no_bound_vars().unwrap_or_else(|| {
|
||||||
bug!("query_constraint {:?} contained bound vars", constraint,);
|
bug!("query_constraint {:?} contained bound vars", constraint,);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -22,6 +22,7 @@ use rustc_data_structures::captures::Captures;
|
||||||
use rustc_index::vec::Idx;
|
use rustc_index::vec::Idx;
|
||||||
use rustc_index::vec::IndexVec;
|
use rustc_index::vec::IndexVec;
|
||||||
use rustc_middle::arena::ArenaAllocatable;
|
use rustc_middle::arena::ArenaAllocatable;
|
||||||
|
use rustc_middle::mir::ConstraintCategory;
|
||||||
use rustc_middle::ty::error::TypeError;
|
use rustc_middle::ty::error::TypeError;
|
||||||
use rustc_middle::ty::fold::TypeFoldable;
|
use rustc_middle::ty::fold::TypeFoldable;
|
||||||
use rustc_middle::ty::relate::TypeRelation;
|
use rustc_middle::ty::relate::TypeRelation;
|
||||||
|
@ -248,6 +249,8 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> {
|
||||||
// the original values `v_o` that was canonicalized into a
|
// the original values `v_o` that was canonicalized into a
|
||||||
// variable...
|
// variable...
|
||||||
|
|
||||||
|
let constraint_category = ConstraintCategory::BoringNoLocation;
|
||||||
|
|
||||||
for (index, original_value) in original_values.var_values.iter().enumerate() {
|
for (index, original_value) in original_values.var_values.iter().enumerate() {
|
||||||
// ...with the value `v_r` of that variable from the query.
|
// ...with the value `v_r` of that variable from the query.
|
||||||
let result_value = query_response.substitute_projected(self.tcx, &result_subst, |v| {
|
let result_value = query_response.substitute_projected(self.tcx, &result_subst, |v| {
|
||||||
|
@ -263,12 +266,14 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> {
|
||||||
(GenericArgKind::Lifetime(v_o), GenericArgKind::Lifetime(v_r)) => {
|
(GenericArgKind::Lifetime(v_o), GenericArgKind::Lifetime(v_r)) => {
|
||||||
// To make `v_o = v_r`, we emit `v_o: v_r` and `v_r: v_o`.
|
// To make `v_o = v_r`, we emit `v_o: v_r` and `v_r: v_o`.
|
||||||
if v_o != v_r {
|
if v_o != v_r {
|
||||||
output_query_region_constraints
|
output_query_region_constraints.outlives.push((
|
||||||
.outlives
|
ty::Binder::dummy(ty::OutlivesPredicate(v_o.into(), v_r)),
|
||||||
.push(ty::Binder::dummy(ty::OutlivesPredicate(v_o.into(), v_r)));
|
constraint_category,
|
||||||
output_query_region_constraints
|
));
|
||||||
.outlives
|
output_query_region_constraints.outlives.push((
|
||||||
.push(ty::Binder::dummy(ty::OutlivesPredicate(v_r.into(), v_o)));
|
ty::Binder::dummy(ty::OutlivesPredicate(v_r.into(), v_o)),
|
||||||
|
constraint_category,
|
||||||
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -314,7 +319,7 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> {
|
||||||
// Screen out `'a: 'a` cases -- we skip the binder here but
|
// Screen out `'a: 'a` cases -- we skip the binder here but
|
||||||
// only compare the inner values to one another, so they are still at
|
// only compare the inner values to one another, so they are still at
|
||||||
// consistent binding levels.
|
// consistent binding levels.
|
||||||
let ty::OutlivesPredicate(k1, r2) = r_c.skip_binder();
|
let ty::OutlivesPredicate(k1, r2) = r_c.0.skip_binder();
|
||||||
if k1 != r2.into() { Some(r_c) } else { None }
|
if k1 != r2.into() { Some(r_c) } else { None }
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
@ -559,7 +564,7 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> {
|
||||||
cause: ObligationCause<'tcx>,
|
cause: ObligationCause<'tcx>,
|
||||||
param_env: ty::ParamEnv<'tcx>,
|
param_env: ty::ParamEnv<'tcx>,
|
||||||
) -> Obligation<'tcx, ty::Predicate<'tcx>> {
|
) -> Obligation<'tcx, ty::Predicate<'tcx>> {
|
||||||
let ty::OutlivesPredicate(k1, r2) = predicate.skip_binder();
|
let ty::OutlivesPredicate(k1, r2) = predicate.0.skip_binder();
|
||||||
|
|
||||||
let atom = match k1.unpack() {
|
let atom = match k1.unpack() {
|
||||||
GenericArgKind::Lifetime(r1) => {
|
GenericArgKind::Lifetime(r1) => {
|
||||||
|
@ -574,7 +579,7 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> {
|
||||||
span_bug!(cause.span, "unexpected const outlives {:?}", predicate);
|
span_bug!(cause.span, "unexpected const outlives {:?}", predicate);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
let predicate = predicate.rebind(atom).to_predicate(self.tcx);
|
let predicate = predicate.0.rebind(atom).to_predicate(self.tcx);
|
||||||
|
|
||||||
Obligation::new(cause, param_env, predicate)
|
Obligation::new(cause, param_env, predicate)
|
||||||
}
|
}
|
||||||
|
@ -638,7 +643,8 @@ pub fn make_query_region_constraints<'tcx>(
|
||||||
|
|
||||||
let outlives: Vec<_> = constraints
|
let outlives: Vec<_> = constraints
|
||||||
.iter()
|
.iter()
|
||||||
.map(|(k, _)| match *k {
|
.map(|(k, _)| {
|
||||||
|
let constraint = ty::Binder::dummy(match *k {
|
||||||
// Swap regions because we are going from sub (<=) to outlives
|
// Swap regions because we are going from sub (<=) to outlives
|
||||||
// (>=).
|
// (>=).
|
||||||
Constraint::VarSubVar(v1, v2) => ty::OutlivesPredicate(
|
Constraint::VarSubVar(v1, v2) => ty::OutlivesPredicate(
|
||||||
|
@ -652,12 +658,19 @@ pub fn make_query_region_constraints<'tcx>(
|
||||||
ty::OutlivesPredicate(tcx.mk_region(ty::ReVar(v2)).into(), r1)
|
ty::OutlivesPredicate(tcx.mk_region(ty::ReVar(v2)).into(), r1)
|
||||||
}
|
}
|
||||||
Constraint::RegSubReg(r1, r2) => ty::OutlivesPredicate(r2.into(), r1),
|
Constraint::RegSubReg(r1, r2) => ty::OutlivesPredicate(r2.into(), r1),
|
||||||
|
});
|
||||||
|
|
||||||
|
(constraint, ConstraintCategory::BoringNoLocation)
|
||||||
})
|
})
|
||||||
.map(ty::Binder::dummy) // no bound vars in the code above
|
|
||||||
.chain(
|
.chain(
|
||||||
outlives_obligations
|
outlives_obligations
|
||||||
.map(|(ty, r)| ty::OutlivesPredicate(ty.into(), r))
|
// no bound vars in the code above
|
||||||
.map(ty::Binder::dummy), // no bound vars in the code above
|
.map(|(ty, r)| {
|
||||||
|
(
|
||||||
|
ty::Binder::dummy(ty::OutlivesPredicate(ty.into(), r)),
|
||||||
|
ConstraintCategory::BoringNoLocation,
|
||||||
|
)
|
||||||
|
}),
|
||||||
)
|
)
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
|
|
|
@ -22,6 +22,7 @@
|
||||||
//! [c]: https://rust-lang.github.io/chalk/book/canonical_queries/canonicalization.html
|
//! [c]: https://rust-lang.github.io/chalk/book/canonical_queries/canonicalization.html
|
||||||
|
|
||||||
use crate::infer::MemberConstraint;
|
use crate::infer::MemberConstraint;
|
||||||
|
use crate::mir::ConstraintCategory;
|
||||||
use crate::ty::subst::GenericArg;
|
use crate::ty::subst::GenericArg;
|
||||||
use crate::ty::{self, BoundVar, List, Region, Ty, TyCtxt};
|
use crate::ty::{self, BoundVar, List, Region, Ty, TyCtxt};
|
||||||
use rustc_index::vec::IndexVec;
|
use rustc_index::vec::IndexVec;
|
||||||
|
@ -301,8 +302,10 @@ impl<'tcx, V> Canonical<'tcx, V> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub type QueryOutlivesConstraint<'tcx> =
|
pub type QueryOutlivesConstraint<'tcx> = (
|
||||||
ty::Binder<'tcx, ty::OutlivesPredicate<GenericArg<'tcx>, Region<'tcx>>>;
|
ty::Binder<'tcx, ty::OutlivesPredicate<GenericArg<'tcx>, Region<'tcx>>>,
|
||||||
|
ConstraintCategory<'tcx>,
|
||||||
|
);
|
||||||
|
|
||||||
TrivialTypeTraversalAndLiftImpls! {
|
TrivialTypeTraversalAndLiftImpls! {
|
||||||
for <'tcx> {
|
for <'tcx> {
|
||||||
|
|
|
@ -327,7 +327,7 @@ rustc_data_structures::static_assert_size!(ConstraintCategory<'_>, 16);
|
||||||
///
|
///
|
||||||
/// See also `rustc_const_eval::borrow_check::constraints`.
|
/// See also `rustc_const_eval::borrow_check::constraints`.
|
||||||
#[derive(Copy, Clone, Debug, Eq, PartialEq, PartialOrd, Ord, Hash)]
|
#[derive(Copy, Clone, Debug, Eq, PartialEq, PartialOrd, Ord, Hash)]
|
||||||
#[derive(TyEncodable, TyDecodable, HashStable)]
|
#[derive(TyEncodable, TyDecodable, HashStable, Lift, TypeVisitable, TypeFoldable)]
|
||||||
pub enum ConstraintCategory<'tcx> {
|
pub enum ConstraintCategory<'tcx> {
|
||||||
Return(ReturnConstraint),
|
Return(ReturnConstraint),
|
||||||
Yield,
|
Yield,
|
||||||
|
@ -369,7 +369,7 @@ pub enum ConstraintCategory<'tcx> {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Copy, Clone, Debug, Eq, PartialEq, PartialOrd, Ord, Hash)]
|
#[derive(Copy, Clone, Debug, Eq, PartialEq, PartialOrd, Ord, Hash)]
|
||||||
#[derive(TyEncodable, TyDecodable, HashStable)]
|
#[derive(TyEncodable, TyDecodable, HashStable, TypeVisitable, TypeFoldable)]
|
||||||
pub enum ReturnConstraint {
|
pub enum ReturnConstraint {
|
||||||
Normal,
|
Normal,
|
||||||
ClosureUpvar(Field),
|
ClosureUpvar(Field),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue