@@ -65,22 +65,6 @@ impl Type {
65
65
& self . kind
66
66
}
67
67
68
- /// Overrides the kind of the item. This is mostly a template alias
69
- /// implementation detail, and debug assertions guard it like so.
70
- pub fn set_kind ( & mut self , kind : TypeKind ) {
71
- if cfg ! ( debug_assertions) {
72
- match ( & self . kind , & kind) {
73
- ( & TypeKind :: Alias ( ref alias_name, alias_inner) ,
74
- & TypeKind :: TemplateAlias ( ref name, inner, _) ) => {
75
- assert_eq ! ( alias_name, name) ;
76
- assert_eq ! ( alias_inner, inner) ;
77
- }
78
- _ => panic ! ( "Unexpected kind in `set_kind`!" ) ,
79
- } ;
80
- }
81
- self . kind = kind;
82
- }
83
-
84
68
/// Get a mutable reference to this type's kind.
85
69
pub fn kind_mut ( & mut self ) -> & mut TypeKind {
86
70
& mut self . kind
@@ -102,7 +86,7 @@ impl Type {
102
86
/// Is this a named type?
103
87
pub fn is_named ( & self ) -> bool {
104
88
match self . kind {
105
- TypeKind :: Named ( .. ) => true ,
89
+ TypeKind :: Named => true ,
106
90
_ => false ,
107
91
}
108
92
}
@@ -143,17 +127,15 @@ impl Type {
143
127
TypeKind :: BlockPointer |
144
128
TypeKind :: Int ( ..) |
145
129
TypeKind :: Float ( ..) |
146
- TypeKind :: Named ( .. ) => true ,
130
+ TypeKind :: Named => true ,
147
131
_ => false ,
148
132
}
149
133
}
150
134
151
135
/// Creates a new named type, with name `name`.
152
136
pub fn named ( name : String ) -> Self {
153
137
assert ! ( !name. is_empty( ) ) ;
154
- // TODO: stop duplicating the name, it's stupid.
155
- let kind = TypeKind :: Named ( name. clone ( ) ) ;
156
- Self :: new ( Some ( name) , None , kind, false )
138
+ Self :: new ( Some ( name) , None , TypeKind :: Named , false )
157
139
}
158
140
159
141
/// Is this a floating point type?
@@ -230,8 +212,8 @@ impl Type {
230
212
// FIXME: Can we do something about template parameters? Huh...
231
213
match self . kind {
232
214
TypeKind :: TemplateRef ( t, _) |
233
- TypeKind :: TemplateAlias ( _ , t, _) |
234
- TypeKind :: Alias ( _ , t) |
215
+ TypeKind :: TemplateAlias ( t, _) |
216
+ TypeKind :: Alias ( t) |
235
217
TypeKind :: ResolvedTypeRef ( t) => ctx. resolve_type ( t) . has_vtable ( ctx) ,
236
218
TypeKind :: Comp ( ref info) => info. has_vtable ( ctx) ,
237
219
_ => false ,
@@ -243,8 +225,8 @@ impl Type {
243
225
pub fn has_destructor ( & self , ctx : & BindgenContext ) -> bool {
244
226
match self . kind {
245
227
TypeKind :: TemplateRef ( t, _) |
246
- TypeKind :: TemplateAlias ( _ , t, _) |
247
- TypeKind :: Alias ( _ , t) |
228
+ TypeKind :: TemplateAlias ( t, _) |
229
+ TypeKind :: Alias ( t) |
248
230
TypeKind :: ResolvedTypeRef ( t) => {
249
231
ctx. resolve_type ( t) . has_destructor ( ctx)
250
232
}
@@ -259,16 +241,16 @@ impl Type {
259
241
ty : & Type )
260
242
-> bool {
261
243
let name = match * ty. kind ( ) {
262
- TypeKind :: Named ( ref name ) => name,
244
+ TypeKind :: Named => ty . name ( ) ,
263
245
ref other @ _ => unreachable ! ( "Not a named type: {:?}" , other) ,
264
246
} ;
265
247
266
248
match self . kind {
267
- TypeKind :: Named ( ref this_name ) => this_name == name,
249
+ TypeKind :: Named => self . name ( ) == name,
268
250
TypeKind :: ResolvedTypeRef ( t) |
269
251
TypeKind :: Array ( t, _) |
270
252
TypeKind :: Pointer ( t) |
271
- TypeKind :: Alias ( _ , t) => {
253
+ TypeKind :: Alias ( t) => {
272
254
ctx. resolve_type ( t)
273
255
. signature_contains_named_type ( ctx, ty)
274
256
}
@@ -280,7 +262,7 @@ impl Type {
280
262
ctx. resolve_type ( sig. return_type ( ) )
281
263
. signature_contains_named_type ( ctx, ty)
282
264
}
283
- TypeKind :: TemplateAlias ( _, _ , ref template_args) |
265
+ TypeKind :: TemplateAlias ( _, ref template_args) |
284
266
TypeKind :: TemplateRef ( _, ref template_args) => {
285
267
template_args. iter ( ) . any ( |arg| {
286
268
ctx. resolve_type ( * arg)
@@ -298,8 +280,8 @@ impl Type {
298
280
/// tests/headers/381-decltype-alias.hpp
299
281
pub fn is_invalid_named_type ( & self ) -> bool {
300
282
match self . kind {
301
- TypeKind :: Named ( ref name ) => {
302
- assert ! ( ! name. is_empty ( ) ) ;
283
+ TypeKind :: Named => {
284
+ let name = self . name ( ) . expect ( "Unnamed named type?" ) ;
303
285
let mut chars = name. chars ( ) ;
304
286
let first = chars. next ( ) . unwrap ( ) ;
305
287
let mut remaining = chars;
@@ -330,7 +312,7 @@ impl Type {
330
312
ctx : & ' tr BindgenContext )
331
313
-> Option < & ' tr Type > {
332
314
match self . kind {
333
- TypeKind :: Named ( .. ) |
315
+ TypeKind :: Named |
334
316
TypeKind :: Array ( ..) |
335
317
TypeKind :: Comp ( ..) |
336
318
TypeKind :: Int ( ..) |
@@ -345,8 +327,8 @@ impl Type {
345
327
TypeKind :: Pointer ( ..) => Some ( self ) ,
346
328
347
329
TypeKind :: ResolvedTypeRef ( inner) |
348
- TypeKind :: Alias ( _ , inner) |
349
- TypeKind :: TemplateAlias ( _ , inner, _) |
330
+ TypeKind :: Alias ( inner) |
331
+ TypeKind :: TemplateAlias ( inner, _) |
350
332
TypeKind :: TemplateRef ( inner, _) => {
351
333
ctx. resolve_type ( inner) . safe_canonical_type ( ctx)
352
334
}
@@ -379,8 +361,8 @@ impl CanDeriveDebug for Type {
379
361
len <= RUST_DERIVE_IN_ARRAY_LIMIT && t. can_derive_debug ( ctx, ( ) )
380
362
}
381
363
TypeKind :: ResolvedTypeRef ( t) |
382
- TypeKind :: TemplateAlias ( _ , t, _) |
383
- TypeKind :: Alias ( _ , t) => t. can_derive_debug ( ctx, ( ) ) ,
364
+ TypeKind :: TemplateAlias ( t, _) |
365
+ TypeKind :: Alias ( t) => t. can_derive_debug ( ctx, ( ) ) ,
384
366
TypeKind :: Comp ( ref info) => {
385
367
info. can_derive_debug ( ctx, self . layout ( ctx) )
386
368
}
@@ -399,9 +381,9 @@ impl<'a> CanDeriveCopy<'a> for Type {
399
381
t. can_derive_copy_in_array ( ctx, ( ) )
400
382
}
401
383
TypeKind :: ResolvedTypeRef ( t) |
402
- TypeKind :: TemplateAlias ( _ , t, _) |
384
+ TypeKind :: TemplateAlias ( t, _) |
403
385
TypeKind :: TemplateRef ( t, _) |
404
- TypeKind :: Alias ( _ , t) => t. can_derive_copy ( ctx, ( ) ) ,
386
+ TypeKind :: Alias ( t) => t. can_derive_copy ( ctx, ( ) ) ,
405
387
TypeKind :: Comp ( ref info) => {
406
388
info. can_derive_copy ( ctx, ( item, self . layout ( ctx) ) )
407
389
}
@@ -415,10 +397,10 @@ impl<'a> CanDeriveCopy<'a> for Type {
415
397
-> bool {
416
398
match self . kind {
417
399
TypeKind :: ResolvedTypeRef ( t) |
418
- TypeKind :: TemplateAlias ( _ , t, _) |
419
- TypeKind :: Alias ( _ , t) |
400
+ TypeKind :: TemplateAlias ( t, _) |
401
+ TypeKind :: Alias ( t) |
420
402
TypeKind :: Array ( t, _) => t. can_derive_copy_in_array ( ctx, ( ) ) ,
421
- TypeKind :: Named ( .. ) => false ,
403
+ TypeKind :: Named => false ,
422
404
_ => self . can_derive_copy ( ctx, item) ,
423
405
}
424
406
}
@@ -460,11 +442,11 @@ pub enum TypeKind {
460
442
Complex ( FloatKind ) ,
461
443
462
444
/// A type alias, with a name, that points to another type.
463
- Alias ( String , ItemId ) ,
445
+ Alias ( ItemId ) ,
464
446
465
447
/// A templated alias, pointing to an inner type, just as `Alias`, but with
466
448
/// template parameters.
467
- TemplateAlias ( String , ItemId , Vec < ItemId > ) ,
449
+ TemplateAlias ( ItemId , Vec < ItemId > ) ,
468
450
469
451
/// An array of a type and a lenght.
470
452
Array ( ItemId , usize ) ,
@@ -509,7 +491,7 @@ pub enum TypeKind {
509
491
ResolvedTypeRef ( ItemId ) ,
510
492
511
493
/// A named type, that is, a template parameter.
512
- Named ( String ) ,
494
+ Named ,
513
495
}
514
496
515
497
impl Type {
@@ -527,12 +509,12 @@ impl Type {
527
509
size == 0 || ctx. resolve_type ( inner) . is_unsized ( ctx)
528
510
}
529
511
TypeKind :: ResolvedTypeRef ( inner) |
530
- TypeKind :: Alias ( _ , inner) |
531
- TypeKind :: TemplateAlias ( _ , inner, _) |
512
+ TypeKind :: Alias ( inner) |
513
+ TypeKind :: TemplateAlias ( inner, _) |
532
514
TypeKind :: TemplateRef ( inner, _) => {
533
515
ctx. resolve_type ( inner) . is_unsized ( ctx)
534
516
}
535
- TypeKind :: Named ( .. ) |
517
+ TypeKind :: Named |
536
518
TypeKind :: Int ( ..) |
537
519
TypeKind :: Float ( ..) |
538
520
TypeKind :: Complex ( ..) |
@@ -725,8 +707,7 @@ impl Type {
725
707
}
726
708
} ;
727
709
728
- TypeKind :: TemplateAlias ( name. clone ( ) ,
729
- inner_type,
710
+ TypeKind :: TemplateAlias ( inner_type,
730
711
args)
731
712
}
732
713
CXCursor_TemplateRef => {
@@ -873,7 +854,7 @@ impl Type {
873
854
let inner = cursor. typedef_type ( ) . expect ( "Not valid Type?" ) ;
874
855
let inner =
875
856
Item :: from_ty_or_ref ( inner, location, parent_id, ctx) ;
876
- TypeKind :: Alias ( ty . spelling ( ) , inner)
857
+ TypeKind :: Alias ( inner)
877
858
}
878
859
CXType_Enum => {
879
860
let enum_ = Enum :: from_ty ( ty, ctx) . expect ( "Not an enum?" ) ;
@@ -935,12 +916,12 @@ impl TypeCollector for Type {
935
916
TypeKind :: Pointer ( inner) |
936
917
TypeKind :: Reference ( inner) |
937
918
TypeKind :: Array ( inner, _) |
938
- TypeKind :: Alias ( _ , inner) |
919
+ TypeKind :: Alias ( inner) |
939
920
TypeKind :: ResolvedTypeRef ( inner) => {
940
921
types. insert ( inner) ;
941
922
}
942
923
943
- TypeKind :: TemplateAlias ( _ , inner, ref template_args) |
924
+ TypeKind :: TemplateAlias ( inner, ref template_args) |
944
925
TypeKind :: TemplateRef ( inner, ref template_args) => {
945
926
types. insert ( inner) ;
946
927
for & item in template_args {
@@ -962,7 +943,7 @@ impl TypeCollector for Type {
962
943
963
944
// None of these variants have edges to other items and types.
964
945
TypeKind :: UnresolvedTypeRef ( _, _, None ) |
965
- TypeKind :: Named ( _ ) |
946
+ TypeKind :: Named |
966
947
TypeKind :: Void |
967
948
TypeKind :: NullPtr |
968
949
TypeKind :: Int ( _) |
0 commit comments