Skip to content

Commit

Permalink
Add to_constraint_category to ObligationCause and SubregionOrigin
Browse files Browse the repository at this point in the history
  • Loading branch information
jackh726 committed Sep 16, 2022
1 parent 6075877 commit 6765329
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 6 deletions.
6 changes: 3 additions & 3 deletions compiler/rustc_infer/src/infer/canonical/query_response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> {
// the original values `v_o` that was canonicalized into a
// variable...

let constraint_category = ConstraintCategory::BoringNoLocation;
let constraint_category = cause.to_constraint_category();

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

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

(constraint, ConstraintCategory::BoringNoLocation)
(constraint, origin.to_constraint_category())
})
.chain(
outlives_obligations
Expand Down
10 changes: 10 additions & 0 deletions compiler/rustc_infer/src/infer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ use rustc_middle::infer::canonical::{Canonical, CanonicalVarValues};
use rustc_middle::infer::unify_key::{ConstVarValue, ConstVariableValue};
use rustc_middle::infer::unify_key::{ConstVariableOrigin, ConstVariableOriginKind, ToType};
use rustc_middle::mir::interpret::{ErrorHandled, EvalToValTreeResult};
use rustc_middle::mir::ConstraintCategory;
use rustc_middle::traits::select;
use rustc_middle::ty::abstract_const::{AbstractConst, FailureKind};
use rustc_middle::ty::error::{ExpectedFound, TypeError};
Expand Down Expand Up @@ -422,6 +423,15 @@ pub enum SubregionOrigin<'tcx> {
#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
static_assert_size!(SubregionOrigin<'_>, 32);

impl<'tcx> SubregionOrigin<'tcx> {
pub fn to_constraint_category(&self) -> ConstraintCategory<'tcx> {
match self {
Self::Subtype(type_trace) => type_trace.cause.to_constraint_category(),
_ => ConstraintCategory::BoringNoLocation,
}
}
}

/// Times when we replace late-bound regions with variables:
#[derive(Clone, Copy, Debug)]
pub enum LateBoundRegionConversionTime {
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_infer/src/infer/outlives/obligations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> {

let outlives =
&mut TypeOutlives::new(self, self.tcx, &region_bound_pairs, None, param_env);
let category = ConstraintCategory::BoringNoLocation;
let category = origin.to_constraint_category();
outlives.type_must_outlive(origin, sup_type, sub_region, category);
}
}
Expand Down Expand Up @@ -394,7 +394,7 @@ where
if approx_env_bounds.is_empty() && trait_bounds.is_empty() && needs_infer {
debug!("projection_must_outlive: no declared bounds");

let constraint = ConstraintCategory::BoringNoLocation;
let constraint = origin.to_constraint_category();
for k in projection_ty.substs {
match k.unpack() {
GenericArgKind::Lifetime(lt) => {
Expand Down Expand Up @@ -444,7 +444,7 @@ where
let unique_bound = trait_bounds[0];
debug!("projection_must_outlive: unique trait bound = {:?}", unique_bound);
debug!("projection_must_outlive: unique declared bound appears in trait ref");
let category = ConstraintCategory::BoringNoLocation;
let category = origin.to_constraint_category();
self.delegate.push_sub_region_constraint(origin, region, unique_bound, category);
return;
}
Expand Down
8 changes: 8 additions & 0 deletions compiler/rustc_middle/src/traits/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ mod structural_impls;
pub mod util;

use crate::infer::canonical::Canonical;
use crate::mir::ConstraintCategory;
use crate::ty::abstract_const::NotConstEvaluatable;
use crate::ty::subst::SubstsRef;
use crate::ty::{self, AdtKind, Ty, TyCtxt};
Expand Down Expand Up @@ -183,6 +184,13 @@ impl<'tcx> ObligationCause<'tcx> {
variant(DerivedObligationCause { parent_trait_pred, parent_code: self.code }).into();
self
}

pub fn to_constraint_category(&self) -> ConstraintCategory<'tcx> {
match self.code() {
MatchImpl(cause, _) => cause.to_constraint_category(),
_ => ConstraintCategory::BoringNoLocation,
}
}
}

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

0 comments on commit 6765329

Please sign in to comment.