Repository: rust-lang/rust-bindgen (rust)

Issue:
allowlist_item does not work for anonymous enums - allowlist_var does
### Input C/C++ Header

```C++
enum
{
  BASS_FX_BFX_ROTATE = 0x10000
  BASS_FX_BFX_ECHO,
  BASS_FX_BFX_FLANGER
};
```

### Bindgen Invocation

```
$ bindgen input.h --allowlist-item "BASS.*" -o output.rs
```

### Actual Results

empty file - apart from the bindgen comment

one warning is outputted by bindgen: `bindgen::ir::context] unused option: --allowlist-items BASS.*`

### Expected Results

consts generated like this (works when omitting the `allowlist-items` flag or using `allowlist-var` instead):

```rust
/* automatically generated by rust-bindgen 0.69.4 */

pub const BASS_FX_BFX_ROTATE: _bindgen_ty_1 = 65536;
pub const BASS_FX_BFX_ECHO: _bindgen_ty_1 = 65537;
pub const BASS_FX_BFX_FLANGER: _bindgen_ty_1 = 65538;
pub type _bindgen_ty_1 = ::std::os::raw::c_int;
```


Pull request:
Fix `--allowlist-item` so it doesn't ignore anon enums
Fixes #2826


Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 390660f2..2dbcb146 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -209,6 +209,7 @@
 ## Fixed
 - Fix `--formatter=prettyplease` not working in `bindgen-cli` by adding `prettyplease` feature and
   enabling it by default for `bindgen-cli` (#2789) .
+- Fix `--allowlist-item` so anonymous enums are no longer ignored.
 ## Security
 
 # 0.69.4 (2024-02-04)
diff --git a/bindgen/ir/context.rs b/bindgen/ir/context.rs
index c4465df9..2e608b07 100644
--- a/bindgen/ir/context.rs
+++ b/bindgen/ir/context.rs
@@ -2530,7 +2530,11 @@ If you encounter an error missing from this list, please file an issue or a PR!"
                                 );
                                 let name = prefix_path[1..].join("::");
                                 prefix_path.pop().unwrap();
-                                self.options().allowlisted_vars.matches(name)
+                                self.options().allowlisted_vars.matches(&name)
+                                    || self
+                                        .options()
+                                        .allowlisted_items
+                                        .matches(name)
                             })
                         }
                     }


Test patch:
diff --git a/bindgen-tests/tests/expectations/tests/anon_enum_allowlist_item.rs b/bindgen-tests/tests/expectations/tests/anon_enum_allowlist_item.rs
new file mode 100644
index 00000000..4d28c3ab
--- /dev/null
+++ b/bindgen-tests/tests/expectations/tests/anon_enum_allowlist_item.rs
@@ -0,0 +1,4 @@
+#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]
+pub const NODE_FLAG_FOO: _bindgen_ty_1 = 0;
+pub const NODE_FLAG_BAR: _bindgen_ty_1 = 1;
+pub type _bindgen_ty_1 = ::std::os::raw::c_uint;
diff --git a/bindgen-tests/tests/headers/anon_enum_allowlist_item.h b/bindgen-tests/tests/headers/anon_enum_allowlist_item.h
new file mode 100644
index 00000000..23caacc9
--- /dev/null
+++ b/bindgen-tests/tests/headers/anon_enum_allowlist_item.h
@@ -0,0 +1,6 @@
+// bindgen-flags: --allowlist-item "NODE_.*"
+
+enum {
+  NODE_FLAG_FOO,
+  NODE_FLAG_BAR,
+};