@@ -698,7 +698,12 @@ impl Type {
698
698
699
699
let layout = ty. fallible_layout ( ctx) . ok ( ) ;
700
700
let cursor = ty. declaration ( ) ;
701
- let mut name = cursor. spelling ( ) ;
701
+ let is_anonymous = cursor. is_anonymous ( ) ;
702
+ let mut name = if is_anonymous {
703
+ None
704
+ } else {
705
+ Some ( cursor. spelling ( ) )
706
+ } ;
702
707
703
708
debug ! (
704
709
"from_clang_ty: {:?}, ty: {:?}, loc: {:?}" ,
@@ -732,7 +737,7 @@ impl Type {
732
737
if is_canonical_objcpointer && is_template_type_param {
733
738
// Objective-C generics are just ids with fancy name.
734
739
// To keep it simple, just name them ids
735
- name = "id" . to_owned ( ) ;
740
+ name = Some ( "id" . to_owned ( ) ) ;
736
741
}
737
742
}
738
743
@@ -861,7 +866,7 @@ impl Type {
861
866
return Err ( ParseError :: Recurse ) ;
862
867
}
863
868
} else {
864
- name = location. spelling ( ) ;
869
+ name = Some ( location. spelling ( ) ) ;
865
870
}
866
871
867
872
let complex = CompInfo :: from_ty (
@@ -903,7 +908,7 @@ impl Type {
903
908
CXType_Typedef
904
909
) ;
905
910
906
- name = current . spelling ( ) ;
911
+ name = Some ( location . spelling ( ) ) ;
907
912
908
913
let inner_ty = cur
909
914
. typedef_type ( )
@@ -1105,10 +1110,10 @@ impl Type {
1105
1110
CXType_Enum => {
1106
1111
let enum_ = Enum :: from_ty ( ty, ctx) . expect ( "Not an enum?" ) ;
1107
1112
1108
- if name . is_empty ( ) {
1113
+ if !is_anonymous {
1109
1114
let pretty_name = ty. spelling ( ) ;
1110
1115
if clang:: is_valid_identifier ( & pretty_name) {
1111
- name = pretty_name;
1116
+ name = Some ( pretty_name) ;
1112
1117
}
1113
1118
}
1114
1119
@@ -1123,12 +1128,12 @@ impl Type {
1123
1128
)
1124
1129
. expect ( "Not a complex type?" ) ;
1125
1130
1126
- if name . is_empty ( ) {
1131
+ if !is_anonymous {
1127
1132
// The pretty-printed name may contain typedefed name,
1128
1133
// but may also be "struct (anonymous at .h:1)"
1129
1134
let pretty_name = ty. spelling ( ) ;
1130
1135
if clang:: is_valid_identifier ( & pretty_name) {
1131
- name = pretty_name;
1136
+ name = Some ( pretty_name) ;
1132
1137
}
1133
1138
}
1134
1139
@@ -1168,7 +1173,9 @@ impl Type {
1168
1173
CXType_ObjCClass | CXType_ObjCInterface => {
1169
1174
let interface = ObjCInterface :: from_ty ( & location, ctx)
1170
1175
. expect ( "Not a valid objc interface?" ) ;
1171
- name = interface. rust_name ( ) ;
1176
+ if !is_anonymous {
1177
+ name = Some ( interface. rust_name ( ) ) ;
1178
+ }
1172
1179
TypeKind :: ObjCInterface ( interface)
1173
1180
}
1174
1181
CXType_Dependent => {
@@ -1186,7 +1193,7 @@ impl Type {
1186
1193
}
1187
1194
} ;
1188
1195
1189
- let name = if name. is_empty ( ) { None } else { Some ( name ) } ;
1196
+ name = name. filter ( |n| !n . is_empty ( ) ) ;
1190
1197
1191
1198
let is_const = ty. is_const ( ) ||
1192
1199
( ty. kind ( ) == CXType_ConstantArray &&
0 commit comments