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.
12 use middle::ty::{self, IntVarValue, Ty};
13 use rustc_data_structures::unify::UnifyKey;
15 pub trait ToType<'tcx> {
16 fn to_type(&self, tcx: &ty::ctxt<'tcx>) -> Ty<'tcx>;
19 impl UnifyKey for ty::IntVid {
20 type Value = Option<IntVarValue>;
21 fn index(&self) -> u32 { self.index }
22 fn from_index(i: u32) -> ty::IntVid { ty::IntVid { index: i } }
23 fn tag(_: Option<ty::IntVid>) -> &'static str { "IntVid" }
26 impl<'tcx> ToType<'tcx> for IntVarValue {
27 fn to_type(&self, tcx: &ty::ctxt<'tcx>) -> Ty<'tcx> {
29 ty::IntType(i) => tcx.mk_mach_int(i),
30 ty::UintType(i) => tcx.mk_mach_uint(i),
35 // Floating point type keys
37 impl UnifyKey for ty::FloatVid {
38 type Value = Option<ast::FloatTy>;
39 fn index(&self) -> u32 { self.index }
40 fn from_index(i: u32) -> ty::FloatVid { ty::FloatVid { index: i } }
41 fn tag(_: Option<ty::FloatVid>) -> &'static str { "FloatVid" }
44 impl<'tcx> ToType<'tcx> for ast::FloatTy {
45 fn to_type(&self, tcx: &ty::ctxt<'tcx>) -> Ty<'tcx> {
46 tcx.mk_mach_float(*self)