Yeet QueryTypeRelatingDelegate
This commit is contained in:
parent
f8131a48a4
commit
da1e6a8c1c
3 changed files with 18 additions and 106 deletions
|
@ -12,22 +12,19 @@ use crate::infer::canonical::{
|
|||
Canonical, CanonicalQueryResponse, CanonicalVarValues, Certainty, OriginalQueryValues,
|
||||
QueryOutlivesConstraint, QueryRegionConstraints, QueryResponse,
|
||||
};
|
||||
use crate::infer::nll_relate::{TypeRelating, TypeRelatingDelegate};
|
||||
use crate::infer::region_constraints::{Constraint, RegionConstraintData};
|
||||
use crate::infer::{DefineOpaqueTypes, InferCtxt, InferOk, InferResult, NllRegionVariableOrigin};
|
||||
use crate::infer::{DefineOpaqueTypes, InferCtxt, InferOk, InferResult};
|
||||
use crate::traits::query::NoSolution;
|
||||
use crate::traits::{Obligation, ObligationCause, PredicateObligation};
|
||||
use crate::traits::{PredicateObligations, TraitEngine, TraitEngineExt};
|
||||
use crate::traits::{TraitEngine, TraitEngineExt};
|
||||
use rustc_data_structures::captures::Captures;
|
||||
use rustc_index::Idx;
|
||||
use rustc_index::IndexVec;
|
||||
use rustc_middle::arena::ArenaAllocatable;
|
||||
use rustc_middle::mir::ConstraintCategory;
|
||||
use rustc_middle::ty::fold::TypeFoldable;
|
||||
use rustc_middle::ty::relate::TypeRelation;
|
||||
use rustc_middle::ty::{self, BoundVar, ToPredicate, Ty, TyCtxt};
|
||||
use rustc_middle::ty::{self, BoundVar, Ty, TyCtxt};
|
||||
use rustc_middle::ty::{GenericArg, GenericArgKind};
|
||||
use rustc_span::{Span, Symbol};
|
||||
use std::fmt::Debug;
|
||||
use std::iter;
|
||||
|
||||
|
@ -290,31 +287,19 @@ impl<'tcx> InferCtxt<'tcx> {
|
|||
}
|
||||
|
||||
(GenericArgKind::Type(v1), GenericArgKind::Type(v2)) => {
|
||||
TypeRelating::new(
|
||||
self,
|
||||
QueryTypeRelatingDelegate {
|
||||
infcx: self,
|
||||
param_env,
|
||||
cause,
|
||||
obligations: &mut obligations,
|
||||
},
|
||||
ty::Variance::Invariant,
|
||||
)
|
||||
.relate(v1, v2)?;
|
||||
obligations.extend(
|
||||
self.at(&cause, param_env)
|
||||
.eq(DefineOpaqueTypes::Yes, v1, v2)?
|
||||
.into_obligations(),
|
||||
);
|
||||
}
|
||||
|
||||
(GenericArgKind::Const(v1), GenericArgKind::Const(v2)) => {
|
||||
TypeRelating::new(
|
||||
self,
|
||||
QueryTypeRelatingDelegate {
|
||||
infcx: self,
|
||||
param_env,
|
||||
cause,
|
||||
obligations: &mut obligations,
|
||||
},
|
||||
ty::Variance::Invariant,
|
||||
)
|
||||
.relate(v1, v2)?;
|
||||
obligations.extend(
|
||||
self.at(&cause, param_env)
|
||||
.eq(DefineOpaqueTypes::Yes, v1, v2)?
|
||||
.into_obligations(),
|
||||
);
|
||||
}
|
||||
|
||||
_ => {
|
||||
|
@ -697,60 +682,3 @@ pub fn make_query_region_constraints<'tcx>(
|
|||
|
||||
QueryRegionConstraints { outlives, member_constraints: member_constraints.clone() }
|
||||
}
|
||||
|
||||
struct QueryTypeRelatingDelegate<'a, 'tcx> {
|
||||
infcx: &'a InferCtxt<'tcx>,
|
||||
obligations: &'a mut Vec<PredicateObligation<'tcx>>,
|
||||
param_env: ty::ParamEnv<'tcx>,
|
||||
cause: &'a ObligationCause<'tcx>,
|
||||
}
|
||||
|
||||
impl<'tcx> TypeRelatingDelegate<'tcx> for QueryTypeRelatingDelegate<'_, 'tcx> {
|
||||
fn span(&self) -> Span {
|
||||
self.cause.span
|
||||
}
|
||||
|
||||
fn param_env(&self) -> ty::ParamEnv<'tcx> {
|
||||
self.param_env
|
||||
}
|
||||
|
||||
fn create_next_universe(&mut self) -> ty::UniverseIndex {
|
||||
self.infcx.create_next_universe()
|
||||
}
|
||||
|
||||
fn next_existential_region_var(
|
||||
&mut self,
|
||||
from_forall: bool,
|
||||
_name: Option<Symbol>,
|
||||
) -> ty::Region<'tcx> {
|
||||
let origin = NllRegionVariableOrigin::Existential { from_forall };
|
||||
self.infcx.next_nll_region_var(origin)
|
||||
}
|
||||
|
||||
fn next_placeholder_region(&mut self, placeholder: ty::PlaceholderRegion) -> ty::Region<'tcx> {
|
||||
ty::Region::new_placeholder(self.infcx.tcx, placeholder)
|
||||
}
|
||||
|
||||
fn push_outlives(
|
||||
&mut self,
|
||||
sup: ty::Region<'tcx>,
|
||||
sub: ty::Region<'tcx>,
|
||||
_info: ty::VarianceDiagInfo<'tcx>,
|
||||
) {
|
||||
self.obligations.push(Obligation {
|
||||
cause: self.cause.clone(),
|
||||
param_env: self.param_env,
|
||||
predicate: ty::ClauseKind::RegionOutlives(ty::OutlivesPredicate(sup, sub))
|
||||
.to_predicate(self.infcx.tcx),
|
||||
recursion_depth: 0,
|
||||
});
|
||||
}
|
||||
|
||||
fn forbid_inference_vars() -> bool {
|
||||
true
|
||||
}
|
||||
|
||||
fn register_obligations(&mut self, obligations: PredicateObligations<'tcx>) {
|
||||
self.obligations.extend(obligations);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -96,10 +96,6 @@ pub trait TypeRelatingDelegate<'tcx> {
|
|||
/// we will invoke this method to instantiate `'b` with a
|
||||
/// placeholder region.
|
||||
fn next_placeholder_region(&mut self, placeholder: ty::PlaceholderRegion) -> ty::Region<'tcx>;
|
||||
|
||||
/// Enables some optimizations if we do not expect inference variables
|
||||
/// in the RHS of the relation.
|
||||
fn forbid_inference_vars() -> bool;
|
||||
}
|
||||
|
||||
impl<'me, 'tcx, D> TypeRelating<'me, 'tcx, D>
|
||||
|
@ -316,16 +312,11 @@ where
|
|||
}
|
||||
|
||||
#[instrument(skip(self), level = "debug")]
|
||||
fn tys(&mut self, a: Ty<'tcx>, mut b: Ty<'tcx>) -> RelateResult<'tcx, Ty<'tcx>> {
|
||||
fn tys(&mut self, a: Ty<'tcx>, b: Ty<'tcx>) -> RelateResult<'tcx, Ty<'tcx>> {
|
||||
let infcx = self.infcx;
|
||||
|
||||
let a = self.infcx.shallow_resolve(a);
|
||||
|
||||
if !D::forbid_inference_vars() {
|
||||
b = self.infcx.shallow_resolve(b);
|
||||
} else {
|
||||
assert!(!b.has_non_region_infer(), "unexpected inference var {:?}", b);
|
||||
}
|
||||
assert!(!b.has_non_region_infer(), "unexpected inference var {:?}", b);
|
||||
|
||||
if a == b {
|
||||
return Ok(a);
|
||||
|
@ -409,16 +400,13 @@ where
|
|||
fn consts(
|
||||
&mut self,
|
||||
a: ty::Const<'tcx>,
|
||||
mut b: ty::Const<'tcx>,
|
||||
b: ty::Const<'tcx>,
|
||||
) -> RelateResult<'tcx, ty::Const<'tcx>> {
|
||||
let a = self.infcx.shallow_resolve(a);
|
||||
|
||||
if !D::forbid_inference_vars() {
|
||||
b = self.infcx.shallow_resolve(b);
|
||||
}
|
||||
assert!(!b.has_non_region_infer(), "unexpected inference var {:?}", b);
|
||||
|
||||
match b.kind() {
|
||||
ty::ConstKind::Infer(InferConst::Var(_)) if D::forbid_inference_vars() => {
|
||||
ty::ConstKind::Infer(InferConst::Var(_)) => {
|
||||
// Forbid inference variables in the RHS.
|
||||
self.infcx
|
||||
.dcx()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue