1 // Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
11 use ty::{self, FloatVarValue, IntVarValue, Ty, TyCtxt};
12 use rustc_data_structures::unify::{NoError, EqUnifyValue, UnifyKey, UnifyValue};
15 fn to_type<'a, 'gcx, 'tcx>(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> Ty<'tcx>;
18 impl UnifyKey for ty::IntVid {
19 type Value = Option<IntVarValue>;
20 fn index(&self) -> u32 { self.index }
21 fn from_index(i: u32) -> ty::IntVid { ty::IntVid { index: i } }
22 fn tag() -> &'static str { "IntVid" }
25 impl EqUnifyValue for IntVarValue {
28 #[derive(PartialEq, Copy, Clone, Debug)]
29 pub struct RegionVidKey {
30 /// The minimum region vid in the unification set. This is needed
31 /// to have a canonical name for a type to prevent infinite
33 pub min_vid: ty::RegionVid
36 impl UnifyValue for RegionVidKey {
39 fn unify_values(value1: &Self, value2: &Self) -> Result<Self, NoError> {
40 let min_vid = if value1.min_vid.index() < value2.min_vid.index() {
46 Ok(RegionVidKey { min_vid: min_vid })
50 impl UnifyKey for ty::RegionVid {
51 type Value = RegionVidKey;
52 fn index(&self) -> u32 { self.0 }
53 fn from_index(i: u32) -> ty::RegionVid { ty::RegionVid(i) }
54 fn tag() -> &'static str { "RegionVid" }
57 impl ToType for IntVarValue {
58 fn to_type<'a, 'gcx, 'tcx>(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> Ty<'tcx> {
60 ty::IntType(i) => tcx.mk_mach_int(i),
61 ty::UintType(i) => tcx.mk_mach_uint(i),
66 // Floating point type keys
68 impl UnifyKey for ty::FloatVid {
69 type Value = Option<FloatVarValue>;
70 fn index(&self) -> u32 { self.index }
71 fn from_index(i: u32) -> ty::FloatVid { ty::FloatVid { index: i } }
72 fn tag() -> &'static str { "FloatVid" }
75 impl EqUnifyValue for FloatVarValue {
78 impl ToType for FloatVarValue {
79 fn to_type<'a, 'gcx, 'tcx>(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> Ty<'tcx> {
80 tcx.mk_mach_float(self.0)