@@ -605,6 +605,13 @@ impl CanDeriveDebug for Type {
605
605
TypeKind :: Comp ( ref info) => {
606
606
info. can_derive_debug ( ctx, self . layout ( ctx) )
607
607
}
608
+ TypeKind :: Pointer ( inner) => {
609
+ let inner = ctx. resolve_type ( inner) ;
610
+ if let TypeKind :: Function ( ref sig) = * inner. canonical_type ( ctx) . kind ( ) {
611
+ return sig. can_derive_debug ( ctx, ( ) ) ;
612
+ }
613
+ return true ;
614
+ }
608
615
_ => true ,
609
616
}
610
617
}
@@ -636,6 +643,7 @@ impl CanDeriveDefault for Type {
636
643
TypeKind :: ObjCSel |
637
644
TypeKind :: ObjCInterface ( ..) |
638
645
TypeKind :: Enum ( ..) => false ,
646
+
639
647
TypeKind :: Function ( ..) |
640
648
TypeKind :: Int ( ..) |
641
649
TypeKind :: Float ( ..) |
@@ -877,6 +885,7 @@ impl Type {
877
885
let kind = match ty_kind {
878
886
CXType_Unexposed if * ty != canonical_ty &&
879
887
canonical_ty. kind ( ) != CXType_Invalid &&
888
+ ty. ret_type ( ) . is_none ( ) &&
880
889
// Sometime clang desugars some types more than
881
890
// what we need, specially with function
882
891
// pointers.
@@ -1132,7 +1141,32 @@ impl Type {
1132
1141
CXType_ObjCObjectPointer |
1133
1142
CXType_MemberPointer |
1134
1143
CXType_Pointer => {
1135
- let inner = Item :: from_ty_or_ref ( ty. pointee_type ( ) . unwrap ( ) ,
1144
+ // Fun fact: the canonical type of a pointer type may sometimes
1145
+ // contain information we need but isn't present in the concrete
1146
+ // type (yeah, I'm equally wat'd).
1147
+ //
1148
+ // Yet we still have trouble if we unconditionally trust the
1149
+ // canonical type, like too-much desugaring (sigh).
1150
+ //
1151
+ // See tests/headers/call-conv-field.h for an example.
1152
+ //
1153
+ // Since for now the only identifier cause of breakage is the
1154
+ // ABI for function pointers, and different ABI mixed with
1155
+ // problematic stuff like that one is _extremely_ unlikely and
1156
+ // can be bypassed via blacklisting, we do the check explicitly
1157
+ // (as hacky as it is).
1158
+ //
1159
+ // Yet we should probably (somehow) get the best of both worlds,
1160
+ // presumably special-casing function pointers as a whole, yet
1161
+ // someone is going to need to care about typedef'd function
1162
+ // pointers, etc, which isn't trivial given function pointers
1163
+ // are mostly unexposed. I don't have the time for it right now.
1164
+ let mut pointee = ty. pointee_type ( ) . unwrap ( ) ;
1165
+ let canonical_pointee = canonical_ty. pointee_type ( ) . unwrap ( ) ;
1166
+ if pointee. call_conv ( ) != canonical_pointee. call_conv ( ) {
1167
+ pointee = canonical_pointee;
1168
+ }
1169
+ let inner = Item :: from_ty_or_ref ( pointee,
1136
1170
location,
1137
1171
None ,
1138
1172
ctx) ;
0 commit comments