@@ -437,6 +437,26 @@ impl FunctionSig {
437
437
// variadic functions without an initial argument.
438
438
self . is_variadic && !self . argument_types . is_empty ( )
439
439
}
440
+
441
+ /// Are function pointers with this signature able to derive Rust traits?
442
+ /// Rust only supports deriving traits for function pointers with a limited
443
+ /// number of parameters and a couple ABIs.
444
+ ///
445
+ /// For more details, see:
446
+ ///
447
+ /// * https://github.com/rust-lang-nursery/rust-bindgen/issues/547,
448
+ /// * https://github.com/rust-lang/rust/issues/38848,
449
+ /// * and https://github.com/rust-lang/rust/issues/40158
450
+ pub fn function_pointers_can_derive ( & self ) -> bool {
451
+ if self . argument_types . len ( ) > RUST_DERIVE_FUNPTR_LIMIT {
452
+ return false ;
453
+ }
454
+
455
+ match self . abi {
456
+ Abi :: C | Abi :: Unknown ( ..) => true ,
457
+ _ => false ,
458
+ }
459
+ }
440
460
}
441
461
442
462
impl ClangSubItemParser for Function {
@@ -523,48 +543,20 @@ impl Trace for FunctionSig {
523
543
}
524
544
}
525
545
526
- // Function pointers follow special rules, see:
527
- //
528
- // https://github.com/rust-lang-nursery/rust-bindgen/issues/547,
529
- // https://github.com/rust-lang/rust/issues/38848,
530
- // and https://github.com/rust-lang/rust/issues/40158
531
- //
532
- // Note that copy is always derived, so we don't need to implement it.
533
546
impl CanTriviallyDeriveDebug for FunctionSig {
534
547
fn can_trivially_derive_debug ( & self ) -> bool {
535
- if self . argument_types . len ( ) > RUST_DERIVE_FUNPTR_LIMIT {
536
- return false ;
537
- }
538
-
539
- match self . abi {
540
- Abi :: C | Abi :: Unknown ( ..) => true ,
541
- _ => false ,
542
- }
548
+ self . function_pointers_can_derive ( )
543
549
}
544
550
}
545
551
546
552
impl CanTriviallyDeriveHash for FunctionSig {
547
553
fn can_trivially_derive_hash ( & self ) -> bool {
548
- if self . argument_types . len ( ) > RUST_DERIVE_FUNPTR_LIMIT {
549
- return false ;
550
- }
551
-
552
- match self . abi {
553
- Abi :: C | Abi :: Unknown ( ..) => true ,
554
- _ => false ,
555
- }
554
+ self . function_pointers_can_derive ( )
556
555
}
557
556
}
558
557
559
558
impl CanTriviallyDerivePartialEqOrPartialOrd for FunctionSig {
560
559
fn can_trivially_derive_partialeq_or_partialord ( & self ) -> bool {
561
- if self . argument_types . len ( ) > RUST_DERIVE_FUNPTR_LIMIT {
562
- return false ;
563
- }
564
-
565
- match self . abi {
566
- Abi :: C | Abi :: Unknown ( ..) => true ,
567
- _ => false ,
568
- }
560
+ self . function_pointers_can_derive ( )
569
561
}
570
562
}
0 commit comments