Skip to content

Commit e901c73

Browse files
committed
Allow blocklisting anonymous enums
1 parent 97ab915 commit e901c73

File tree

4 files changed

+23
-1
lines changed

4 files changed

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

+10
Original file line numberDiff line numberDiff line change
@@ -3654,6 +3654,16 @@ impl CodeGenerator for Enum {
36543654
let layout = enum_ty.layout(ctx);
36553655
let variation = self.computed_enum_variation(ctx, item);
36563656

3657+
// blocklist anonymous enums if all variants match a regex.
3658+
if enum_ty.name().is_none() &&
3659+
self.variants()
3660+
.iter()
3661+
.all(|v| ctx.options().blocklisted_items.matches(v.name()))
3662+
{
3663+
debug!("Blocklisting anonymous enum.");
3664+
return;
3665+
}
3666+
36573667
let repr_translated;
36583668
let repr = match self.repr().map(|repr| ctx.resolve_type(repr)) {
36593669
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)