Skip to content

Commit 6765329

Browse files
committed
Add to_constraint_category to ObligationCause and SubregionOrigin
1 parent 6075877 commit 6765329

File tree

4 files changed

+24
-6
lines changed

4 files changed

+24
-6
lines changed

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> {
249249
// the original values `v_o` that was canonicalized into a
250250
// variable...
251251

252-
let constraint_category = ConstraintCategory::BoringNoLocation;
252+
let constraint_category = cause.to_constraint_category();
253253

254254
for (index, original_value) in original_values.var_values.iter().enumerate() {
255255
// ...with the value `v_r` of that variable from the query.
@@ -643,7 +643,7 @@ pub fn make_query_region_constraints<'tcx>(
643643

644644
let outlives: Vec<_> = constraints
645645
.iter()
646-
.map(|(k, _)| {
646+
.map(|(k, origin)| {
647647
let constraint = ty::Binder::dummy(match *k {
648648
// Swap regions because we are going from sub (<=) to outlives
649649
// (>=).
@@ -660,7 +660,7 @@ pub fn make_query_region_constraints<'tcx>(
660660
Constraint::RegSubReg(r1, r2) => ty::OutlivesPredicate(r2.into(), r1),
661661
});
662662

663-
(constraint, ConstraintCategory::BoringNoLocation)
663+
(constraint, origin.to_constraint_category())
664664
})
665665
.chain(
666666
outlives_obligations

compiler/rustc_infer/src/infer/mod.rs

+10
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ use rustc_middle::infer::canonical::{Canonical, CanonicalVarValues};
2020
use rustc_middle::infer::unify_key::{ConstVarValue, ConstVariableValue};
2121
use rustc_middle::infer::unify_key::{ConstVariableOrigin, ConstVariableOriginKind, ToType};
2222
use rustc_middle::mir::interpret::{ErrorHandled, EvalToValTreeResult};
23+
use rustc_middle::mir::ConstraintCategory;
2324
use rustc_middle::traits::select;
2425
use rustc_middle::ty::abstract_const::{AbstractConst, FailureKind};
2526
use rustc_middle::ty::error::{ExpectedFound, TypeError};
@@ -422,6 +423,15 @@ pub enum SubregionOrigin<'tcx> {
422423
#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
423424
static_assert_size!(SubregionOrigin<'_>, 32);
424425

426+
impl<'tcx> SubregionOrigin<'tcx> {
427+
pub fn to_constraint_category(&self) -> ConstraintCategory<'tcx> {
428+
match self {
429+
Self::Subtype(type_trace) => type_trace.cause.to_constraint_category(),
430+
_ => ConstraintCategory::BoringNoLocation,
431+
}
432+
}
433+
}
434+
425435
/// Times when we replace late-bound regions with variables:
426436
#[derive(Clone, Copy, Debug)]
427437
pub enum LateBoundRegionConversionTime {

compiler/rustc_infer/src/infer/outlives/obligations.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> {
164164

165165
let outlives =
166166
&mut TypeOutlives::new(self, self.tcx, &region_bound_pairs, None, param_env);
167-
let category = ConstraintCategory::BoringNoLocation;
167+
let category = origin.to_constraint_category();
168168
outlives.type_must_outlive(origin, sup_type, sub_region, category);
169169
}
170170
}
@@ -394,7 +394,7 @@ where
394394
if approx_env_bounds.is_empty() && trait_bounds.is_empty() && needs_infer {
395395
debug!("projection_must_outlive: no declared bounds");
396396

397-
let constraint = ConstraintCategory::BoringNoLocation;
397+
let constraint = origin.to_constraint_category();
398398
for k in projection_ty.substs {
399399
match k.unpack() {
400400
GenericArgKind::Lifetime(lt) => {
@@ -444,7 +444,7 @@ where
444444
let unique_bound = trait_bounds[0];
445445
debug!("projection_must_outlive: unique trait bound = {:?}", unique_bound);
446446
debug!("projection_must_outlive: unique declared bound appears in trait ref");
447-
let category = ConstraintCategory::BoringNoLocation;
447+
let category = origin.to_constraint_category();
448448
self.delegate.push_sub_region_constraint(origin, region, unique_bound, category);
449449
return;
450450
}

compiler/rustc_middle/src/traits/mod.rs

+8
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ mod structural_impls;
1010
pub mod util;
1111

1212
use crate::infer::canonical::Canonical;
13+
use crate::mir::ConstraintCategory;
1314
use crate::ty::abstract_const::NotConstEvaluatable;
1415
use crate::ty::subst::SubstsRef;
1516
use crate::ty::{self, AdtKind, Ty, TyCtxt};
@@ -183,6 +184,13 @@ impl<'tcx> ObligationCause<'tcx> {
183184
variant(DerivedObligationCause { parent_trait_pred, parent_code: self.code }).into();
184185
self
185186
}
187+
188+
pub fn to_constraint_category(&self) -> ConstraintCategory<'tcx> {
189+
match self.code() {
190+
MatchImpl(cause, _) => cause.to_constraint_category(),
191+
_ => ConstraintCategory::BoringNoLocation,
192+
}
193+
}
186194
}
187195

188196
#[derive(Clone, Debug, PartialEq, Eq, Hash, Lift)]

0 commit comments

Comments
 (0)