Skip to content

Commit a46376e

Browse files
committed
Make QueryOutlivesConstraint contain a ConstraintCategory
1 parent 4d4e51e commit a46376e

File tree

6 files changed

+64
-36
lines changed

6 files changed

+64
-36
lines changed

compiler/rustc_borrowck/src/region_infer/mod.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2295,7 +2295,13 @@ impl<'tcx> ClosureRegionRequirementsExt<'tcx> for ClosureRegionRequirements<'tcx
22952295
outlives_requirement={:?}",
22962296
region, outlived_region, outlives_requirement,
22972297
);
2298-
ty::Binder::dummy(ty::OutlivesPredicate(region.into(), outlived_region))
2298+
(
2299+
ty::Binder::dummy(ty::OutlivesPredicate(
2300+
region.into(),
2301+
outlived_region,
2302+
)),
2303+
ConstraintCategory::BoringNoLocation,
2304+
)
22992305
}
23002306

23012307
ClosureOutlivesSubject::Ty(ty) => {
@@ -2305,7 +2311,10 @@ impl<'tcx> ClosureRegionRequirementsExt<'tcx> for ClosureRegionRequirements<'tcx
23052311
outlives_requirement={:?}",
23062312
ty, outlived_region, outlives_requirement,
23072313
);
2308-
ty::Binder::dummy(ty::OutlivesPredicate(ty.into(), outlived_region))
2314+
(
2315+
ty::Binder::dummy(ty::OutlivesPredicate(ty.into(), outlived_region)),
2316+
ConstraintCategory::BoringNoLocation,
2317+
)
23092318
}
23102319
}
23112320
})

compiler/rustc_borrowck/src/type_check/constraint_conversion.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,12 @@ impl<'a, 'tcx> ConstraintConversion<'a, 'tcx> {
9898
// region constraints like `for<'a> 'a: 'b`. At some point
9999
// when we move to universes, we will, and this assertion
100100
// will start to fail.
101-
let ty::OutlivesPredicate(k1, r2) = query_constraint.no_bound_vars().unwrap_or_else(|| {
102-
bug!("query_constraint {:?} contained bound vars", query_constraint,);
103-
});
101+
let ty::OutlivesPredicate(k1, r2) =
102+
query_constraint.0.no_bound_vars().unwrap_or_else(|| {
103+
bug!("query_constraint {:?} contained bound vars", query_constraint,);
104+
});
105+
106+
let _constraint_category = query_constraint.1;
104107

105108
match k1.unpack() {
106109
GenericArgKind::Lifetime(r1) => {

compiler/rustc_borrowck/src/type_check/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2591,7 +2591,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
25912591
.enumerate()
25922592
.filter_map(|(idx, constraint)| {
25932593
let ty::OutlivesPredicate(k1, r2) =
2594-
constraint.no_bound_vars().unwrap_or_else(|| {
2594+
constraint.0.no_bound_vars().unwrap_or_else(|| {
25952595
bug!("query_constraint {:?} contained bound vars", constraint,);
25962596
});
25972597

compiler/rustc_infer/src/infer/canonical/query_response.rs

Lines changed: 39 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ use rustc_data_structures::captures::Captures;
2222
use rustc_index::vec::Idx;
2323
use rustc_index::vec::IndexVec;
2424
use rustc_middle::arena::ArenaAllocatable;
25+
use rustc_middle::mir::ConstraintCategory;
2526
use rustc_middle::ty::error::TypeError;
2627
use rustc_middle::ty::fold::TypeFoldable;
2728
use rustc_middle::ty::relate::TypeRelation;
@@ -248,6 +249,8 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> {
248249
// the original values `v_o` that was canonicalized into a
249250
// variable...
250251

252+
let constraint_category = ConstraintCategory::BoringNoLocation;
253+
251254
for (index, original_value) in original_values.var_values.iter().enumerate() {
252255
// ...with the value `v_r` of that variable from the query.
253256
let result_value = query_response.substitute_projected(self.tcx, &result_subst, |v| {
@@ -263,12 +266,14 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> {
263266
(GenericArgKind::Lifetime(v_o), GenericArgKind::Lifetime(v_r)) => {
264267
// To make `v_o = v_r`, we emit `v_o: v_r` and `v_r: v_o`.
265268
if v_o != v_r {
266-
output_query_region_constraints
267-
.outlives
268-
.push(ty::Binder::dummy(ty::OutlivesPredicate(v_o.into(), v_r)));
269-
output_query_region_constraints
270-
.outlives
271-
.push(ty::Binder::dummy(ty::OutlivesPredicate(v_r.into(), v_o)));
269+
output_query_region_constraints.outlives.push((
270+
ty::Binder::dummy(ty::OutlivesPredicate(v_o.into(), v_r)),
271+
constraint_category,
272+
));
273+
output_query_region_constraints.outlives.push((
274+
ty::Binder::dummy(ty::OutlivesPredicate(v_r.into(), v_o)),
275+
constraint_category,
276+
));
272277
}
273278
}
274279

@@ -314,7 +319,7 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> {
314319
// Screen out `'a: 'a` cases -- we skip the binder here but
315320
// only compare the inner values to one another, so they are still at
316321
// consistent binding levels.
317-
let ty::OutlivesPredicate(k1, r2) = r_c.skip_binder();
322+
let ty::OutlivesPredicate(k1, r2) = r_c.0.skip_binder();
318323
if k1 != r2.into() { Some(r_c) } else { None }
319324
}),
320325
);
@@ -559,7 +564,7 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> {
559564
cause: ObligationCause<'tcx>,
560565
param_env: ty::ParamEnv<'tcx>,
561566
) -> Obligation<'tcx, ty::Predicate<'tcx>> {
562-
let ty::OutlivesPredicate(k1, r2) = predicate.skip_binder();
567+
let ty::OutlivesPredicate(k1, r2) = predicate.0.skip_binder();
563568

564569
let atom = match k1.unpack() {
565570
GenericArgKind::Lifetime(r1) => {
@@ -574,7 +579,7 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> {
574579
span_bug!(cause.span, "unexpected const outlives {:?}", predicate);
575580
}
576581
};
577-
let predicate = predicate.rebind(atom).to_predicate(self.tcx);
582+
let predicate = predicate.0.rebind(atom).to_predicate(self.tcx);
578583

579584
Obligation::new(cause, param_env, predicate)
580585
}
@@ -638,26 +643,34 @@ pub fn make_query_region_constraints<'tcx>(
638643

639644
let outlives: Vec<_> = constraints
640645
.iter()
641-
.map(|(k, _)| match *k {
642-
// Swap regions because we are going from sub (<=) to outlives
643-
// (>=).
644-
Constraint::VarSubVar(v1, v2) => ty::OutlivesPredicate(
645-
tcx.mk_region(ty::ReVar(v2)).into(),
646-
tcx.mk_region(ty::ReVar(v1)),
647-
),
648-
Constraint::VarSubReg(v1, r2) => {
649-
ty::OutlivesPredicate(r2.into(), tcx.mk_region(ty::ReVar(v1)))
650-
}
651-
Constraint::RegSubVar(r1, v2) => {
652-
ty::OutlivesPredicate(tcx.mk_region(ty::ReVar(v2)).into(), r1)
653-
}
654-
Constraint::RegSubReg(r1, r2) => ty::OutlivesPredicate(r2.into(), r1),
646+
.map(|(k, _)| {
647+
let constraint = ty::Binder::dummy(match *k {
648+
// Swap regions because we are going from sub (<=) to outlives
649+
// (>=).
650+
Constraint::VarSubVar(v1, v2) => ty::OutlivesPredicate(
651+
tcx.mk_region(ty::ReVar(v2)).into(),
652+
tcx.mk_region(ty::ReVar(v1)),
653+
),
654+
Constraint::VarSubReg(v1, r2) => {
655+
ty::OutlivesPredicate(r2.into(), tcx.mk_region(ty::ReVar(v1)))
656+
}
657+
Constraint::RegSubVar(r1, v2) => {
658+
ty::OutlivesPredicate(tcx.mk_region(ty::ReVar(v2)).into(), r1)
659+
}
660+
Constraint::RegSubReg(r1, r2) => ty::OutlivesPredicate(r2.into(), r1),
661+
});
662+
663+
(constraint, ConstraintCategory::BoringNoLocation)
655664
})
656-
.map(ty::Binder::dummy) // no bound vars in the code above
657665
.chain(
658666
outlives_obligations
659-
.map(|(ty, r)| ty::OutlivesPredicate(ty.into(), r))
660-
.map(ty::Binder::dummy), // no bound vars in the code above
667+
// no bound vars in the code above
668+
.map(|(ty, r)| {
669+
(
670+
ty::Binder::dummy(ty::OutlivesPredicate(ty.into(), r)),
671+
ConstraintCategory::BoringNoLocation,
672+
)
673+
}),
661674
)
662675
.collect();
663676

compiler/rustc_middle/src/infer/canonical.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
//! [c]: https://rust-lang.github.io/chalk/book/canonical_queries/canonicalization.html
2323
2424
use crate::infer::MemberConstraint;
25+
use crate::mir::ConstraintCategory;
2526
use crate::ty::subst::GenericArg;
2627
use crate::ty::{self, BoundVar, List, Region, Ty, TyCtxt};
2728
use rustc_index::vec::IndexVec;
@@ -301,8 +302,10 @@ impl<'tcx, V> Canonical<'tcx, V> {
301302
}
302303
}
303304

304-
pub type QueryOutlivesConstraint<'tcx> =
305-
ty::Binder<'tcx, ty::OutlivesPredicate<GenericArg<'tcx>, Region<'tcx>>>;
305+
pub type QueryOutlivesConstraint<'tcx> = (
306+
ty::Binder<'tcx, ty::OutlivesPredicate<GenericArg<'tcx>, Region<'tcx>>>,
307+
ConstraintCategory<'tcx>,
308+
);
306309

307310
TrivialTypeTraversalAndLiftImpls! {
308311
for <'tcx> {

compiler/rustc_middle/src/mir/query.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ rustc_data_structures::static_assert_size!(ConstraintCategory<'_>, 16);
327327
///
328328
/// See also `rustc_const_eval::borrow_check::constraints`.
329329
#[derive(Copy, Clone, Debug, Eq, PartialEq, PartialOrd, Ord, Hash)]
330-
#[derive(TyEncodable, TyDecodable, HashStable)]
330+
#[derive(TyEncodable, TyDecodable, HashStable, Lift, TypeVisitable, TypeFoldable)]
331331
pub enum ConstraintCategory<'tcx> {
332332
Return(ReturnConstraint),
333333
Yield,
@@ -369,7 +369,7 @@ pub enum ConstraintCategory<'tcx> {
369369
}
370370

371371
#[derive(Copy, Clone, Debug, Eq, PartialEq, PartialOrd, Ord, Hash)]
372-
#[derive(TyEncodable, TyDecodable, HashStable)]
372+
#[derive(TyEncodable, TyDecodable, HashStable, TypeVisitable, TypeFoldable)]
373373
pub enum ReturnConstraint {
374374
Normal,
375375
ClosureUpvar(Field),

0 commit comments

Comments
 (0)