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

Type aliases do not work in #[repr(...)] for C-style enums #10374

Closed
brendanzab opened this issue Nov 9, 2013 · 9 comments
Closed

Type aliases do not work in #[repr(...)] for C-style enums #10374

brendanzab opened this issue Nov 9, 2013 · 9 comments
Labels
C-feature-request Category: A feature request, i.e: not implemented / a PR. T-lang Relevant to the language team, which will review and decide on the PR/issue.

Comments

@brendanzab
Copy link
Member

#[repr(c_int)]
enum ABC {
    A = 0,
    B = 1,
    C = 2,
}
$ rustc --lib repr-test.rs
repr-test.rs:1:7: 1:12 error: unrecognized representation hint
repr-test.rs:1 #[repr(c_int)]
                      ^~~~~
error: aborting due to previous error
task 'rustc' failed at 'explicit failure', /Users/brendan/dev/rust/rust/src/libsyntax/diagnostic.rs:101
task '<main>' failed at 'explicit failure', /Users/brendan/dev/rust/rust/src/librustc/lib.rs:397
@brendanzab
Copy link
Member Author

Apparently you can use #[repr(C)], but this doesn't seem all that flexible.

@huonw
Copy link
Member

huonw commented Nov 9, 2013

@bjz, if you are interfacing with C, you want #[repr(C)] rather than c_int, since it's not guaranteed that the size will be an int (i.e. the C type).

@brendanzab
Copy link
Member Author

@huonw Could you give an example?

@huonw
Copy link
Member

huonw commented Nov 9, 2013

Discussion on IRC revealed that @bjz is defining an enum wrapper around a series of #define constants, which are used as arguments to functions with type c_int, not just a plain C-enum, so my suggestion of #[repr(C)] doesn't necessarily directly apply.

@steveklabnik steveklabnik added the C-enhancement Category: An issue proposing an enhancement or a PR with one. label Sep 3, 2015
@steveklabnik
Copy link
Member

Triage: I believe we've gotten more restrictive with what can go inside of repr since then, making this an enhancement.

@steveklabnik
Copy link
Member

Triage: no change.

@Mark-Simulacrum
Copy link
Member

I'm not sure we expect to support type aliases and other "expressions" in repr. In fact, I'm not sure we should.

@Mark-Simulacrum Mark-Simulacrum added C-feature-request Category: A feature request, i.e: not implemented / a PR. T-lang Relevant to the language team, which will review and decide on the PR/issue. and removed A-attributes Area: Attributes (`#[…]`, `#![…]`) C-enhancement Category: An issue proposing an enhancement or a PR with one. labels Jul 28, 2017
@Havvy
Copy link
Contributor

Havvy commented Jun 30, 2018

IMO, this should be closed, with an RFC dedicated to the idea should somebody want to seriously pursue this. (Although I think it's a bad idea).

@Centril
Copy link
Contributor

Centril commented Jun 30, 2018

Closing per @Havvy's request and motivation and @steveklabnik's note from 2015.

@Centril Centril closed this as completed Jun 30, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-feature-request Category: A feature request, i.e: not implemented / a PR. 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

7 participants