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

Rustified enums getting both #[repr(u32)] and #[repr(C)] #1224

Closed
faern opened this issue Jan 18, 2018 · 7 comments
Closed

Rustified enums getting both #[repr(u32)] and #[repr(C)] #1224

faern opened this issue Jan 18, 2018 · 7 comments

Comments

@faern
Copy link

faern commented Jan 18, 2018

Input C header

enum my_enum {
    VARIANT1,
};

Bindgen Invocation

$ bindgen enum.h --rustified-enum my_enum

Actual Results

With bindgen 0.32.1 I get:

#[repr(u32)]
#[repr(C)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub enum my_enum {
    VARIANT1 = 0,
}

rustc warning when compiling:

warning[E0566]: conflicting representation hints
 --> enum.rs:3:8
  |
3 | #[repr(u32)]
  |        ^^^
4 | #[repr(C)]
  |        ^

Expected Results

To only have one #[repr(...)]:

#[repr(C)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub enum my_enum {
    VARIANT1 = 0,
}
@faern
Copy link
Author

faern commented Jan 18, 2018

The same problem can be seen in the generated code in issue #1198. But that issue is about something else, so I felt it was worth reporting on this alone.

@RazrFalcon
Copy link

Stumbled on the same bug just now.

@emilio
Copy link
Contributor

emilio commented Jan 18, 2018

Hmm, this is clearly a regression... Shouldn't be hard to fix.

@emilio
Copy link
Contributor

emilio commented Jan 18, 2018

Oh, I lie, this was added intentionally in 43c43ba... Which version of rustc are you using?

@faern
Copy link
Author

faern commented Jan 18, 2018

@emilio rustc 1.25.0-nightly (3f92e8d89 2018-01-14)

EDIT: Latest nightly gives the same warning, but stable does not give any warning when compiling with two representation hints.

@emilio
Copy link
Contributor

emilio commented Jan 19, 2018

Ok, asked in #rustc today. Relevant log: https://botbot.me/mozilla/rustc/2018-01-19/?msg=95934948&page=2

TL;DR: the extra repr(C) is only needed for enums with fields, not for plain enums that bindgen generates.

@emilio
Copy link
Contributor

emilio commented Jan 19, 2018

Will send a patch with a fix.

emilio added a commit to emilio/rust-bindgen that referenced this issue Jan 19, 2018
bors-servo pushed a commit that referenced this issue Jan 19, 2018
codegen: Don't generate repr(C) for enums.

That's only undefined for enums with fields.

Fixes #1224
See also: https://botbot.me/mozilla/rustc/2018-01-19/?msg=95934948&page=2
emilio added a commit to emilio/rust-bindgen that referenced this issue Jan 19, 2018
bors-servo pushed a commit that referenced this issue Jan 19, 2018
codegen: Don't generate repr(C) for enums.

That's only undefined for enums with fields.

Fixes #1224
See also: https://botbot.me/mozilla/rustc/2018-01-19/?msg=95934948&page=2
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

No branches or pull requests

3 participants