Skip to content

Commit c4e3cc0

Browse files
committed
Move TermVid out of rustc_middle.
It's only used in `rustc_infer`.
1 parent b44eb11 commit c4e3cc0

File tree

2 files changed

+26
-28
lines changed

2 files changed

+26
-28
lines changed

compiler/rustc_infer/src/infer/relate/generalize.rs

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,24 @@ use crate::infer::type_variable::TypeVariableValue;
1919
use crate::infer::unify_key::ConstVariableValue;
2020
use crate::infer::{InferCtxt, RegionVariableOrigin, relate};
2121

22+
#[derive(Copy, Clone, Eq, PartialEq, Debug)]
23+
enum TermVid {
24+
Ty(ty::TyVid),
25+
Const(ty::ConstVid),
26+
}
27+
28+
impl From<ty::TyVid> for TermVid {
29+
fn from(value: ty::TyVid) -> Self {
30+
TermVid::Ty(value)
31+
}
32+
}
33+
34+
impl From<ty::ConstVid> for TermVid {
35+
fn from(value: ty::ConstVid) -> Self {
36+
TermVid::Const(value)
37+
}
38+
}
39+
2240
impl<'tcx> InferCtxt<'tcx> {
2341
/// The idea is that we should ensure that the type variable `target_vid`
2442
/// is equal to, a subtype of, or a supertype of `source_ty`.
@@ -238,20 +256,18 @@ impl<'tcx> InferCtxt<'tcx> {
238256
&self,
239257
span: Span,
240258
structurally_relate_aliases: StructurallyRelateAliases,
241-
target_vid: impl Into<ty::TermVid>,
259+
target_vid: impl Into<TermVid>,
242260
ambient_variance: ty::Variance,
243261
source_term: T,
244262
) -> RelateResult<'tcx, Generalization<T>> {
245263
assert!(!source_term.has_escaping_bound_vars());
246264
let (for_universe, root_vid) = match target_vid.into() {
247-
ty::TermVid::Ty(ty_vid) => {
248-
(self.probe_ty_var(ty_vid).unwrap_err(), ty::TermVid::Ty(self.root_var(ty_vid)))
265+
TermVid::Ty(ty_vid) => {
266+
(self.probe_ty_var(ty_vid).unwrap_err(), TermVid::Ty(self.root_var(ty_vid)))
249267
}
250-
ty::TermVid::Const(ct_vid) => (
268+
TermVid::Const(ct_vid) => (
251269
self.probe_const_var(ct_vid).unwrap_err(),
252-
ty::TermVid::Const(
253-
self.inner.borrow_mut().const_unification_table().find(ct_vid).vid,
254-
),
270+
TermVid::Const(self.inner.borrow_mut().const_unification_table().find(ct_vid).vid),
255271
),
256272
};
257273

@@ -299,7 +315,7 @@ struct Generalizer<'me, 'tcx> {
299315
/// The vid of the type variable that is in the process of being
300316
/// instantiated. If we find this within the value we are folding,
301317
/// that means we would have created a cyclic value.
302-
root_vid: ty::TermVid,
318+
root_vid: TermVid,
303319

304320
/// The universe of the type variable that is in the process of being
305321
/// instantiated. If we find anything that this universe cannot name,
@@ -469,7 +485,7 @@ impl<'tcx> TypeRelation<TyCtxt<'tcx>> for Generalizer<'_, 'tcx> {
469485
ty::Infer(ty::TyVar(vid)) => {
470486
let mut inner = self.infcx.inner.borrow_mut();
471487
let vid = inner.type_variables().root_var(vid);
472-
if ty::TermVid::Ty(vid) == self.root_vid {
488+
if TermVid::Ty(vid) == self.root_vid {
473489
// If sub-roots are equal, then `root_vid` and
474490
// `vid` are related via subtyping.
475491
Err(self.cyclic_term_error())
@@ -621,7 +637,7 @@ impl<'tcx> TypeRelation<TyCtxt<'tcx>> for Generalizer<'_, 'tcx> {
621637
// If root const vids are equal, then `root_vid` and
622638
// `vid` are related and we'd be inferring an infinitely
623639
// deep const.
624-
if ty::TermVid::Const(
640+
if TermVid::Const(
625641
self.infcx.inner.borrow_mut().const_unification_table().find(vid).vid,
626642
) == self.root_vid
627643
{

compiler/rustc_middle/src/ty/mod.rs

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -673,24 +673,6 @@ impl<'tcx> TermKind<'tcx> {
673673
}
674674
}
675675

676-
#[derive(Copy, Clone, Eq, PartialEq, Debug)]
677-
pub enum TermVid {
678-
Ty(ty::TyVid),
679-
Const(ty::ConstVid),
680-
}
681-
682-
impl From<ty::TyVid> for TermVid {
683-
fn from(value: ty::TyVid) -> Self {
684-
TermVid::Ty(value)
685-
}
686-
}
687-
688-
impl From<ty::ConstVid> for TermVid {
689-
fn from(value: ty::ConstVid) -> Self {
690-
TermVid::Const(value)
691-
}
692-
}
693-
694676
/// Represents the bounds declared on a particular set of type
695677
/// parameters. Should eventually be generalized into a flag list of
696678
/// where-clauses. You can obtain an `InstantiatedPredicates` list from a

0 commit comments

Comments
 (0)