summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Fitzgerald <fitzgen@gmail.com>2017-09-19 14:12:41 -0700
committerNick Fitzgerald <fitzgen@gmail.com>2017-09-20 10:33:33 -0700
commit508d917ab6003bd3ecaba99ee32bd4720e77f8c8 (patch)
tree763f99031747f20434be2e8b97ac98890716fa9c
parentc65cb37eb623d24ea8a4d822f45b71da6a5ec27b (diff)
Common method for whether function pointers can trivially derive traits
Again, this logic was getting copied all over the place, and it is nice to have a single canonical definition.
-rw-r--r--src/ir/function.rs54
1 files changed, 23 insertions, 31 deletions
diff --git a/src/ir/function.rs b/src/ir/function.rs
index f37f0f3c..402a0230 100644
--- a/src/ir/function.rs
+++ b/src/ir/function.rs
@@ -437,6 +437,26 @@ impl FunctionSig {
// variadic functions without an initial argument.
self.is_variadic && !self.argument_types.is_empty()
}
+
+ /// Are function pointers with this signature able to derive Rust traits?
+ /// Rust only supports deriving traits for function pointers with a limited
+ /// number of parameters and a couple ABIs.
+ ///
+ /// For more details, see:
+ ///
+ /// * https://github.com/rust-lang-nursery/rust-bindgen/issues/547,
+ /// * https://github.com/rust-lang/rust/issues/38848,
+ /// * and https://github.com/rust-lang/rust/issues/40158
+ pub fn function_pointers_can_derive(&self) -> bool {
+ if self.argument_types.len() > RUST_DERIVE_FUNPTR_LIMIT {
+ return false;
+ }
+
+ match self.abi {
+ Abi::C | Abi::Unknown(..) => true,
+ _ => false,
+ }
+ }
}
impl ClangSubItemParser for Function {
@@ -523,48 +543,20 @@ impl Trace for FunctionSig {
}
}
-// Function pointers follow special rules, see:
-//
-// https://github.com/rust-lang-nursery/rust-bindgen/issues/547,
-// https://github.com/rust-lang/rust/issues/38848,
-// and https://github.com/rust-lang/rust/issues/40158
-//
-// Note that copy is always derived, so we don't need to implement it.
impl CanTriviallyDeriveDebug for FunctionSig {
fn can_trivially_derive_debug(&self) -> bool {
- if self.argument_types.len() > RUST_DERIVE_FUNPTR_LIMIT {
- return false;
- }
-
- match self.abi {
- Abi::C | Abi::Unknown(..) => true,
- _ => false,
- }
+ self.function_pointers_can_derive()
}
}
impl CanTriviallyDeriveHash for FunctionSig {
fn can_trivially_derive_hash(&self) -> bool {
- if self.argument_types.len() > RUST_DERIVE_FUNPTR_LIMIT {
- return false;
- }
-
- match self.abi {
- Abi::C | Abi::Unknown(..) => true,
- _ => false,
- }
+ self.function_pointers_can_derive()
}
}
impl CanTriviallyDerivePartialEqOrPartialOrd for FunctionSig {
fn can_trivially_derive_partialeq_or_partialord(&self) -> bool {
- if self.argument_types.len() > RUST_DERIVE_FUNPTR_LIMIT {
- return false;
- }
-
- match self.abi {
- Abi::C | Abi::Unknown(..) => true,
- _ => false,
- }
+ self.function_pointers_can_derive()
}
}