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

Why can I not use a type alias in #[repr()] on an enum? #33432

Closed
raphaelcohn opened this issue May 5, 2016 · 2 comments
Closed

Why can I not use a type alias in #[repr()] on an enum? #33432

raphaelcohn opened this issue May 5, 2016 · 2 comments

Comments

@raphaelcohn
Copy link

I'd like to use a type alias, in this case c_int, as the repr of an enum. For example, in this code snippet:-

extern crate libc;
use self::libc::c_int;

#[repr(c_int)]
pub enum Facility
{
    LOG_KERN = self::libc::LOG_KERN,
    // ... Omitted ...
}

(Note, LOG_KERN is not yet defined in libc, but I'm working on a PR for it). The type alias for LOG_KERN is c_int, which resolves to i32 on Mac OS X.

Whilst I can use a repr of i32, I'd rather not. Whilst in this particular case it's very highly unlikely that the definition of c_int will every change or vary across platforms (16-bit rust, anyone), one loses expressiveness and introduces a little more need to understand what's going on - limiting the usefulness of a type alias...

I've raised this as an issue, not a RFC or anything like that (a) because I'm new to all of this and (b) because what I just did was what I thought would be logical - it's the very first time I tried to use repr, and it didn't work as seemed obvious. Obviously if there's a better forum I'll move this.

@steveklabnik
Copy link
Member

(a) because I'm new to all of this

Welcome!

Obviously if there's a better forum I'll move this.

So, in general, question-type things are best posted to https://users.rust-lang.org/ or http://internals.rust-lang.org/ , I would say this leans more internals. We try to keep the bug tracker for bugs only.

However, as it just so happens, an RFC was opened a few days ago for this exact issue, so I'd suggest you get involved over there!

Thanks :)

@raphaelcohn
Copy link
Author

Thank you. I'll get on to the RFC...

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

2 participants