1 use crate::ty::{self, FloatVarValue, IntVarValue, Ty, TyCtxt};
2 use rustc_data_structures::unify::{NoError, EqUnifyValue, UnifyKey, UnifyValue};
5 fn to_type<'a, 'gcx, 'tcx>(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> Ty<'tcx>;
8 impl UnifyKey for ty::IntVid {
9 type Value = Option<IntVarValue>;
10 fn index(&self) -> u32 { self.index }
11 fn from_index(i: u32) -> ty::IntVid { ty::IntVid { index: i } }
12 fn tag() -> &'static str { "IntVid" }
15 impl EqUnifyValue for IntVarValue {
18 #[derive(PartialEq, Copy, Clone, Debug)]
19 pub struct RegionVidKey {
20 /// The minimum region vid in the unification set. This is needed
21 /// to have a canonical name for a type to prevent infinite
23 pub min_vid: ty::RegionVid
26 impl UnifyValue for RegionVidKey {
29 fn unify_values(value1: &Self, value2: &Self) -> Result<Self, NoError> {
30 let min_vid = if value1.min_vid.index() < value2.min_vid.index() {
36 Ok(RegionVidKey { min_vid })
40 impl UnifyKey for ty::RegionVid {
41 type Value = RegionVidKey;
42 fn index(&self) -> u32 { u32::from(*self) }
43 fn from_index(i: u32) -> ty::RegionVid { ty::RegionVid::from(i) }
44 fn tag() -> &'static str { "RegionVid" }
47 impl ToType for IntVarValue {
48 fn to_type<'a, 'gcx, 'tcx>(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> Ty<'tcx> {
50 ty::IntType(i) => tcx.mk_mach_int(i),
51 ty::UintType(i) => tcx.mk_mach_uint(i),
56 // Floating point type keys
58 impl UnifyKey for ty::FloatVid {
59 type Value = Option<FloatVarValue>;
60 fn index(&self) -> u32 { self.index }
61 fn from_index(i: u32) -> ty::FloatVid { ty::FloatVid { index: i } }
62 fn tag() -> &'static str { "FloatVid" }
65 impl EqUnifyValue for FloatVarValue {
68 impl ToType for FloatVarValue {
69 fn to_type<'a, 'gcx, 'tcx>(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> Ty<'tcx> {
70 tcx.mk_mach_float(self.0)