Move TermVid out of rustc_middle.
It's only used in `rustc_infer`.
This commit is contained in:
@@ -19,6 +19,24 @@ use crate::infer::type_variable::TypeVariableValue;
|
|||||||
use crate::infer::unify_key::ConstVariableValue;
|
use crate::infer::unify_key::ConstVariableValue;
|
||||||
use crate::infer::{InferCtxt, RegionVariableOrigin, relate};
|
use crate::infer::{InferCtxt, RegionVariableOrigin, relate};
|
||||||
|
|
||||||
|
#[derive(Copy, Clone, Eq, PartialEq, Debug)]
|
||||||
|
enum TermVid {
|
||||||
|
Ty(ty::TyVid),
|
||||||
|
Const(ty::ConstVid),
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<ty::TyVid> for TermVid {
|
||||||
|
fn from(value: ty::TyVid) -> Self {
|
||||||
|
TermVid::Ty(value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<ty::ConstVid> for TermVid {
|
||||||
|
fn from(value: ty::ConstVid) -> Self {
|
||||||
|
TermVid::Const(value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl<'tcx> InferCtxt<'tcx> {
|
impl<'tcx> InferCtxt<'tcx> {
|
||||||
/// The idea is that we should ensure that the type variable `target_vid`
|
/// The idea is that we should ensure that the type variable `target_vid`
|
||||||
/// is equal to, a subtype of, or a supertype of `source_ty`.
|
/// is equal to, a subtype of, or a supertype of `source_ty`.
|
||||||
@@ -238,20 +256,18 @@ impl<'tcx> InferCtxt<'tcx> {
|
|||||||
&self,
|
&self,
|
||||||
span: Span,
|
span: Span,
|
||||||
structurally_relate_aliases: StructurallyRelateAliases,
|
structurally_relate_aliases: StructurallyRelateAliases,
|
||||||
target_vid: impl Into<ty::TermVid>,
|
target_vid: impl Into<TermVid>,
|
||||||
ambient_variance: ty::Variance,
|
ambient_variance: ty::Variance,
|
||||||
source_term: T,
|
source_term: T,
|
||||||
) -> RelateResult<'tcx, Generalization<T>> {
|
) -> RelateResult<'tcx, Generalization<T>> {
|
||||||
assert!(!source_term.has_escaping_bound_vars());
|
assert!(!source_term.has_escaping_bound_vars());
|
||||||
let (for_universe, root_vid) = match target_vid.into() {
|
let (for_universe, root_vid) = match target_vid.into() {
|
||||||
ty::TermVid::Ty(ty_vid) => {
|
TermVid::Ty(ty_vid) => {
|
||||||
(self.probe_ty_var(ty_vid).unwrap_err(), ty::TermVid::Ty(self.root_var(ty_vid)))
|
(self.probe_ty_var(ty_vid).unwrap_err(), TermVid::Ty(self.root_var(ty_vid)))
|
||||||
}
|
}
|
||||||
ty::TermVid::Const(ct_vid) => (
|
TermVid::Const(ct_vid) => (
|
||||||
self.probe_const_var(ct_vid).unwrap_err(),
|
self.probe_const_var(ct_vid).unwrap_err(),
|
||||||
ty::TermVid::Const(
|
TermVid::Const(self.inner.borrow_mut().const_unification_table().find(ct_vid).vid),
|
||||||
self.inner.borrow_mut().const_unification_table().find(ct_vid).vid,
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -299,7 +315,7 @@ struct Generalizer<'me, 'tcx> {
|
|||||||
/// The vid of the type variable that is in the process of being
|
/// The vid of the type variable that is in the process of being
|
||||||
/// instantiated. If we find this within the value we are folding,
|
/// instantiated. If we find this within the value we are folding,
|
||||||
/// that means we would have created a cyclic value.
|
/// that means we would have created a cyclic value.
|
||||||
root_vid: ty::TermVid,
|
root_vid: TermVid,
|
||||||
|
|
||||||
/// The universe of the type variable that is in the process of being
|
/// The universe of the type variable that is in the process of being
|
||||||
/// instantiated. If we find anything that this universe cannot name,
|
/// instantiated. If we find anything that this universe cannot name,
|
||||||
@@ -469,7 +485,7 @@ impl<'tcx> TypeRelation<TyCtxt<'tcx>> for Generalizer<'_, 'tcx> {
|
|||||||
ty::Infer(ty::TyVar(vid)) => {
|
ty::Infer(ty::TyVar(vid)) => {
|
||||||
let mut inner = self.infcx.inner.borrow_mut();
|
let mut inner = self.infcx.inner.borrow_mut();
|
||||||
let vid = inner.type_variables().root_var(vid);
|
let vid = inner.type_variables().root_var(vid);
|
||||||
if ty::TermVid::Ty(vid) == self.root_vid {
|
if TermVid::Ty(vid) == self.root_vid {
|
||||||
// If sub-roots are equal, then `root_vid` and
|
// If sub-roots are equal, then `root_vid` and
|
||||||
// `vid` are related via subtyping.
|
// `vid` are related via subtyping.
|
||||||
Err(self.cyclic_term_error())
|
Err(self.cyclic_term_error())
|
||||||
@@ -621,7 +637,7 @@ impl<'tcx> TypeRelation<TyCtxt<'tcx>> for Generalizer<'_, 'tcx> {
|
|||||||
// If root const vids are equal, then `root_vid` and
|
// If root const vids are equal, then `root_vid` and
|
||||||
// `vid` are related and we'd be inferring an infinitely
|
// `vid` are related and we'd be inferring an infinitely
|
||||||
// deep const.
|
// deep const.
|
||||||
if ty::TermVid::Const(
|
if TermVid::Const(
|
||||||
self.infcx.inner.borrow_mut().const_unification_table().find(vid).vid,
|
self.infcx.inner.borrow_mut().const_unification_table().find(vid).vid,
|
||||||
) == self.root_vid
|
) == self.root_vid
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -673,24 +673,6 @@ impl<'tcx> TermKind<'tcx> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Copy, Clone, Eq, PartialEq, Debug)]
|
|
||||||
pub enum TermVid {
|
|
||||||
Ty(ty::TyVid),
|
|
||||||
Const(ty::ConstVid),
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<ty::TyVid> for TermVid {
|
|
||||||
fn from(value: ty::TyVid) -> Self {
|
|
||||||
TermVid::Ty(value)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<ty::ConstVid> for TermVid {
|
|
||||||
fn from(value: ty::ConstVid) -> Self {
|
|
||||||
TermVid::Const(value)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Represents the bounds declared on a particular set of type
|
/// Represents the bounds declared on a particular set of type
|
||||||
/// parameters. Should eventually be generalized into a flag list of
|
/// parameters. Should eventually be generalized into a flag list of
|
||||||
/// where-clauses. You can obtain an `InstantiatedPredicates` list from a
|
/// where-clauses. You can obtain an `InstantiatedPredicates` list from a
|
||||||
|
|||||||
Reference in New Issue
Block a user