@@ -122,13 +122,10 @@ impl Type {
122
122
}
123
123
124
124
/// Is this an integer type?
125
- pub fn is_integer ( & self , ctx : & BindgenContext ) -> bool {
125
+ pub fn is_integer ( & self ) -> bool {
126
126
match self . kind {
127
- TypeKind :: UnresolvedTypeRef ( ..) => false ,
128
- _ => match self . canonical_type ( ctx) . kind {
129
- TypeKind :: Int ( ..) => true ,
130
- _ => false ,
131
- }
127
+ TypeKind :: Int ( ..) => true ,
128
+ _ => false ,
132
129
}
133
130
}
134
131
@@ -311,12 +308,17 @@ impl Type {
311
308
}
312
309
}
313
310
311
+ /// See safe_canonical_type.
312
+ pub fn canonical_type < ' tr > ( & ' tr self , ctx : & ' tr BindgenContext ) -> & ' tr Type {
313
+ self . safe_canonical_type ( ctx) . expect ( "Should have been resolved after parsing!" )
314
+ }
315
+
314
316
/// Returns the canonical type of this type, that is, the "inner type".
315
317
///
316
318
/// For example, for a `typedef`, the canonical type would be the
317
319
/// `typedef`ed type, for a template specialization, would be the template
318
- /// its specializing, and so on.
319
- pub fn canonical_type < ' tr > ( & ' tr self , ctx : & ' tr BindgenContext ) -> & ' tr Type {
320
+ /// its specializing, and so on. Return None if the type is unresolved.
321
+ pub fn safe_canonical_type < ' tr > ( & ' tr self , ctx : & ' tr BindgenContext ) -> Option < & ' tr Type > {
320
322
match self . kind {
321
323
TypeKind :: Named ( ..) |
322
324
TypeKind :: Array ( ..) |
@@ -329,16 +331,15 @@ impl Type {
329
331
TypeKind :: Void |
330
332
TypeKind :: NullPtr |
331
333
TypeKind :: BlockPointer |
332
- TypeKind :: Pointer ( ..) => self ,
334
+ TypeKind :: Pointer ( ..) => Some ( self ) ,
333
335
334
336
TypeKind :: ResolvedTypeRef ( inner) |
335
337
TypeKind :: Alias ( _, inner) |
336
338
TypeKind :: TemplateAlias ( inner, _) |
337
339
TypeKind :: TemplateRef ( inner, _)
338
- => ctx. resolve_type ( inner) . canonical_type ( ctx) ,
340
+ => ctx. resolve_type ( inner) . safe_canonical_type ( ctx) ,
339
341
340
- TypeKind :: UnresolvedTypeRef ( ..)
341
- => unreachable ! ( "Should have been resolved after parsing!" ) ,
342
+ TypeKind :: UnresolvedTypeRef ( ..) => None ,
342
343
}
343
344
}
344
345
}
0 commit comments