summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCldfire <cldfire@3grid.net>2017-09-08 20:04:33 -0400
committerCldfire <cldfire@3grid.net>2017-09-11 13:11:44 -0400
commit89915f9536e4ce385683f0bcbcd9150536f9d975 (patch)
tree573ad0aaecf0b1da4650dcae34db374bcfefe969
parent4dd4ac75e29d3c1b304c9014df18a8efd35d4553 (diff)
Make bindgen generate enums as constants by default
Also simplifies the logic that determines which enum variation gets chosen.
-rw-r--r--bindgen-integration/build.rs1
-rw-r--r--src/codegen/mod.rs134
-rw-r--r--src/ir/enum_ty.rs24
-rw-r--r--src/lib.rs31
-rw-r--r--src/options.rs17
-rw-r--r--tests/headers/anon_enum.hpp2
-rw-r--r--tests/headers/anon_enum_trait.hpp2
-rw-r--r--tests/headers/anon_enum_whitelist.h2
-rw-r--r--tests/headers/anon_union.hpp2
-rw-r--r--tests/headers/anon_union_1_0.hpp2
-rw-r--r--tests/headers/bitfield-enum-basic.hpp2
-rw-r--r--tests/headers/bitfield_align_2.h2
-rw-r--r--tests/headers/class_with_inner_struct.hpp2
-rw-r--r--tests/headers/class_with_inner_struct_1_0.hpp2
-rw-r--r--tests/headers/const_enum_unnamed.hpp1
-rw-r--r--tests/headers/constant-evaluate.h1
-rw-r--r--tests/headers/constify-all-enums.h1
-rw-r--r--tests/headers/constify-enum.h1
-rw-r--r--tests/headers/enum.h2
-rw-r--r--tests/headers/enum_alias.hpp2
-rw-r--r--tests/headers/enum_and_vtable_mangling.hpp1
-rw-r--r--tests/headers/enum_dupe.h2
-rw-r--r--tests/headers/enum_explicit_type.hpp2
-rw-r--r--tests/headers/enum_in_template_with_typedef.hpp2
-rw-r--r--tests/headers/enum_negative.h2
-rw-r--r--tests/headers/enum_packed.h2
-rw-r--r--tests/headers/forward-enum-decl.hpp2
-rw-r--r--tests/headers/func_ptr_in_struct.h2
-rw-r--r--tests/headers/issue-372.hpp2
-rw-r--r--tests/headers/issue-410.hpp2
-rw-r--r--tests/headers/issue-493.hpp2
-rw-r--r--tests/headers/issue-493_1_0.hpp2
-rw-r--r--tests/headers/issue-569-non-type-template-params-causing-layout-test-failures.hpp2
-rw-r--r--tests/headers/issue-888-enum-var-decl-jump.hpp2
-rw-r--r--tests/headers/jsval_layout_opaque.hpp2
-rw-r--r--tests/headers/jsval_layout_opaque_1_0.hpp2
-rw-r--r--tests/headers/layout_array_too_long.h2
-rw-r--r--tests/headers/layout_cmdline_token.h1
-rw-r--r--tests/headers/layout_eth_conf.h2
-rw-r--r--tests/headers/layout_eth_conf_1_0.h2
-rw-r--r--tests/headers/layout_large_align_field.h2
-rw-r--r--tests/headers/no-recursive-whitelisting.h2
-rw-r--r--tests/headers/no-std.h2
-rw-r--r--tests/headers/nsStyleAutoArray.hpp1
-rw-r--r--tests/headers/overflowed_enum.hpp2
-rw-r--r--tests/headers/prepend-enum-constified-variant.h2
-rw-r--r--tests/headers/prepend_enum_name.hpp2
-rw-r--r--tests/headers/short-enums.hpp2
-rw-r--r--tests/headers/struct_typedef.h2
-rw-r--r--tests/headers/struct_typedef_ns.hpp2
-rw-r--r--tests/headers/weird_bitfields.hpp2
51 files changed, 182 insertions, 110 deletions
diff --git a/bindgen-integration/build.rs b/bindgen-integration/build.rs
index 7107d04b..54546ab0 100644
--- a/bindgen-integration/build.rs
+++ b/bindgen-integration/build.rs
@@ -29,6 +29,7 @@ fn main() {
let bindings = Builder::default()
.enable_cxx_namespaces()
+ .rustified_enum(".*")
.raw_line("pub use self::root::*;")
.header("cpp/Test.h")
.clang_args(&["-x", "c++", "-std=c++11"])
diff --git a/src/codegen/mod.rs b/src/codegen/mod.rs
index f13bd65a..b8416314 100644
--- a/src/codegen/mod.rs
+++ b/src/codegen/mod.rs
@@ -2072,7 +2072,41 @@ impl MethodCodegen for Method {
}
}
-/// A helper type to construct enums, either bitfield ones or rust-style ones.
+/// A helper type that represents different enum variations.
+#[derive(Copy, Clone)]
+enum EnumVariation {
+ Rust,
+ Bitfield,
+ Consts,
+ ModuleConsts
+}
+
+impl EnumVariation {
+ fn is_rust(&self) -> bool {
+ match *self {
+ EnumVariation::Rust => true,
+ _ => false
+ }
+ }
+
+ fn is_bitfield(&self) -> bool {
+ match *self {
+ EnumVariation::Bitfield => true,
+ _ => false
+ }
+ }
+
+ /// Both the `Const` and `ModuleConsts` variants will cause this to return
+ /// true.
+ fn is_const(&self) -> bool {
+ match *self {
+ EnumVariation::Consts | EnumVariation::ModuleConsts => true,
+ _ => false
+ }
+ }
+}
+
+/// A helper type to construct different enum variations.
enum EnumBuilder<'a> {
Rust(quote::Tokens),
Bitfield {
@@ -2088,26 +2122,44 @@ enum EnumBuilder<'a> {
impl<'a> EnumBuilder<'a> {
/// Create a new enum given an item builder, a canonical name, a name for
- /// the representation, and whether it should be represented as a rust enum.
+ /// the representation, and which variation it should be generated as.
fn new(
name: &'a str,
attrs: Vec<quote::Tokens>,
repr: quote::Tokens,
- bitfield_like: bool,
- constify: bool,
- constify_module: bool,
+ enum_variation: EnumVariation
) -> Self {
let ident = quote::Ident::new(name);
- if bitfield_like {
- EnumBuilder::Bitfield {
- canonical_name: name,
- tokens: quote! {
+
+ match enum_variation {
+ EnumVariation::Bitfield => {
+ EnumBuilder::Bitfield {
+ canonical_name: name,
+ tokens: quote! {
+ #( #attrs )*
+ pub struct #ident (pub #repr);
+ },
+ }
+ }
+
+ EnumVariation::Rust => {
+ let mut tokens = quote! {
#( #attrs )*
- pub struct #ident (pub #repr);
- },
+ pub enum #ident
+ };
+ tokens.append("{");
+ EnumBuilder::Rust(tokens)
}
- } else if constify {
- if constify_module {
+
+ EnumVariation::Consts => {
+ EnumBuilder::Consts(vec![
+ quote! {
+ pub type #ident = #repr;
+ }
+ ])
+ }
+
+ EnumVariation::ModuleConsts => {
let ident = quote::Ident::new(CONSTIFIED_ENUM_MODULE_REPR_NAME);
let type_definition = quote! {
pub type #ident = #repr;
@@ -2117,20 +2169,7 @@ impl<'a> EnumBuilder<'a> {
module_name: name,
module_items: vec![type_definition],
}
- } else {
- EnumBuilder::Consts(vec![
- quote! {
- pub type #ident = #repr;
- }
- ])
}
- } else {
- let mut tokens = quote! {
- #( #attrs )*
- pub enum #ident
- };
- tokens.append("{");
- EnumBuilder::Rust(tokens)
}
}
@@ -2342,39 +2381,28 @@ impl CodeGenerator for Enum {
// FIXME(emilio): These should probably use the path so it can
// disambiguate between namespaces, just like is_opaque etc.
- let is_bitfield = {
- ctx.options().bitfield_enums.matches(&name) ||
- (enum_ty.name().is_none() &&
- self.variants().iter().any(|v| {
- ctx.options().bitfield_enums.matches(&v.name())
- }))
- };
-
- let is_constified_enum_module =
- self.is_constified_enum_module(ctx, item);
-
- let is_constified_enum = {
- is_constified_enum_module ||
- ctx.options().constified_enums.matches(&name) ||
- (enum_ty.name().is_none() &&
- self.variants().iter().any(|v| {
- ctx.options().constified_enums.matches(&v.name())
- }))
+ let variation = if self.is_bitfield(ctx, item) {
+ EnumVariation::Bitfield
+ } else if self.is_rustified_enum(ctx, item) {
+ EnumVariation::Rust
+ } else if self.is_constified_enum_module(ctx, item) {
+ EnumVariation::ModuleConsts
+ } else {
+ // We generate consts by default
+ EnumVariation::Consts
};
- let is_rust_enum = !is_bitfield && !is_constified_enum;
-
let mut attrs = vec![];
// FIXME: Rust forbids repr with empty enums. Remove this condition when
// this is allowed.
//
// TODO(emilio): Delegate this to the builders?
- if is_rust_enum {
+ if variation.is_rust() {
if !self.variants().is_empty() {
attrs.push(attributes::repr(repr_name));
}
- } else if is_bitfield {
+ } else if variation.is_bitfield() {
attrs.push(attributes::repr("C"));
}
@@ -2382,7 +2410,7 @@ impl CodeGenerator for Enum {
attrs.push(attributes::doc(comment));
}
- if !is_constified_enum {
+ if !variation.is_const() {
attrs.push(attributes::derives(
&["Debug", "Copy", "Clone", "PartialEq", "Eq", "Hash"],
));
@@ -2427,9 +2455,7 @@ impl CodeGenerator for Enum {
&name,
attrs,
repr,
- is_bitfield,
- is_constified_enum,
- is_constified_enum_module,
+ variation
);
// A map where we keep a value -> variant relation.
@@ -2475,7 +2501,7 @@ impl CodeGenerator for Enum {
match seen_values.entry(variant.val()) {
Entry::Occupied(ref entry) => {
- if is_rust_enum {
+ if variation.is_rust() {
let variant_name = ctx.rust_mangle(variant.name());
let mangled_name =
if is_toplevel || enum_ty.name().is_some() {
@@ -2523,7 +2549,7 @@ impl CodeGenerator for Enum {
// If it's an unnamed enum, or constification is enforced,
// we also generate a constant so it can be properly
// accessed.
- if (is_rust_enum && enum_ty.name().is_none()) ||
+ if (variation.is_rust() && enum_ty.name().is_none()) ||
variant.force_constification()
{
let mangled_name = if is_toplevel {
diff --git a/src/ir/enum_ty.rs b/src/ir/enum_ty.rs
index bcd56974..dc56f64a 100644
--- a/src/ir/enum_ty.rs
+++ b/src/ir/enum_ty.rs
@@ -128,6 +128,18 @@ impl Enum {
Ok(Enum::new(repr, variants))
}
+ /// Whether the enum should be a bitfield
+ pub fn is_bitfield(&self, ctx: &BindgenContext, item: &Item) -> bool {
+ let name = item.canonical_name(ctx);
+ let enum_ty = item.expect_type();
+
+ ctx.options().bitfield_enums.matches(&name) ||
+ (enum_ty.name().is_none() &&
+ self.variants().iter().any(|v| {
+ ctx.options().bitfield_enums.matches(&v.name())
+ }))
+ }
+
/// Whether the enum should be an constified enum module
pub fn is_constified_enum_module(
&self,
@@ -143,6 +155,18 @@ impl Enum {
ctx.options().constified_enum_modules.matches(&v.name())
}))
}
+
+ /// Whether the enum should be a Rust enum
+ pub fn is_rustified_enum(&self, ctx: &BindgenContext, item: &Item) -> bool {
+ let name = item.canonical_name(ctx);
+ let enum_ty = item.expect_type();
+
+ ctx.options().rustified_enums.matches(&name) ||
+ (enum_ty.name().is_none() &&
+ self.variants().iter().any(|v| {
+ ctx.options().rustified_enums.matches(&v.name())
+ }))
+ }
}
/// A single enum variant, to be contained only in an enum.
diff --git a/src/lib.rs b/src/lib.rs
index b6310713..dc640911 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -197,11 +197,11 @@ impl Builder {
.count();
self.options
- .constified_enums
+ .rustified_enums
.get_items()
.iter()
.map(|item| {
- output_vector.push("--constified-enum".into());
+ output_vector.push("--rustified-enum".into());
output_vector.push(
item.trim_left_matches("^")
.trim_right_matches("$")
@@ -666,21 +666,26 @@ impl Builder {
self
}
- /// Mark the given enum (or set of enums, if using a pattern) as a set of
- /// constants.
+ /// Mark the given enum (or set of enums, if using a pattern) as a Rust
+ /// enum.
///
- /// This makes bindgen generate constants instead of enums. Regular
+ /// This makes bindgen generate enums instead of constants. Regular
/// expressions are supported.
- pub fn constified_enum<T: AsRef<str>>(mut self, arg: T) -> Builder {
- self.options.constified_enums.insert(arg);
+ ///
+ /// **Use this with caution.** You should not be using Rust enums unless
+ /// you have complete control of the C/C++ code that you're binding to.
+ /// Take a look at https://github.com/rust-lang/rust/issues/36927 for
+ /// more information.
+ pub fn rustified_enum<T: AsRef<str>>(mut self, arg: T) -> Builder {
+ self.options.rustified_enums.insert(arg);
self
}
/// Mark the given enum (or set of enums, if using a pattern) as a set of
/// constants that should be put into a module.
///
- /// This makes bindgen generate a modules containing constants instead of
- /// enums. Regular expressions are supported.
+ /// This makes bindgen generate modules containing constants instead of
+ /// just constants. Regular expressions are supported.
pub fn constified_enum_module<T: AsRef<str>>(mut self, arg: T) -> Builder {
self.options.constified_enum_modules.insert(arg);
self
@@ -1094,8 +1099,8 @@ pub struct BindgenOptions {
/// The enum patterns to mark an enum as bitfield.
pub bitfield_enums: RegexSet,
- /// The enum patterns to mark an enum as constant.
- pub constified_enums: RegexSet,
+ /// The enum patterns to mark an enum as a Rust enum.
+ pub rustified_enums: RegexSet,
/// The enum patterns to mark an enum as a module of constants.
pub constified_enum_modules: RegexSet,
@@ -1251,7 +1256,7 @@ impl BindgenOptions {
self.opaque_types.build();
self.bitfield_enums.build();
self.constified_enum_modules.build();
- self.constified_enums.build();
+ self.rustified_enums.build();
}
/// Update rust target version
@@ -1286,7 +1291,7 @@ impl Default for BindgenOptions {
whitelisted_functions: Default::default(),
whitelisted_vars: Default::default(),
bitfield_enums: Default::default(),
- constified_enums: Default::default(),
+ rustified_enums: Default::default(),
constified_enum_modules: Default::default(),
builtins: false,
links: vec![],
diff --git a/src/options.rs b/src/options.rs
index 50238f1c..383a8899 100644
--- a/src/options.rs
+++ b/src/options.rs
@@ -34,10 +34,10 @@ where
.takes_value(true)
.multiple(true)
.number_of_values(1),
- Arg::with_name("constified-enum")
- .long("constified-enum")
- .help("Mark any enum whose name matches <regex> as a set of \
- constants instead of an enumeration.")
+ Arg::with_name("rustified-enum")
+ .long("rustified-enum")
+ .help("Mark any enum whose name matches <regex> as a Rust enum \
+ instead of a set of constants.")
.value_name("regex")
.takes_value(true)
.multiple(true)
@@ -45,8 +45,7 @@ where
Arg::with_name("constified-enum-module")
.long("constified-enum-module")
.help("Mark any enum whose name matches <regex> as a module of \
- constants instead of an enumeration. This option \
- implies \"--constified-enum.\"")
+ constants instead of just constants.")
.value_name("regex")
.takes_value(true)
.multiple(true)
@@ -292,9 +291,9 @@ where
}
}
- if let Some(constifieds) = matches.values_of("constified-enum") {
- for regex in constifieds {
- builder = builder.constified_enum(regex);
+ if let Some(rustifieds) = matches.values_of("rustified-enum") {
+ for regex in rustifieds {
+ builder = builder.rustified_enum(regex);
}
}
diff --git a/tests/headers/anon_enum.hpp b/tests/headers/anon_enum.hpp
index 3e8ff3d4..23dc5ceb 100644
--- a/tests/headers/anon_enum.hpp
+++ b/tests/headers/anon_enum.hpp
@@ -1,4 +1,4 @@
-// bindgen-flags: --with-derive-hash --with-derive-partialeq --with-derive-eq
+// bindgen-flags: --with-derive-hash --with-derive-partialeq --with-derive-eq --rustified-enum .*
struct Test {
int foo;
float bar;
diff --git a/tests/headers/anon_enum_trait.hpp b/tests/headers/anon_enum_trait.hpp
index 865411e2..6383c748 100644
--- a/tests/headers/anon_enum_trait.hpp
+++ b/tests/headers/anon_enum_trait.hpp
@@ -1,4 +1,4 @@
-// bindgen-flags: --with-derive-hash --with-derive-partialeq --with-derive-eq
+// bindgen-flags: --with-derive-hash --with-derive-partialeq --with-derive-eq --rustified-enum .*
template<typename _Tp>
class DataType {
diff --git a/tests/headers/anon_enum_whitelist.h b/tests/headers/anon_enum_whitelist.h
index 15cda6b1..fc4810e0 100644
--- a/tests/headers/anon_enum_whitelist.h
+++ b/tests/headers/anon_enum_whitelist.h
@@ -1,4 +1,4 @@
-// bindgen-flags: --whitelist-var NODE_.*
+// bindgen-flags: --whitelist-var NODE_.* --rustified-enum .*
enum {
NODE_FLAG_FOO,
diff --git a/tests/headers/anon_union.hpp b/tests/headers/anon_union.hpp
index 8e649abb..19c478d1 100644
--- a/tests/headers/anon_union.hpp
+++ b/tests/headers/anon_union.hpp
@@ -1,4 +1,4 @@
-// bindgen-flags: --with-derive-hash --with-derive-partialeq --with-derive-eq
+// bindgen-flags: --with-derive-hash --with-derive-partialeq --with-derive-eq --rustified-enum .*
template<typename T>
struct TErrorResult {
enum UnionState {
diff --git a/tests/headers/anon_union_1_0.hpp b/tests/headers/anon_union_1_0.hpp
index 699efa32..314215bf 100644
--- a/tests/headers/anon_union_1_0.hpp
+++ b/tests/headers/anon_union_1_0.hpp
@@ -1,4 +1,4 @@
-// bindgen-flags: --rust-target 1.0 --with-derive-hash --with-derive-partialeq --with-derive-eq
+// bindgen-flags: --rust-target 1.0 --with-derive-hash --with-derive-partialeq --with-derive-eq --rustified-enum .*
template<typename T>
struct TErrorResult {
diff --git a/tests/headers/bitfield-enum-basic.hpp b/tests/headers/bitfield-enum-basic.hpp
index 364bebf2..c03f0e70 100644
--- a/tests/headers/bitfield-enum-basic.hpp
+++ b/tests/headers/bitfield-enum-basic.hpp
@@ -1,4 +1,4 @@
-// bindgen-flags: --bitfield-enum "Foo|Buz|NS_.*|DUMMY_.*" -- -std=c++11
+// bindgen-flags: --bitfield-enum "Foo|Buz|NS_.*|DUMMY_.*" --rustified-enum .* -- -std=c++11
enum Foo {
Bar = 1 << 1,
diff --git a/tests/headers/bitfield_align_2.h b/tests/headers/bitfield_align_2.h
index c6e5e5e7..31d37f76 100644
--- a/tests/headers/bitfield_align_2.h
+++ b/tests/headers/bitfield_align_2.h
@@ -1,4 +1,4 @@
-
+// bindgen-flags: --rustified-enum .*
enum MyEnum {
ONE,
TWO,
diff --git a/tests/headers/class_with_inner_struct.hpp b/tests/headers/class_with_inner_struct.hpp
index 3cb6cfed..66c2bd3f 100644
--- a/tests/headers/class_with_inner_struct.hpp
+++ b/tests/headers/class_with_inner_struct.hpp
@@ -1,4 +1,4 @@
-// bindgen-flags: --with-derive-hash --with-derive-partialeq --with-derive-eq
+// bindgen-flags: --with-derive-hash --with-derive-partialeq --with-derive-eq --rustified-enum .*
// bindgen-flags: -- -std=c++11
class A {
diff --git a/tests/headers/class_with_inner_struct_1_0.hpp b/tests/headers/class_with_inner_struct_1_0.hpp
index 0bb8a57f..1bae249f 100644
--- a/tests/headers/class_with_inner_struct_1_0.hpp
+++ b/tests/headers/class_with_inner_struct_1_0.hpp
@@ -1,4 +1,4 @@
-// bindgen-flags: --rust-target 1.0 --with-derive-hash --with-derive-partialeq --with-derive-eq
+// bindgen-flags: --rust-target 1.0 --with-derive-hash --with-derive-partialeq --with-derive-eq --rustified-enum .*
// bindgen-flags: -- -std=c++11
class A {
diff --git a/tests/headers/const_enum_unnamed.hpp b/tests/headers/const_enum_unnamed.hpp
index eb139434..bdd9700f 100644
--- a/tests/headers/const_enum_unnamed.hpp
+++ b/tests/headers/const_enum_unnamed.hpp
@@ -1,3 +1,4 @@
+// bindgen-flags: --rustified-enum .*
enum {
FOO_BAR,
diff --git a/tests/headers/constant-evaluate.h b/tests/headers/constant-evaluate.h
index f9f1fa66..ee9cfaa5 100644
--- a/tests/headers/constant-evaluate.h
+++ b/tests/headers/constant-evaluate.h
@@ -1,4 +1,5 @@
// bindgen-unstable
+// bindgen-flags: --rustified-enum .*
enum {
foo = 4,
diff --git a/tests/headers/constify-all-enums.h b/tests/headers/constify-all-enums.h
index 7138bf20..6f4364e3 100644
--- a/tests/headers/constify-all-enums.h
+++ b/tests/headers/constify-all-enums.h
@@ -1,4 +1,3 @@
-// bindgen-flags: --constified-enum foo
enum foo {
THIS,
diff --git a/tests/headers/constify-enum.h b/tests/headers/constify-enum.h
index a5b4052c..9a9058d3 100644
--- a/tests/headers/constify-enum.h
+++ b/tests/headers/constify-enum.h
@@ -1,3 +1,4 @@
+// bindgen-flags: --rustified-enum .*
enum nsCSSPropertyID {
eCSSProperty_a,
diff --git a/tests/headers/enum.h b/tests/headers/enum.h
index f2d301e7..38ce4eee 100644
--- a/tests/headers/enum.h
+++ b/tests/headers/enum.h
@@ -1,3 +1,5 @@
+// bindgen-flags: --rustified-enum .*
+
enum Foo {
Bar = 0,
Qux
diff --git a/tests/headers/enum_alias.hpp b/tests/headers/enum_alias.hpp
index 658f8fde..c3ecc351 100644
--- a/tests/headers/enum_alias.hpp
+++ b/tests/headers/enum_alias.hpp
@@ -1,4 +1,4 @@
-// bindgen-flags: -- -std=c++11
+// bindgen-flags: --rustified-enum .* -- -std=c++11
typedef unsigned char uint8_t;
diff --git a/tests/headers/enum_and_vtable_mangling.hpp b/tests/headers/enum_and_vtable_mangling.hpp
index 4c7f4d2b..e332fc57 100644
--- a/tests/headers/enum_and_vtable_mangling.hpp
+++ b/tests/headers/enum_and_vtable_mangling.hpp
@@ -1,3 +1,4 @@
+// bindgen-flags: --rustified-enum .*
enum {
match,
diff --git a/tests/headers/enum_dupe.h b/tests/headers/enum_dupe.h
index 6d3591d5..826568fb 100644
--- a/tests/headers/enum_dupe.h
+++ b/tests/headers/enum_dupe.h
@@ -1,3 +1,5 @@
+// bindgen-flags: --rustified-enum .*
+
enum Foo {
Bar = 1,
Dupe = 1
diff --git a/tests/headers/enum_explicit_type.hpp b/tests/headers/enum_explicit_type.hpp
index b2a4307e..e611de74 100644
--- a/tests/headers/enum_explicit_type.hpp
+++ b/tests/headers/enum_explicit_type.hpp
@@ -1,4 +1,4 @@
-// bindgen-flags: -- -std=c++11
+// bindgen-flags: --rustified-enum .* -- -std=c++11
enum Foo: unsigned char {
Bar = 0,
diff --git a/tests/headers/enum_in_template_with_typedef.hpp b/tests/headers/enum_in_template_with_typedef.hpp
index ac19b781..244d916c 100644
--- a/tests/headers/enum_in_template_with_typedef.hpp
+++ b/tests/headers/enum_in_template_with_typedef.hpp
@@ -1,4 +1,4 @@
-// bindgen-flags: -- -std=c++11
+// bindgen-flags: --rustified-enum .* -- -std=c++11
namespace std {
template <typename Char> class fbstring_core;
diff --git a/tests/headers/enum_negative.h b/tests/headers/enum_negative.h
index 6cbdfe04..267f799f 100644
--- a/tests/headers/enum_negative.h
+++ b/tests/headers/enum_negative.h
@@ -1,3 +1,5 @@
+// bindgen-flags: --rustified-enum .*
+
enum Foo {
Bar = -2,
Qux = 1,
diff --git a/tests/headers/enum_packed.h b/tests/headers/enum_packed.h
index 8654d110..1c89b992 100644
--- a/tests/headers/enum_packed.h
+++ b/tests/headers/enum_packed.h
@@ -1,3 +1,5 @@
+// bindgen-flags: --rustified-enum .*
+
enum __attribute__((packed)) Foo {
Bar = 0,
Qux
diff --git a/tests/headers/forward-enum-decl.hpp b/tests/headers/forward-enum-decl.hpp
index 2c4316c6..a3df8584 100644
--- a/tests/headers/forward-enum-decl.hpp
+++ b/tests/headers/forward-enum-decl.hpp
@@ -1,4 +1,4 @@
-// bindgen-flags: -- -std=c++11
+// bindgen-flags: --rustified-enum .* -- -std=c++11
enum class CSSPseudoClassType : int;
diff --git a/tests/headers/func_ptr_in_struct.h b/tests/headers/func_ptr_in_struct.h
index 24e1f44f..dd608549 100644
--- a/tests/headers/func_ptr_in_struct.h
+++ b/tests/headers/func_ptr_in_struct.h
@@ -1,4 +1,4 @@
-// bindgen-flags: --with-derive-hash --with-derive-partialeq --with-derive-eq
+// bindgen-flags: --with-derive-hash --with-derive-partialeq --with-derive-eq --rustified-enum .*
//
enum baz;
diff --git a/tests/headers/issue-372.hpp b/tests/headers/issue-372.hpp
index a072f061..de144776 100644
--- a/tests/headers/issue-372.hpp
+++ b/tests/headers/issue-372.hpp
@@ -1,4 +1,4 @@
-// bindgen-flags: --enable-cxx-namespaces
+// bindgen-flags: --enable-cxx-namespaces --rustified-enum .*
template <typename a, int b> class c { a e[b]; };
class d;
template <typename g, g f> class C { c<d, f> h; };
diff --git a/tests/headers/issue-410.hpp b/tests/headers/issue-410.hpp
index a7a834cf..c91c83d1 100644
--- a/tests/headers/issue-410.hpp
+++ b/tests/headers/issue-410.hpp
@@ -1,4 +1,4 @@
-// bindgen-flags: --enable-cxx-namespaces --whitelist-type JS::Value
+// bindgen-flags: --enable-cxx-namespaces --whitelist-type JS::Value --rustified-enum .*
namespace JS {
class Value;
diff --git a/tests/headers/issue-493.hpp b/tests/headers/issue-493.hpp
index 5d4cb4b8..280b8736 100644
--- a/tests/headers/issue-493.hpp
+++ b/tests/headers/issue-493.hpp
@@ -1,4 +1,4 @@
-// bindgen-flags: --with-derive-hash --with-derive-partialeq --with-derive-eq
+// bindgen-flags: --with-derive-hash --with-derive-partialeq --with-derive-eq --rustified-enum .*
template<class _CharT, class _Traits, class _Allocator>
class basic_string
{
diff --git a/tests/headers/issue-493_1_0.hpp b/tests/headers/issue-493_1_0.hpp
index 4e383be3..7406d893 100644
--- a/tests/headers/issue-493_1_0.hpp
+++ b/tests/headers/issue-493_1_0.hpp
@@ -1,4 +1,4 @@
-// bindgen-flags: --rust-target 1.0 --with-derive-hash --with-derive-partialeq --with-derive-eq
+// bindgen-flags: --rust-target 1.0 --with-derive-hash --with-derive-partialeq --with-derive-eq --rustified-enum .*
template<class _CharT, class _Traits, class _Allocator>
class basic_string
diff --git a/tests/headers/issue-569-non-type-template-params-causing-layout-test-failures.hpp b/tests/headers/issue-569-non-type-template-params-causing-layout-test-failures.hpp
index 7f8c2d8a..964b69cb 100644
--- a/tests/headers/issue-569-non-type-template-params-causing-layout-test-failures.hpp
+++ b/tests/headers/issue-569-non-type-template-params-causing-layout-test-failures.hpp
@@ -1,4 +1,4 @@
-// bindgen-flags: -- -std=c++14
+// bindgen-flags: --rustified-enum .* -- -std=c++14
// Generated by C-Reduce, cleaned up and given names for readability.
diff --git a/tests/headers/issue-888-enum-var-decl-jump.hpp b/tests/headers/issue-888-enum-var-decl-jump.hpp
index d7f31b3e..d7182c3c 100644
--- a/tests/headers/issue-888-enum-var-decl-jump.hpp
+++ b/tests/headers/issue-888-enum-var-decl-jump.hpp
@@ -1,4 +1,4 @@
-// bindgen-flags: --enable-cxx-namespaces
+// bindgen-flags: --enable-cxx-namespaces --rustified-enum .*
namespace Halide {
struct Type;
diff --git a/tests/headers/jsval_layout_opaque.hpp b/tests/headers/jsval_layout_opaque.hpp
index 09b5bebe..7a1957cf 100644
--- a/tests/headers/jsval_layout_opaque.hpp
+++ b/tests/headers/jsval_layout_opaque.hpp
@@ -1,4 +1,4 @@
-// bindgen-flags: --with-derive-hash --with-derive-partialeq --with-derive-eq
+// bindgen-flags: --with-derive-hash --with-derive-partialeq --with-derive-eq --rustified-enum .*
// bindgen-flags: -- -std=c++11
/**
diff --git a/tests/headers/jsval_layout_opaque_1_0.hpp b/tests/headers/jsval_layout_opaque_1_0.hpp
index 61eefe1e..dcf6274d 100644
--- a/tests/headers/jsval_layout_opaque_1_0.hpp
+++ b/tests/headers/jsval_layout_opaque_1_0.hpp
@@ -1,4 +1,4 @@
-// bindgen-flags: --rust-target 1.0 --with-derive-hash --with-derive-partialeq --with-derive-eq
+// bindgen-flags: --rust-target 1.0 --with-derive-hash --with-derive-partialeq --with-derive-eq --rustified-enum .*
// bindgen-flags: -- -std=c++11
/**
diff --git a/tests/headers/layout_array_too_long.h b/tests/headers/layout_array_too_long.h
index 5240f040..a3ef3d20 100644
--- a/tests/headers/layout_array_too_long.h
+++ b/tests/headers/layout_array_too_long.h
@@ -1,4 +1,4 @@
-// bindgen-flags: --with-derive-hash --with-derive-partialeq --with-derive-eq
+// bindgen-flags: --with-derive-hash --with-derive-partialeq --with-derive-eq --rustified-enum .*
typedef unsigned char uint8_t;
typedef unsigned short uint16_t;
typedef unsigned int uint32_t;
diff --git a/tests/headers/layout_cmdline_token.h b/tests/headers/layout_cmdline_token.h
index 34ebd017..68dd53b8 100644
--- a/tests/headers/layout_cmdline_token.h
+++ b/tests/headers/layout_cmdline_token.h
@@ -1,3 +1,4 @@
+// bindgen-flags: --rustified-enum .*
/**
* Stores a pointer to the ops struct, and the offset: the place to
diff --git a/tests/headers/layout_eth_conf.h b/tests/headers/layout_eth_conf.h
index 637b5696..71a430bf 100644
--- a/tests/headers/layout_eth_conf.h
+++ b/tests/headers/layout_eth_conf.h
@@ -1,4 +1,4 @@
-// bindgen-flags: --with-derive-hash --with-derive-partialeq --with-derive-eq
+// bindgen-flags: --with-derive-hash --with-derive-partialeq --with-derive-eq --rustified-enum .*
typedef unsigned char uint8_t;
typedef unsigned short uint16_t;
typedef unsigned int uint32_t;
diff --git a/tests/headers/layout_eth_conf_1_0.h b/tests/headers/layout_eth_conf_1_0.h
index 285c8c7a..cf6fa6ad 100644
--- a/tests/headers/layout_eth_conf_1_0.h
+++ b/tests/headers/layout_eth_conf_1_0.h
@@ -1,4 +1,4 @@
-// bindgen-flags: --rust-target 1.0 --with-derive-hash --with-derive-partialeq --with-derive-eq
+// bindgen-flags: --rust-target 1.0 --with-derive-hash --with-derive-partialeq --with-derive-eq --rustified-enum .*
typedef unsigned char uint8_t;
typedef unsigned short uint16_t;
diff --git a/tests/headers/layout_large_align_field.h b/tests/headers/layout_large_align_field.h
index f4f412c6..5e87c2a1 100644
--- a/tests/headers/layout_large_align_field.h
+++ b/tests/headers/layout_large_align_field.h
@@ -1,3 +1,5 @@
+// bindgen-flags: --rustified-enum .*
+
typedef unsigned char uint8_t;
typedef unsigned short uint16_t;
typedef unsigned int uint32_t;
diff --git a/tests/headers/no-recursive-whitelisting.h b/tests/headers/no-recursive-whitelisting.h
index 1d805d93..8eb8afea 100644
--- a/tests/headers/no-recursive-whitelisting.h
+++ b/tests/headers/no-recursive-whitelisting.h
@@ -1,4 +1,4 @@
-// bindgen-flags: --no-recursive-whitelist --whitelist-type "Foo" --raw-line "pub enum Bar {}"
+// bindgen-flags: --no-recursive-whitelist --whitelist-type "Foo" --raw-line "pub enum Bar {}" --rustified-enum .*
struct Bar;
diff --git a/tests/headers/no-std.h b/tests/headers/no-std.h
index 7bee9657..9248cc3d 100644
--- a/tests/headers/no-std.h
+++ b/tests/headers/no-std.h
@@ -1,4 +1,4 @@
-// bindgen-flags: --ctypes-prefix "libc" --use-core --raw-line "#![no_std]" --raw-line "mod libc { pub type c_int = i32; pub enum c_void {} }"
+// bindgen-flags: --ctypes-prefix "libc" --use-core --raw-line "#![no_std]" --raw-line "mod libc { pub type c_int = i32; pub enum c_void {} }" --rustified-enum .*
struct foo {
int a, b;
void* bar;
diff --git a/tests/headers/nsStyleAutoArray.hpp b/tests/headers/nsStyleAutoArray.hpp
index 950152c0..2a0bc216 100644
--- a/tests/headers/nsStyleAutoArray.hpp
+++ b/tests/headers/nsStyleAutoArray.hpp
@@ -1,3 +1,4 @@
+// bindgen-flags: --rustified-enum .*
template<typename T>
class nsTArray {
diff --git a/tests/headers/overflowed_enum.hpp b/tests/headers/overflowed_enum.hpp
index 1f2075a5..53a05ddf 100644
--- a/tests/headers/overflowed_enum.hpp
+++ b/tests/headers/overflowed_enum.hpp
@@ -1,4 +1,4 @@
-// bindgen-flags: -- -std=c++11 -Wno-narrowing
+// bindgen-flags: --rustified-enum .* -- -std=c++11 -Wno-narrowing
enum Foo {
BAP_ARM = 0x93fcb9,
diff --git a/tests/headers/prepend-enum-constified-variant.h b/tests/headers/prepend-enum-constified-variant.h
index aa526ffb..06ae264f 100644
--- a/tests/headers/prepend-enum-constified-variant.h
+++ b/tests/headers/prepend-enum-constified-variant.h
@@ -1,4 +1,4 @@
-// bindgen-flags: --no-prepend-enum-name
+// bindgen-flags: --no-prepend-enum-name --rustified-enum .*
enum AVCodecID {
AV_CODEC_ID_FIRST_UNKNOWN = 0x18000,
diff --git a/tests/headers/prepend_enum_name.hpp b/tests/headers/prepend_enum_name.hpp
index df4ecf1f..e7660369 100644
--- a/tests/headers/prepend_enum_name.hpp
+++ b/tests/headers/prepend_enum_name.hpp
@@ -1,4 +1,4 @@
-// bindgen-flags: --constified-enum foo --no-prepend-enum-name
+// bindgen-flags: --no-prepend-enum-name
enum foo {
FOO_BAR,
diff --git a/tests/headers/short-enums.hpp b/tests/headers/short-enums.hpp
index 484c84af..0b517d6f 100644
--- a/tests/headers/short-enums.hpp
+++ b/tests/headers/short-enums.hpp
@@ -1,4 +1,4 @@
-// bindgen-flags: -- -std=c++11 -fshort-enums
+// bindgen-flags: --rustified-enum .* -- -std=c++11 -fshort-enums
typedef enum {
SOME_VALUE = 0x1,
diff --git a/tests/headers/struct_typedef.h b/tests/headers/struct_typedef.h
index de861c5f..e996b28f 100644
--- a/tests/headers/struct_typedef.h
+++ b/tests/headers/struct_typedef.h
@@ -1,4 +1,4 @@
-// bindgen-flags: --with-derive-hash --with-derive-partialeq --with-derive-eq
+// bindgen-flags: --with-derive-hash --with-derive-partialeq --with-derive-eq --rustified-enum .*
//
typedef struct {
_Bool has_name;
diff --git a/tests/headers/struct_typedef_ns.hpp b/tests/headers/struct_typedef_ns.hpp
index 07ecc160..a5a8f9a6 100644
--- a/tests/headers/struct_typedef_ns.hpp
+++ b/tests/headers/struct_typedef_ns.hpp
@@ -1,4 +1,4 @@
-// bindgen-flags: --with-derive-hash --with-derive-partialeq --with-derive-eq --enable-cxx-namespaces
+// bindgen-flags: --with-derive-hash --with-derive-partialeq --with-derive-eq --enable-cxx-namespaces --rustified-enum .*
namespace whatever {
typedef struct {
diff --git a/tests/headers/weird_bitfields.hpp b/tests/headers/weird_bitfields.hpp
index 68cbf4a5..7236d60a 100644
--- a/tests/headers/weird_bitfields.hpp
+++ b/tests/headers/weird_bitfields.hpp
@@ -1,3 +1,5 @@
+// bindgen-flags: --rustified-enum .*
+
// You can guess where this is taken from...
enum nsStyleSVGOpacitySource {
eStyleSVGOpacitySource_Normal,