@@ -15,7 +15,7 @@ use cast::transmute;
1515use cmp:: Eq ;
1616use option:: { Option , Some , None } ;
1717use to_str:: ToStr ;
18- use unstable:: intrinsics:: { TyDesc , get_tydesc , forget } ;
18+ use unstable:: intrinsics;
1919use util:: Void ;
2020
2121///////////////////////////////////////////////////////////////////////////////
@@ -24,15 +24,30 @@ use util::Void;
2424///////////////////////////////////////////////////////////////////////////////
2525
2626/// `TypeId` represents a globally unique identifier for a type
27+ #[ cfg( stage0) ]
2728pub struct TypeId {
28- priv t: * TyDesc
29+ priv t: * intrinsics:: TyDesc ,
30+ }
31+
32+ /// `TypeId` represents a globally unique identifier for a type
33+ #[ cfg( not( stage0) ) ]
34+ pub struct TypeId {
35+ priv t: u64 ,
2936}
3037
3138impl TypeId {
3239 /// Returns the `TypeId` of the type this generic function has been instantiated with
3340 #[ inline]
34- pub fn of < T > ( ) -> TypeId {
35- TypeId { t : unsafe { get_tydesc :: < T > ( ) } }
41+ #[ cfg( stage0) ]
42+ pub fn of < T : ' static > ( ) -> TypeId {
43+ TypeId { t : unsafe { intrinsics:: get_tydesc :: < T > ( ) } }
44+ }
45+
46+ /// Returns the `TypeId` of the type this generic function has been instantiated with
47+ #[ inline]
48+ #[ cfg( not( stage0) ) ]
49+ pub fn of < T : ' static > ( ) -> TypeId {
50+ TypeId { t : unsafe { intrinsics:: type_id :: < T > ( ) } }
3651 }
3752}
3853
@@ -50,22 +65,32 @@ impl Eq for TypeId {
5065/// The `Any` trait is implemented by all types, and can be used as a trait object
5166/// for dynamic typing
5267pub trait Any {
68+ /// Get the `TypeId` of `self`
69+ fn get_type_id ( & self ) -> TypeId ;
70+
71+ /// Get a void pointer to `self`
72+ fn as_void_ptr ( & self ) -> * Void ;
73+
74+ /// Get a mutable void pointer to `self`
75+ fn as_mut_void_ptr ( & mut self ) -> * mut Void ;
76+ }
77+
78+ impl < T : ' static > Any for T {
5379 /// Get the `TypeId` of `self`
5480 fn get_type_id ( & self ) -> TypeId {
55- TypeId :: of :: < Self > ( )
81+ TypeId :: of :: < T > ( )
5682 }
5783
5884 /// Get a void pointer to `self`
5985 fn as_void_ptr ( & self ) -> * Void {
60- self as * Self as * Void
86+ self as * T as * Void
6187 }
6288
6389 /// Get a mutable void pointer to `self`
6490 fn as_mut_void_ptr ( & mut self ) -> * mut Void {
65- self as * mut Self as * mut Void
91+ self as * mut T as * mut Void
6692 }
6793}
68- impl < T > Any for T { }
6994
7095///////////////////////////////////////////////////////////////////////////////
7196// Extension methods for Any trait objects.
@@ -75,16 +100,16 @@ impl<T> Any for T {}
75100/// Extension methods for a referenced `Any` trait object
76101pub trait AnyRefExt < ' self > {
77102 /// Returns true if the boxed type is the same as `T`
78- fn is < T > ( self ) -> bool ;
103+ fn is < T : ' static > ( self ) -> bool ;
79104
80105 /// Returns some reference to the boxed value if it is of type `T`, or
81106 /// `None` if it isn't.
82- fn as_ref < T > ( self ) -> Option < & ' self T > ;
107+ fn as_ref < T : ' static > ( self ) -> Option < & ' self T > ;
83108}
84109
85110impl < ' self > AnyRefExt < ' self > for & ' self Any {
86111 #[ inline]
87- fn is < T > ( self ) -> bool {
112+ fn is < T : ' static > ( self ) -> bool {
88113 // Get TypeId of the type this function is instantiated with
89114 let t = TypeId :: of :: < T > ( ) ;
90115
@@ -96,7 +121,7 @@ impl<'self> AnyRefExt<'self> for &'self Any {
96121 }
97122
98123 #[ inline]
99- fn as_ref < T > ( self ) -> Option < & ' self T > {
124+ fn as_ref < T : ' static > ( self ) -> Option < & ' self T > {
100125 if self . is :: < T > ( ) {
101126 Some ( unsafe { transmute ( self . as_void_ptr ( ) ) } )
102127 } else {
@@ -109,12 +134,12 @@ impl<'self> AnyRefExt<'self> for &'self Any {
109134pub trait AnyMutRefExt < ' self > {
110135 /// Returns some mutable reference to the boxed value if it is of type `T`, or
111136 /// `None` if it isn't.
112- fn as_mut < T > ( self ) -> Option < & ' self mut T > ;
137+ fn as_mut < T : ' static > ( self ) -> Option < & ' self mut T > ;
113138}
114139
115140impl < ' self > AnyMutRefExt < ' self > for & ' self mut Any {
116141 #[ inline]
117- fn as_mut < T > ( self ) -> Option < & ' self mut T > {
142+ fn as_mut < T : ' static > ( self ) -> Option < & ' self mut T > {
118143 if self . is :: < T > ( ) {
119144 Some ( unsafe { transmute ( self . as_mut_void_ptr ( ) ) } )
120145 } else {
@@ -127,19 +152,19 @@ impl<'self> AnyMutRefExt<'self> for &'self mut Any {
127152pub trait AnyOwnExt {
128153 /// Returns the boxed value if it is of type `T`, or
129154 /// `None` if it isn't.
130- fn move < T > ( self ) -> Option < ~T > ;
155+ fn move < T : ' static > ( self ) -> Option < ~T > ;
131156}
132157
133158impl AnyOwnExt for ~Any {
134159 #[ inline]
135- fn move < T > ( self ) -> Option < ~T > {
160+ fn move < T : ' static > ( self ) -> Option < ~T > {
136161 if self . is :: < T > ( ) {
137162 unsafe {
138163 // Extract the pointer to the boxed value, temporary alias with self
139164 let ptr: ~T = transmute ( self . as_void_ptr ( ) ) ;
140165
141166 // Prevent destructor on self being run
142- forget ( self ) ;
167+ intrinsics :: forget ( self ) ;
143168
144169 Some ( ptr)
145170 }
0 commit comments