Skip to content

#[repr(C)] silently accepted on ADT enums #31692

New issue

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

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

Already on GitHub? # to your account

Closed
durka opened this issue Feb 16, 2016 · 3 comments
Closed

#[repr(C)] silently accepted on ADT enums #31692

durka opened this issue Feb 16, 2016 · 3 comments
Labels
A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. C-bug Category: This is a bug. T-lang Relevant to the language team, which will review and decide on the PR/issue.

Comments

@durka
Copy link
Contributor

durka commented Feb 16, 2016

This code compiles without error or relevant warning:

#[repr(C)]
enum Foo { A { x: i32 }, B(i32), C }

#[repr(i32)]
enum Bar { Bar(i32), Baz(u32) }

But obviously the representation of the enum is still going to be undefined, and not integral or C-compatible (trivially checked by mem::size_of in this case).

There should be an error (probably infeasible) or at least a lint that is on by default.

@Aatch says there is already an issue about this, but I can't find it, so feel free to close as a duplicate if you can find it :)
cc @niconii

@nodakai
Copy link
Contributor

nodakai commented Feb 16, 2016

Take a look at #25651

@durka
Copy link
Contributor Author

durka commented Feb 16, 2016

Okay, so #[repr] on an enum controls the size of the discriminant, not the whole enum. At least #[repr(C)] should warn IMO because #[repr(C)] means "give this thing a defined layout", but that doesn't happen in this case.

@Mark-Simulacrum Mark-Simulacrum added A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. T-lang Relevant to the language team, which will review and decide on the PR/issue. labels Jun 23, 2017
@Mark-Simulacrum Mark-Simulacrum added the C-bug Category: This is a bug. label Jul 24, 2017
@Mark-Simulacrum Mark-Simulacrum changed the title #[repr] silently accepted on ADT enums #[repr(C)] silently accepted on ADT enums Jul 24, 2017
@hanna-kruppe
Copy link
Contributor

rust-lang/rfcs#2195 makes this do something useful so if/when that's accepted this issue can be closed I guess.

@fmease fmease added A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. and removed A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. labels Dec 21, 2024
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. C-bug Category: This is a bug. T-lang Relevant to the language team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

6 participants