Skip to content

Commit 05c2885

Browse files
committed
Allow blocklisting anonymous enums
1 parent 59a43e1 commit 05c2885

File tree

4 files changed

+15
-1
lines changed

4 files changed

+15
-1
lines changed

bindgen-tests/tests/expectations/tests/blocklist-anon-enum.rs

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// bindgen-flags: --blocklist-item 'SHOULD_BE_BLOCKED.*'
2+
3+
enum {
4+
SHOULD_BE_BLOCKED_1,
5+
SHOULD_BE_BLOCKED_2,
6+
SHOULD_BE_BLOCKED_3
7+
};

bindgen/codegen/mod.rs

+6
Original file line numberDiff line numberDiff line change
@@ -3595,6 +3595,12 @@ impl CodeGenerator for Enum {
35953595
let layout = enum_ty.layout(ctx);
35963596
let variation = self.computed_enum_variation(ctx, item);
35973597

3598+
// blocklist anonymous enums based on variants.
3599+
if enum_ty.name().is_none() && self.is_matching_enum(ctx, &ctx.options().blocklisted_items, item) {
3600+
debug!("Blocklisting anonymous enum.");
3601+
return;
3602+
}
3603+
35983604
let repr_translated;
35993605
let repr = match self.repr().map(|repr| ctx.resolve_type(repr)) {
36003606
Some(repr)

bindgen/ir/enum_ty.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ impl Enum {
150150
Ok(Enum::new(repr, variants))
151151
}
152152

153-
fn is_matching_enum(
153+
pub(crate) fn is_matching_enum(
154154
&self,
155155
ctx: &BindgenContext,
156156
enums: &RegexSet,

0 commit comments

Comments
 (0)