@@ -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 ( ) ) . filter ( |n| !n. is_empty ( ) )
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 ( )
@@ -1096,10 +1101,10 @@ impl Type {
1096
1101
CXType_Enum => {
1097
1102
let enum_ = Enum :: from_ty ( ty, ctx) . expect ( "Not an enum?" ) ;
1098
1103
1099
- if name . is_empty ( ) {
1104
+ if !is_anonymous {
1100
1105
let pretty_name = ty. spelling ( ) ;
1101
1106
if clang:: is_valid_identifier ( & pretty_name) {
1102
- name = pretty_name;
1107
+ name = Some ( pretty_name) ;
1103
1108
}
1104
1109
}
1105
1110
@@ -1114,12 +1119,12 @@ impl Type {
1114
1119
)
1115
1120
. expect ( "Not a complex type?" ) ;
1116
1121
1117
- if name . is_empty ( ) {
1122
+ if !is_anonymous {
1118
1123
// The pretty-printed name may contain typedefed name,
1119
1124
// but may also be "struct (anonymous at .h:1)"
1120
1125
let pretty_name = ty. spelling ( ) ;
1121
1126
if clang:: is_valid_identifier ( & pretty_name) {
1122
- name = pretty_name;
1127
+ name = Some ( pretty_name) ;
1123
1128
}
1124
1129
}
1125
1130
@@ -1159,7 +1164,9 @@ impl Type {
1159
1164
CXType_ObjCClass | CXType_ObjCInterface => {
1160
1165
let interface = ObjCInterface :: from_ty ( & location, ctx)
1161
1166
. expect ( "Not a valid objc interface?" ) ;
1162
- name = interface. rust_name ( ) ;
1167
+ if !is_anonymous {
1168
+ name = Some ( interface. rust_name ( ) ) ;
1169
+ }
1163
1170
TypeKind :: ObjCInterface ( interface)
1164
1171
}
1165
1172
CXType_Dependent => {
@@ -1177,7 +1184,7 @@ impl Type {
1177
1184
}
1178
1185
} ;
1179
1186
1180
- let name = if name. is_empty ( ) { None } else { Some ( name ) } ;
1187
+ name = name. filter ( |n| !n . is_empty ( ) ) ;
1181
1188
1182
1189
let is_const = ty. is_const ( ) ||
1183
1190
( ty. kind ( ) == CXType_ConstantArray &&
0 commit comments