Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use common type alias for anonymous enums in consts mode #2191

Merged
merged 1 commit into from Apr 19, 2022

Conversation

XrXr
Copy link
Contributor

@XrXr XrXr commented Apr 19, 2022

Previously, anonymous enums generated a type alias but did not use it.
For example the following:

enum {
    ZERO,
    ONE = 4999,
};

Generated this:

/* 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.


Just a minor improvement. It's a further revert of #1850 after the fix in #1882

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.
Copy link
Contributor

@emilio emilio left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This goes back to f56fbce, but I think this behavior makes more sense generally, indeed.

@emilio emilio merged commit 841fd4c into rust-lang:master Apr 19, 2022
@XrXr XrXr deleted the unused-enum-type branch April 19, 2022 19:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants