mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-23 07:14:28 +00:00
Add to_constraint_category to ObligationCause and SubregionOrigin
This commit is contained in:
parent
6075877c89
commit
67653292be
@ -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.
|
||||
@ -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
|
||||
// (>=).
|
||||
@ -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
|
||||
|
@ -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};
|
||||
@ -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 {
|
||||
|
@ -164,7 +164,7 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> {
|
||||
|
||||
let outlives =
|
||||
&mut TypeOutlives::new(self, self.tcx, ®ion_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);
|
||||
}
|
||||
}
|
||||
@ -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) => {
|
||||
@ -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;
|
||||
}
|
||||
|
@ -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};
|
||||
@ -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)]
|
||||
|
Loading…
Reference in New Issue
Block a user