]> git.proxmox.com Git - rustc.git/blame - src/librustc/middle/infer/unify_key.rs
Imported Upstream version 1.3.0+dfsg1
[rustc.git] / src / librustc / middle / infer / unify_key.rs
CommitLineData
d9579d0f
AL
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.
4//
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.
10
11use middle::ty::{self, IntVarValue, Ty};
12use rustc_data_structures::unify::UnifyKey;
13use syntax::ast;
14
15pub trait ToType<'tcx> {
16 fn to_type(&self, tcx: &ty::ctxt<'tcx>) -> Ty<'tcx>;
17}
18
19impl 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" }
24}
25
26impl<'tcx> ToType<'tcx> for IntVarValue {
27 fn to_type(&self, tcx: &ty::ctxt<'tcx>) -> Ty<'tcx> {
28 match *self {
c1a9b12d
SL
29 ty::IntType(i) => tcx.mk_mach_int(i),
30 ty::UintType(i) => tcx.mk_mach_uint(i),
d9579d0f
AL
31 }
32 }
33}
34
35// Floating point type keys
36
37impl 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" }
42}
43
44impl<'tcx> ToType<'tcx> for ast::FloatTy {
45 fn to_type(&self, tcx: &ty::ctxt<'tcx>) -> Ty<'tcx> {
c1a9b12d 46 tcx.mk_mach_float(*self)
d9579d0f
AL
47 }
48}