Skip to content

Commit a6f2d51

Browse files
committed
Add a kill-switch for untagged unions.
Otherwise we can't use repr(align) on stylo.
1 parent d6b69bf commit a6f2d51

File tree

10 files changed

+26
-26
lines changed

10 files changed

+26
-26
lines changed

src/codegen/impl_partialeq.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ pub fn gen_partialeq_impl(
2020
&self._bindgen_opaque_blob[..] == &other._bindgen_opaque_blob[..]
2121
});
2222
} else if comp_info.kind() == CompKind::Union {
23-
assert!(!ctx.options().rust_features().untagged_union());
23+
assert!(!ctx.options().rust_features().untagged_union);
2424
tokens.push(quote! {
2525
&self.bindgen_union_field[..] == &other.bindgen_union_field[..]
2626
});

src/codegen/mod.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1641,7 +1641,7 @@ impl CodeGenerator for CompInfo {
16411641
attributes.push(attributes::repr("C"));
16421642
}
16431643

1644-
if ctx.options().rust_features().repr_align() {
1644+
if ctx.options().rust_features().repr_align {
16451645
if let Some(explicit) = explicit_align {
16461646
// Ensure that the struct has the correct alignment even in
16471647
// presence of alignas.
@@ -1671,7 +1671,7 @@ impl CodeGenerator for CompInfo {
16711671
if item.can_derive_copy(ctx) && !item.annotations().disallow_copy() {
16721672
derives.push("Copy");
16731673

1674-
if ctx.options().rust_features().builtin_clone_impls() ||
1674+
if ctx.options().rust_features().builtin_clone_impls ||
16751675
used_template_params.is_some()
16761676
{
16771677
// FIXME: This requires extra logic if you have a big array in a
@@ -2012,7 +2012,7 @@ impl MethodCodegen for Method {
20122012
_ => panic!("How in the world?"),
20132013
};
20142014

2015-
if let (Abi::ThisCall, false) = (signature.abi(), ctx.options().rust_features().thiscall_abi()) {
2015+
if let (Abi::ThisCall, false) = (signature.abi(), ctx.options().rust_features().thiscall_abi) {
20162016
return;
20172017
}
20182018

@@ -3183,7 +3183,7 @@ impl TryToRustTy for FunctionSig {
31833183
let abi = self.abi();
31843184

31853185
match abi {
3186-
Abi::ThisCall if !ctx.options().rust_features().thiscall_abi() => {
3186+
Abi::ThisCall if !ctx.options().rust_features().thiscall_abi => {
31873187
warn!("Skipping function with thiscall ABI that isn't supported by the configured Rust target");
31883188
Ok(quote::Tokens::new())
31893189
}
@@ -3280,7 +3280,7 @@ impl CodeGenerator for Function {
32803280
}
32813281

32823282
let abi = match signature.abi() {
3283-
Abi::ThisCall if !ctx.options().rust_features().thiscall_abi() => {
3283+
Abi::ThisCall if !ctx.options().rust_features().thiscall_abi => {
32843284
warn!("Skipping function with thiscall ABI that isn't supported by the configured Rust target");
32853285
return;
32863286
}

src/features.rs

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,10 @@ macro_rules! rust_feature_def {
113113
#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
114114
pub struct RustFeatures {
115115
$(
116-
$feature: bool,
116+
$(
117+
#[$attr]
118+
)*
119+
pub $feature: bool,
117120
)*
118121
}
119122

@@ -126,15 +129,6 @@ macro_rules! rust_feature_def {
126129
)*
127130
}
128131
}
129-
130-
$(
131-
$(
132-
#[$attr]
133-
)*
134-
pub fn $feature(&self) -> bool {
135-
self.$feature
136-
}
137-
)*
138132
}
139133
}
140134
}

src/ir/analysis/derive_copy.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ impl<'ctx> MonotoneFramework for CannotDeriveCopy<'ctx> {
234234
}
235235

236236
if info.kind() == CompKind::Union {
237-
if !self.ctx.options().rust_features().untagged_union() {
237+
if !self.ctx.options().rust_features().untagged_union {
238238
// NOTE: If there's no template parameters we can derive
239239
// copy unconditionally, since arrays are magical for
240240
// rustc, and __BindgenUnionField always implements

src/ir/analysis/derive_debug.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ impl<'ctx> MonotoneFramework for CannotDeriveDebug<'ctx> {
150150
});
151151
return if layout_can_derive &&
152152
!(ty.is_union() &&
153-
self.ctx.options().rust_features().untagged_union()) {
153+
self.ctx.options().rust_features().untagged_union) {
154154
trace!(" we can trivially derive Debug for the layout");
155155
ConstrainResult::Same
156156
} else {
@@ -235,7 +235,7 @@ impl<'ctx> MonotoneFramework for CannotDeriveDebug<'ctx> {
235235
);
236236

237237
if info.kind() == CompKind::Union {
238-
if self.ctx.options().rust_features().untagged_union() {
238+
if self.ctx.options().rust_features().untagged_union {
239239
trace!(" cannot derive Debug for Rust unions");
240240
return self.insert(id);
241241
}

src/ir/analysis/derive_default.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ impl<'ctx> MonotoneFramework for CannotDeriveDefault<'ctx> {
177177
});
178178
return if layout_can_derive &&
179179
!(ty.is_union() &&
180-
self.ctx.options().rust_features().untagged_union()) {
180+
self.ctx.options().rust_features().untagged_union) {
181181
trace!(" we can trivially derive Default for the layout");
182182
ConstrainResult::Same
183183
} else {
@@ -271,7 +271,7 @@ impl<'ctx> MonotoneFramework for CannotDeriveDefault<'ctx> {
271271
}
272272

273273
if info.kind() == CompKind::Union {
274-
if self.ctx.options().rust_features().untagged_union() {
274+
if self.ctx.options().rust_features().untagged_union {
275275
trace!(" cannot derive Default for Rust unions");
276276
return self.insert(id);
277277
}

src/ir/analysis/derive_hash.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ impl<'ctx> MonotoneFramework for CannotDeriveHash<'ctx> {
137137
});
138138
return if layout_can_derive &&
139139
!(ty.is_union() &&
140-
self.ctx.options().rust_features().untagged_union()) {
140+
self.ctx.options().rust_features().untagged_union) {
141141
trace!(" we can trivially derive Hash for the layout");
142142
ConstrainResult::Same
143143
} else {
@@ -257,7 +257,7 @@ impl<'ctx> MonotoneFramework for CannotDeriveHash<'ctx> {
257257
}
258258

259259
if info.kind() == CompKind::Union {
260-
if self.ctx.options().rust_features().untagged_union() {
260+
if self.ctx.options().rust_features().untagged_union {
261261
trace!(" cannot derive Hash for Rust unions");
262262
return self.insert(id);
263263
}

src/ir/analysis/derive_partialeq_or_partialord.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ impl<'ctx> CannotDerivePartialEqOrPartialOrd<'ctx> {
119119
trace!("ty: {:?}", ty);
120120
if item.is_opaque(self.ctx, &()) {
121121
if ty.is_union()
122-
&& self.ctx.options().rust_features().untagged_union()
122+
&& self.ctx.options().rust_features().untagged_union
123123
{
124124
trace!(
125125
" cannot derive `PartialEq`/`PartialOrd` for Rust unions"
@@ -242,7 +242,7 @@ impl<'ctx> CannotDerivePartialEqOrPartialOrd<'ctx> {
242242
}
243243

244244
if info.kind() == CompKind::Union {
245-
if self.ctx.options().rust_features().untagged_union() {
245+
if self.ctx.options().rust_features().untagged_union {
246246
trace!(
247247
" cannot derive `PartialEq`/`PartialOrd` for Rust unions"
248248
);

src/ir/comp.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1543,7 +1543,7 @@ impl CompInfo {
15431543
/// 1. Current RustTarget allows for `untagged_union`
15441544
/// 2. Each field can derive `Copy`
15451545
pub fn can_be_rust_union(&self, ctx: &BindgenContext) -> bool {
1546-
if !ctx.options().rust_features().untagged_union() {
1546+
if !ctx.options().rust_features().untagged_union {
15471547
return false;
15481548
}
15491549

src/lib.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -600,6 +600,12 @@ impl Builder {
600600
self
601601
}
602602

603+
/// Disable support for native Rust unions, if supported.
604+
pub fn disable_untagged_union(mut self) -> Self {
605+
self.options.rust_features.untagged_union = false;
606+
self
607+
}
608+
603609
/// Set the output graphviz file.
604610
pub fn emit_ir_graphviz<T: Into<String>>(mut self, path: T) -> Builder {
605611
let path = path.into();

0 commit comments

Comments
 (0)