Skip to content

Commit 3b5da54

Browse files
committed
Allow blocklisting anonymous enums
1 parent 03d49b6 commit 3b5da54

File tree

4 files changed

+25
-1
lines changed

4 files changed

+25
-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

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

3597+
// blocklist anonymous enums based on variants.
3598+
if enum_ty.name().is_none() &&
3599+
self.is_matching_enum(
3600+
ctx,
3601+
&ctx.options().blocklisted_items,
3602+
item,
3603+
)
3604+
{
3605+
debug!("Blocklisting anonymous enum.");
3606+
return;
3607+
}
3608+
35973609
let repr_translated;
35983610
let repr = match self.repr().map(|repr| ctx.resolve_type(repr)) {
35993611
Some(repr)

bindgen/ir/enum_ty.rs

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

153-
fn is_matching_enum(
153+
/// Checks if the enum matches any of the regular expressions in `enums`
154+
///
155+
/// For anonymous enums, returns true if any of the enum variants matches
156+
/// any of the regular expressions in `enums`.
157+
pub(crate) fn is_matching_enum(
154158
&self,
155159
ctx: &BindgenContext,
156160
enums: &RegexSet,

0 commit comments

Comments
 (0)