1
Fork 0

remove binder from query constraints

This commit is contained in:
lcnr 2023-02-07 10:59:18 +01:00
parent dffea43fc1
commit a04f31dc34
3 changed files with 20 additions and 39 deletions

View file

@ -83,16 +83,8 @@ impl<'a, 'tcx> ConstraintConversion<'a, 'tcx> {
} }
self.constraints.member_constraints = tmp; self.constraints.member_constraints = tmp;
for (predicate, constraint_category) in outlives { for &(predicate, constraint_category) in outlives {
// At the moment, we never generate any "higher-ranked" self.convert(predicate, constraint_category);
// region constraints like `for<'a> 'a: 'b`. At some point
// when we move to universes, we will, and this assertion
// will start to fail.
let predicate = predicate.no_bound_vars().unwrap_or_else(|| {
bug!("query_constraint {:?} contained bound vars", predicate,);
});
self.convert(predicate, *constraint_category);
} }
} }

View file

@ -268,14 +268,12 @@ impl<'tcx> InferCtxt<'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.outlives.push(( output_query_region_constraints
ty::Binder::dummy(ty::OutlivesPredicate(v_o.into(), v_r)), .outlives
constraint_category, .push((ty::OutlivesPredicate(v_o.into(), v_r), constraint_category));
)); output_query_region_constraints
output_query_region_constraints.outlives.push(( .outlives
ty::Binder::dummy(ty::OutlivesPredicate(v_r.into(), v_o)), .push((ty::OutlivesPredicate(v_r.into(), v_o), constraint_category));
constraint_category,
));
} }
} }
@ -318,10 +316,8 @@ impl<'tcx> InferCtxt<'tcx> {
query_response.value.region_constraints.outlives.iter().filter_map(|&r_c| { query_response.value.region_constraints.outlives.iter().filter_map(|&r_c| {
let r_c = substitute_value(self.tcx, &result_subst, r_c); let r_c = substitute_value(self.tcx, &result_subst, r_c);
// Screen out `'a: 'a` cases -- we skip the binder here but // Screen out `'a: 'a` cases.
// only compare the inner values to one another, so they are still at let ty::OutlivesPredicate(k1, r2) = r_c.0;
// consistent binding levels.
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,11 +555,11 @@ impl<'tcx> InferCtxt<'tcx> {
pub fn query_outlives_constraint_to_obligation( pub fn query_outlives_constraint_to_obligation(
&self, &self,
predicate: QueryOutlivesConstraint<'tcx>, (predicate, _): QueryOutlivesConstraint<'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.0.skip_binder(); let ty::OutlivesPredicate(k1, r2) = predicate;
let atom = match k1.unpack() { let atom = match k1.unpack() {
GenericArgKind::Lifetime(r1) => { GenericArgKind::Lifetime(r1) => {
@ -578,7 +574,7 @@ impl<'tcx> InferCtxt<'tcx> {
span_bug!(cause.span, "unexpected const outlives {:?}", predicate); span_bug!(cause.span, "unexpected const outlives {:?}", predicate);
} }
}; };
let predicate = predicate.0.rebind(atom); let predicate = ty::Binder::dummy(atom);
Obligation::new(self.tcx, cause, param_env, predicate) Obligation::new(self.tcx, cause, param_env, predicate)
} }
@ -643,8 +639,7 @@ pub fn make_query_region_constraints<'tcx>(
let outlives: Vec<_> = constraints let outlives: Vec<_> = constraints
.iter() .iter()
.map(|(k, origin)| { .map(|(k, origin)| {
// no bound vars in the code above let constraint = match *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(
@ -658,16 +653,12 @@ 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, origin.to_constraint_category()) (constraint, origin.to_constraint_category())
}) })
.chain( .chain(outlives_obligations.map(|(ty, r, constraint_category)| {
outlives_obligations (ty::OutlivesPredicate(ty.into(), r), constraint_category)
// no bound vars in the code above }))
.map(|(ty, r, constraint_category)| {
(ty::Binder::dummy(ty::OutlivesPredicate(ty.into(), r)), constraint_category)
}),
)
.collect(); .collect();
QueryRegionConstraints { outlives, member_constraints: member_constraints.clone() } QueryRegionConstraints { outlives, member_constraints: member_constraints.clone() }

View file

@ -324,10 +324,8 @@ impl<'tcx, V> Canonical<'tcx, V> {
} }
} }
pub type QueryOutlivesConstraint<'tcx> = ( pub type QueryOutlivesConstraint<'tcx> =
ty::Binder<'tcx, ty::OutlivesPredicate<GenericArg<'tcx>, Region<'tcx>>>, (ty::OutlivesPredicate<GenericArg<'tcx>, Region<'tcx>>, ConstraintCategory<'tcx>);
ConstraintCategory<'tcx>,
);
TrivialTypeTraversalAndLiftImpls! { TrivialTypeTraversalAndLiftImpls! {
for <'tcx> { for <'tcx> {