diff options
author | Alan Wu <XrXr@users.noreply.github.com> | 2022-04-13 18:55:49 -0400 |
---|---|---|
committer | Emilio Cobos Álvarez <emilio@crisal.io> | 2022-04-19 21:18:17 +0200 |
commit | 841fd4c8dc3790b068e2b63fbf892ccad5f17e00 (patch) | |
tree | 1f783c4dd19eee8443a3a97378f305fca0eccedf /src/codegen | |
parent | c27578fac5372575e3caa933a83eac931ae3b53f (diff) |
Use common type alias for anonymous enums in consts mode
Previously, anonymous enums generated a type alias but did not use it.
For example the following:
```C
enum {
ZERO,
ONE = 4999,
};
```
Generated this:
```Rust
/* automatically generated by rust-bindgen 0.59.2 */
pub const ZERO: ::std::os::raw::c_uint = 0;
pub const ONE: ::std::os::raw::c_uint = 4999;
pub type _bindgen_ty_1 = ::std::os::raw::c_uint;
```
For use cases where humans look at bindgen's Rust output this was a little
strange since it's a deviation from how the Rust output for named enums
is organized, where all constants share the same type using the type
alias. The unused type alias also triggered the dead_code lint.
Change to use the generated type alias.
Diffstat (limited to 'src/codegen')
-rw-r--r-- | src/codegen/mod.rs | 8 |
1 files changed, 2 insertions, 6 deletions
diff --git a/src/codegen/mod.rs b/src/codegen/mod.rs index ffa6879b..99cdf3c8 100644 --- a/src/codegen/mod.rs +++ b/src/codegen/mod.rs @@ -2625,7 +2625,6 @@ enum EnumBuilder<'a> { is_bitfield: bool, }, Consts { - repr: proc_macro2::TokenStream, variants: Vec<proc_macro2::TokenStream>, codegen_depth: usize, }, @@ -2696,7 +2695,6 @@ impl<'a> EnumBuilder<'a> { }); EnumBuilder::Consts { - repr, variants, codegen_depth: enum_codegen_depth, } @@ -2800,7 +2798,7 @@ impl<'a> EnumBuilder<'a> { self } - EnumBuilder::Consts { ref repr, .. } => { + EnumBuilder::Consts { .. } => { let constant_name = match mangling_prefix { Some(prefix) => { Cow::Owned(format!("{}_{}", prefix, variant_name)) @@ -2808,12 +2806,10 @@ impl<'a> EnumBuilder<'a> { None => variant_name, }; - let ty = if is_ty_named { &rust_ty } else { repr }; - let ident = ctx.rust_ident(constant_name); result.push(quote! { #doc - pub const #ident : #ty = #expr ; + pub const #ident : #rust_ty = #expr ; }); self |