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 {}
17 #[derive(PartialEq, Copy, Clone, Debug)]
18 pub struct RegionVidKey {
19 /// The minimum region vid in the unification set. This is needed
20 /// to have a canonical name for a type to prevent infinite
22 pub min_vid: ty::RegionVid
25 impl UnifyValue for RegionVidKey {
28 fn unify_values(value1: &Self, value2: &Self) -> Result<Self, NoError> {
29 let min_vid = if value1.min_vid.index() < value2.min_vid.index() {
35 Ok(RegionVidKey { min_vid })
39 impl UnifyKey for ty::RegionVid {
40 type Value = RegionVidKey;
41 fn index(&self) -> u32 { u32::from(*self) }
42 fn from_index(i: u32) -> ty::RegionVid { ty::RegionVid::from(i) }
43 fn tag() -> &'static str { "RegionVid" }
46 impl ToType for IntVarValue {
47 fn to_type<'a, 'gcx, 'tcx>(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> Ty<'tcx> {
49 ty::IntType(i) => tcx.mk_mach_int(i),
50 ty::UintType(i) => tcx.mk_mach_uint(i),
55 // Floating point type keys
57 impl UnifyKey for ty::FloatVid {
58 type Value = Option<FloatVarValue>;
59 fn index(&self) -> u32 { self.index }
60 fn from_index(i: u32) -> ty::FloatVid { ty::FloatVid { index: i } }
61 fn tag() -> &'static str { "FloatVid" }
64 impl EqUnifyValue for FloatVarValue {}
66 impl ToType for FloatVarValue {
67 fn to_type<'a, 'gcx, 'tcx>(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> Ty<'tcx> {
68 tcx.mk_mach_float(self.0)