diff --git a/src/codegen/impl_partialeq.rs b/src/codegen/impl_partialeq.rs index 02783808..31c2c979 100644 --- a/src/codegen/impl_partialeq.rs +++ b/src/codegen/impl_partialeq.rs @@ -20,7 +20,7 @@ pub fn gen_partialeq_impl( &self._bindgen_opaque_blob[..] == &other._bindgen_opaque_blob[..] }); } else if comp_info.kind() == CompKind::Union { - assert!(!ctx.options().rust_features().untagged_union()); + assert!(!ctx.options().rust_features().untagged_union); tokens.push(quote! { &self.bindgen_union_field[..] == &other.bindgen_union_field[..] }); diff --git a/src/codegen/mod.rs b/src/codegen/mod.rs index 950708a0..a6ab3997 100644 --- a/src/codegen/mod.rs +++ b/src/codegen/mod.rs @@ -1641,7 +1641,7 @@ impl CodeGenerator for CompInfo { attributes.push(attributes::repr("C")); } - if ctx.options().rust_features().repr_align() { + if ctx.options().rust_features().repr_align { if let Some(explicit) = explicit_align { // Ensure that the struct has the correct alignment even in // presence of alignas. @@ -1671,7 +1671,7 @@ impl CodeGenerator for CompInfo { if item.can_derive_copy(ctx) && !item.annotations().disallow_copy() { derives.push("Copy"); - if ctx.options().rust_features().builtin_clone_impls() || + if ctx.options().rust_features().builtin_clone_impls || used_template_params.is_some() { // FIXME: This requires extra logic if you have a big array in a @@ -2012,7 +2012,7 @@ impl MethodCodegen for Method { _ => panic!("How in the world?"), }; - if let (Abi::ThisCall, false) = (signature.abi(), ctx.options().rust_features().thiscall_abi()) { + if let (Abi::ThisCall, false) = (signature.abi(), ctx.options().rust_features().thiscall_abi) { return; } @@ -3183,7 +3183,7 @@ impl TryToRustTy for FunctionSig { let abi = self.abi(); match abi { - Abi::ThisCall if !ctx.options().rust_features().thiscall_abi() => { + Abi::ThisCall if !ctx.options().rust_features().thiscall_abi => { warn!("Skipping function with thiscall ABI that isn't supported by the configured Rust target"); Ok(quote::Tokens::new()) } @@ -3280,7 +3280,7 @@ impl CodeGenerator for Function { } let abi = match signature.abi() { - Abi::ThisCall if !ctx.options().rust_features().thiscall_abi() => { + Abi::ThisCall if !ctx.options().rust_features().thiscall_abi => { warn!("Skipping function with thiscall ABI that isn't supported by the configured Rust target"); return; } diff --git a/src/features.rs b/src/features.rs index fe4f8453..1b490f54 100644 --- a/src/features.rs +++ b/src/features.rs @@ -113,7 +113,10 @@ macro_rules! rust_feature_def { #[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)] pub struct RustFeatures { $( - $feature: bool, + $( + #[$attr] + )* + pub $feature: bool, )* } @@ -126,15 +129,6 @@ macro_rules! rust_feature_def { )* } } - - $( - $( - #[$attr] - )* - pub fn $feature(&self) -> bool { - self.$feature - } - )* } } } diff --git a/src/ir/analysis/derive_copy.rs b/src/ir/analysis/derive_copy.rs index 94d457d5..69725ead 100644 --- a/src/ir/analysis/derive_copy.rs +++ b/src/ir/analysis/derive_copy.rs @@ -234,7 +234,7 @@ impl<'ctx> MonotoneFramework for CannotDeriveCopy<'ctx> { } if info.kind() == CompKind::Union { - if !self.ctx.options().rust_features().untagged_union() { + if !self.ctx.options().rust_features().untagged_union { // NOTE: If there's no template parameters we can derive // copy unconditionally, since arrays are magical for // rustc, and __BindgenUnionField always implements diff --git a/src/ir/analysis/derive_debug.rs b/src/ir/analysis/derive_debug.rs index a1743ae9..b191d37d 100644 --- a/src/ir/analysis/derive_debug.rs +++ b/src/ir/analysis/derive_debug.rs @@ -150,7 +150,7 @@ impl<'ctx> MonotoneFramework for CannotDeriveDebug<'ctx> { }); return if layout_can_derive && !(ty.is_union() && - self.ctx.options().rust_features().untagged_union()) { + self.ctx.options().rust_features().untagged_union) { trace!(" we can trivially derive Debug for the layout"); ConstrainResult::Same } else { @@ -235,7 +235,7 @@ impl<'ctx> MonotoneFramework for CannotDeriveDebug<'ctx> { ); if info.kind() == CompKind::Union { - if self.ctx.options().rust_features().untagged_union() { + if self.ctx.options().rust_features().untagged_union { trace!(" cannot derive Debug for Rust unions"); return self.insert(id); } diff --git a/src/ir/analysis/derive_default.rs b/src/ir/analysis/derive_default.rs index 2c79a437..e319166d 100644 --- a/src/ir/analysis/derive_default.rs +++ b/src/ir/analysis/derive_default.rs @@ -177,7 +177,7 @@ impl<'ctx> MonotoneFramework for CannotDeriveDefault<'ctx> { }); return if layout_can_derive && !(ty.is_union() && - self.ctx.options().rust_features().untagged_union()) { + self.ctx.options().rust_features().untagged_union) { trace!(" we can trivially derive Default for the layout"); ConstrainResult::Same } else { @@ -271,7 +271,7 @@ impl<'ctx> MonotoneFramework for CannotDeriveDefault<'ctx> { } if info.kind() == CompKind::Union { - if self.ctx.options().rust_features().untagged_union() { + if self.ctx.options().rust_features().untagged_union { trace!(" cannot derive Default for Rust unions"); return self.insert(id); } diff --git a/src/ir/analysis/derive_hash.rs b/src/ir/analysis/derive_hash.rs index 3fc31b39..c23a891e 100644 --- a/src/ir/analysis/derive_hash.rs +++ b/src/ir/analysis/derive_hash.rs @@ -137,7 +137,7 @@ impl<'ctx> MonotoneFramework for CannotDeriveHash<'ctx> { }); return if layout_can_derive && !(ty.is_union() && - self.ctx.options().rust_features().untagged_union()) { + self.ctx.options().rust_features().untagged_union) { trace!(" we can trivially derive Hash for the layout"); ConstrainResult::Same } else { @@ -257,7 +257,7 @@ impl<'ctx> MonotoneFramework for CannotDeriveHash<'ctx> { } if info.kind() == CompKind::Union { - if self.ctx.options().rust_features().untagged_union() { + if self.ctx.options().rust_features().untagged_union { trace!(" cannot derive Hash for Rust unions"); return self.insert(id); } diff --git a/src/ir/analysis/derive_partialeq_or_partialord.rs b/src/ir/analysis/derive_partialeq_or_partialord.rs index 2641d2b3..cebdceef 100644 --- a/src/ir/analysis/derive_partialeq_or_partialord.rs +++ b/src/ir/analysis/derive_partialeq_or_partialord.rs @@ -119,7 +119,7 @@ impl<'ctx> CannotDerivePartialEqOrPartialOrd<'ctx> { trace!("ty: {:?}", ty); if item.is_opaque(self.ctx, &()) { if ty.is_union() - && self.ctx.options().rust_features().untagged_union() + && self.ctx.options().rust_features().untagged_union { trace!( " cannot derive `PartialEq`/`PartialOrd` for Rust unions" @@ -242,7 +242,7 @@ impl<'ctx> CannotDerivePartialEqOrPartialOrd<'ctx> { } if info.kind() == CompKind::Union { - if self.ctx.options().rust_features().untagged_union() { + if self.ctx.options().rust_features().untagged_union { trace!( " cannot derive `PartialEq`/`PartialOrd` for Rust unions" ); diff --git a/src/ir/comp.rs b/src/ir/comp.rs index 24909cb5..131851fd 100644 --- a/src/ir/comp.rs +++ b/src/ir/comp.rs @@ -1543,7 +1543,7 @@ impl CompInfo { /// 1. Current RustTarget allows for `untagged_union` /// 2. Each field can derive `Copy` pub fn can_be_rust_union(&self, ctx: &BindgenContext) -> bool { - if !ctx.options().rust_features().untagged_union() { + if !ctx.options().rust_features().untagged_union { return false; } diff --git a/src/lib.rs b/src/lib.rs index db58f6f4..6346ff80 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -600,6 +600,12 @@ impl Builder { self } + /// Disable support for native Rust unions, if supported. + pub fn disable_untagged_union(mut self) -> Self { + self.options.rust_features.untagged_union = false; + self + } + /// Set the output graphviz file. pub fn emit_ir_graphviz>(mut self, path: T) -> Builder { let path = path.into();