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 /tests | |
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 'tests')
4 files changed, 9 insertions, 9 deletions
diff --git a/tests/expectations/tests/enum-default-consts.rs b/tests/expectations/tests/enum-default-consts.rs index 5c023a3c..d7f5d7c2 100644 --- a/tests/expectations/tests/enum-default-consts.rs +++ b/tests/expectations/tests/enum-default-consts.rs @@ -10,8 +10,8 @@ pub struct foo { pub member: foo__bindgen_ty_1, } -pub const foo_FOO_A: ::std::os::raw::c_uint = 0; -pub const foo_FOO_B: ::std::os::raw::c_uint = 1; +pub const foo_FOO_A: foo__bindgen_ty_1 = 0; +pub const foo_FOO_B: foo__bindgen_ty_1 = 1; pub type foo__bindgen_ty_1 = ::std::os::raw::c_uint; #[test] fn bindgen_test_layout_foo() { @@ -60,4 +60,4 @@ pub type NoDebug = ::std::os::raw::c_uint; pub const Debug_Debug1: Debug = 0; pub const Debug_Debug2: Debug = 1; /// <div rustbindgen derive="Debug"></div> -pub type Debug = ::std::os::raw::c_uint;
\ No newline at end of file +pub type Debug = ::std::os::raw::c_uint; diff --git a/tests/expectations/tests/enum.rs b/tests/expectations/tests/enum.rs index cc3f4932..fd76151f 100644 --- a/tests/expectations/tests/enum.rs +++ b/tests/expectations/tests/enum.rs @@ -10,8 +10,8 @@ pub struct foo { pub member: foo__bindgen_ty_1, } -pub const foo_FOO_A: ::std::os::raw::c_uint = 0; -pub const foo_FOO_B: ::std::os::raw::c_uint = 1; +pub const foo_FOO_A: foo__bindgen_ty_1 = 0; +pub const foo_FOO_B: foo__bindgen_ty_1 = 1; pub type foo__bindgen_ty_1 = ::std::os::raw::c_uint; #[test] fn bindgen_test_layout_foo() { @@ -58,4 +58,4 @@ pub type NoDebug = ::std::os::raw::c_uint; pub const Debug_Debug1: Debug = 0; pub const Debug_Debug2: Debug = 1; /// <div rustbindgen derive="Debug"></div> -pub type Debug = ::std::os::raw::c_uint;
\ No newline at end of file +pub type Debug = ::std::os::raw::c_uint; diff --git a/tests/expectations/tests/enum_explicit_type_constants.rs b/tests/expectations/tests/enum_explicit_type_constants.rs index 117f6847..0c833b66 100644 --- a/tests/expectations/tests/enum_explicit_type_constants.rs +++ b/tests/expectations/tests/enum_explicit_type_constants.rs @@ -26,6 +26,6 @@ pub type BoolEnumsAreFun = bool; pub type MyType = bool; pub const BoolEnumsAreFun2_Value2: BoolEnumsAreFun2 = true; pub type BoolEnumsAreFun2 = MyType; -pub const AnonymousVariantOne: ::std::os::raw::c_uchar = 0; -pub const AnonymousVariantTwo: ::std::os::raw::c_uchar = 1; +pub const AnonymousVariantOne: _bindgen_ty_1 = 0; +pub const AnonymousVariantTwo: _bindgen_ty_1 = 1; pub type _bindgen_ty_1 = ::std::os::raw::c_uchar; diff --git a/tests/expectations/tests/parsecb-anonymous-enum-variant-rename.rs b/tests/expectations/tests/parsecb-anonymous-enum-variant-rename.rs index e615486e..8ead5b8a 100644 --- a/tests/expectations/tests/parsecb-anonymous-enum-variant-rename.rs +++ b/tests/expectations/tests/parsecb-anonymous-enum-variant-rename.rs @@ -5,5 +5,5 @@ non_upper_case_globals )] -pub const RENAMED_MyVal: ::std::os::raw::c_uint = 0; +pub const RENAMED_MyVal: _bindgen_ty_1 = 0; pub type _bindgen_ty_1 = ::std::os::raw::c_uint; |