Skip to content

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

@raphaelcohn

Description

@raphaelcohn

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.

Activity

steveklabnik

steveklabnik commented on May 5, 2016

@steveklabnik
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

raphaelcohn commented on May 5, 2016

@raphaelcohn
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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @steveklabnik@raphaelcohn

        Issue actions

          Why can I not use a type alias in #[repr()] on an enum? · Issue #33432 · rust-lang/rust