summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/codegen/mod.rs15
-rw-r--r--tests/expectations/tests/prepend-enum-constified-variant.rs10
-rw-r--r--tests/headers/prepend-enum-constified-variant.h6
3 files changed, 27 insertions, 4 deletions
diff --git a/src/codegen/mod.rs b/src/codegen/mod.rs
index 86aafa39..8d979dce 100644
--- a/src/codegen/mod.rs
+++ b/src/codegen/mod.rs
@@ -2264,7 +2264,8 @@ impl CodeGenerator for Enum {
builder = builder.with_attr(derives);
}
- fn add_constant<'a>(enum_: &Type,
+ fn add_constant<'a>(ctx: &BindgenContext,
+ enum_: &Type,
// Only to avoid recomputing every time.
enum_canonical_name: &str,
// May be the same as "variant" if it's because the
@@ -2275,7 +2276,11 @@ impl CodeGenerator for Enum {
enum_rust_ty: P<ast::Ty>,
result: &mut CodegenResult<'a>) {
let constant_name = if enum_.name().is_some() {
- format!("{}_{}", enum_canonical_name, variant_name)
+ if ctx.options().prepend_enum_name {
+ format!("{}_{}", enum_canonical_name, variant_name)
+ } else {
+ variant_name.into()
+ }
} else {
variant_name.into()
};
@@ -2358,7 +2363,8 @@ impl CodeGenerator for Enum {
};
let existing_variant_name = entry.get();
- add_constant(enum_ty,
+ add_constant(ctx,
+ enum_ty,
&name,
&*mangled_name,
existing_variant_name,
@@ -2397,7 +2403,8 @@ impl CodeGenerator for Enum {
variant_name))
};
- add_constant(enum_ty,
+ add_constant(ctx,
+ enum_ty,
&name,
&mangled_name,
&variant_name,
diff --git a/tests/expectations/tests/prepend-enum-constified-variant.rs b/tests/expectations/tests/prepend-enum-constified-variant.rs
new file mode 100644
index 00000000..d5dca70c
--- /dev/null
+++ b/tests/expectations/tests/prepend-enum-constified-variant.rs
@@ -0,0 +1,10 @@
+/* automatically generated by rust-bindgen */
+
+
+#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]
+
+
+pub const AV_CODEC_ID_TTF: AVCodecID = AVCodecID::AV_CODEC_ID_FIRST_UNKNOWN;
+#[repr(u32)]
+#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
+pub enum AVCodecID { AV_CODEC_ID_FIRST_UNKNOWN = 98304, }
diff --git a/tests/headers/prepend-enum-constified-variant.h b/tests/headers/prepend-enum-constified-variant.h
new file mode 100644
index 00000000..aa526ffb
--- /dev/null
+++ b/tests/headers/prepend-enum-constified-variant.h
@@ -0,0 +1,6 @@
+// bindgen-flags: --no-prepend-enum-name
+
+enum AVCodecID {
+ AV_CODEC_ID_FIRST_UNKNOWN = 0x18000,
+ AV_CODEC_ID_TTF = 0x18000,
+};