@@ -177,6 +177,25 @@ pub enum TypeInfo<'a> {
177
177
Structure ( & ' a StructureDef < ' a > ) ,
178
178
/// An untagged union
179
179
Union ( & ' a UnionDef < ' a > ) ,
180
+ /// A named, transparent, extern type
181
+ Extern {
182
+ /// The name of the type
183
+ ///
184
+ /// Since this is all we have, it's what used
185
+ /// to disambiguate between them.
186
+ name : & ' static str
187
+ } ,
188
+ /// A 'magic' type, with a user-defined meaning
189
+ ///
190
+ /// This allows extensions to the type system
191
+ Magic {
192
+ /// The id of the magic type,
193
+ /// giving more information about how its implemented
194
+ /// and what it actually means.
195
+ id : & ' static & ' static str ,
196
+ /// Extra information (if any)
197
+ extra : Option < & ' a TypeInfo < ' a > > ,
198
+ }
180
199
}
181
200
/*
182
201
* HACK: Implement AsmType as `NullTrace`
@@ -240,7 +259,9 @@ impl<'tp> TypeInfo<'tp> {
240
259
#[ cfg( feature = "builtins" ) ]
241
260
Str => size_of :: < AsmStr > ( ) ,
242
261
Structure ( ref def) => def. size ,
243
- Union ( ref def) => def. size
262
+ Union ( ref def) => def. size ,
263
+ // Provide a dummy value
264
+ TypeInfo :: Magic { .. } | TypeInfo :: Extern { .. } => 0xFFFF_FFFF
244
265
}
245
266
}
246
267
/// The alignment of the type, matching `std::mem::align_of`
@@ -250,6 +271,7 @@ impl<'tp> TypeInfo<'tp> {
250
271
TypeInfo :: Unit => align_of :: < ( ) > ( ) ,
251
272
#[ cfg( feature = "never" ) ]
252
273
TypeInfo :: Never => align_of :: < !> ( ) ,
274
+ TypeInfo :: Magic { .. } | TypeInfo :: Extern { .. } => 0 ,
253
275
TypeInfo :: Bool => align_of :: < bool > ( ) ,
254
276
TypeInfo :: Integer { size : IntSize :: Byte , signed : false } => align_of :: < u8 > ( ) ,
255
277
TypeInfo :: Integer { size : IntSize :: Short , signed : false } => align_of :: < u16 > ( ) ,
@@ -286,6 +308,9 @@ impl<'a> Display for TypeInfo<'a> {
286
308
TypeInfo :: Pointer => f. write_str ( "*mut void" ) ,
287
309
TypeInfo :: Structure ( ref def) => f. write_str ( def. name ) ,
288
310
TypeInfo :: Union ( ref def) => f. write_str ( def. name ) ,
311
+ TypeInfo :: Extern { name } => write ! ( f, "extern {}" , name) ,
312
+ TypeInfo :: Magic { id, extra : None } => write ! ( f, "magic::{}" , id) ,
313
+ TypeInfo :: Magic { id, extra : Some ( extra) } => write ! ( f, "magic::{}<{}>" , id, extra)
289
314
}
290
315
}
291
316
}
0 commit comments