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 ty
::{self, IntVarValue, Ty, TyCtxt}
;
13 use rustc_data_structures
::unify
::{Combine, UnifyKey}
;
15 pub trait ToType
<'tcx
> {
16 fn to_type(&self, tcx
: &TyCtxt
<'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 #[derive(PartialEq, Copy, Clone, Debug)]
27 pub struct RegionVidKey
{
28 /// The minimum region vid in the unification set. This is needed
29 /// to have a canonical name for a type to prevent infinite
31 pub min_vid
: ty
::RegionVid
34 impl Combine
for RegionVidKey
{
35 fn combine(&self, other
: &RegionVidKey
) -> RegionVidKey
{
36 let min_vid
= if self.min_vid
.index
< other
.min_vid
.index
{
42 RegionVidKey { min_vid: min_vid }
46 impl UnifyKey
for ty
::RegionVid
{
47 type Value
= RegionVidKey
;
48 fn index(&self) -> u32 { self.index }
49 fn from_index(i
: u32) -> ty
::RegionVid { ty::RegionVid { index: i }
}
50 fn tag(_
: Option
<ty
::RegionVid
>) -> &'
static str { "RegionVid" }
53 impl<'tcx
> ToType
<'tcx
> for IntVarValue
{
54 fn to_type(&self, tcx
: &TyCtxt
<'tcx
>) -> Ty
<'tcx
> {
56 ty
::IntType(i
) => tcx
.mk_mach_int(i
),
57 ty
::UintType(i
) => tcx
.mk_mach_uint(i
),
62 // Floating point type keys
64 impl UnifyKey
for ty
::FloatVid
{
65 type Value
= Option
<ast
::FloatTy
>;
66 fn index(&self) -> u32 { self.index }
67 fn from_index(i
: u32) -> ty
::FloatVid { ty::FloatVid { index: i }
}
68 fn tag(_
: Option
<ty
::FloatVid
>) -> &'
static str { "FloatVid" }
71 impl<'tcx
> ToType
<'tcx
> for ast
::FloatTy
{
72 fn to_type(&self, tcx
: &TyCtxt
<'tcx
>) -> Ty
<'tcx
> {
73 tcx
.mk_mach_float(*self)
77 impl UnifyKey
for ty
::TyVid
{
79 fn index(&self) -> u32 { self.index }
80 fn from_index(i
: u32) -> ty
::TyVid { ty::TyVid { index: i }
}
81 fn tag(_
: Option
<ty
::TyVid
>) -> &'
static str { "TyVid" }