Lokasi ngalangkungan proxy:   [ UP ]  
[Ngawartoskeun bug]   [Panyetelan cookie]                
Skip to content

Can't implement Copy for C style enums with negative discriminants that overflow into unspecified positive discriminants #23221

Closed

Description

@mahkoh
fn main() { }

#[repr(C)]
#[derive(Copy)]
enum X {
    A = -1,
    B,
}
test5.rs:7:5: 7:6 error: Discriminant overflowed!
test5.rs:7     B,
               ^

Activity

  1. huonw commented on Mar 9, 2015

    @huonw
    Contributor

    Providing an explicit discriminant for the variant after the -1 works as a workaround:

    fn main() { }
    
    #[repr(C)]
    #[derive(Copy)]
    enum X {
        A = -1,
        B = 0,
    }
  2. mahkoh commented on Mar 9, 2015

    @mahkoh
    ContributorAuthor

    The same happens without repr(C) or with repr(i32).

  3. pnkfelix commented on Mar 9, 2015

    @pnkfelix
    Contributor

    Also, -2 will work. I'll update the title.

  4. changed the title [-]Can't implement Copy for C style enums with negative discriminants[/-] [+]Can't implement Copy for C style enums with discriminant of -1[/+] on Mar 9, 2015
  5. mahkoh commented on Mar 9, 2015

    @mahkoh
    ContributorAuthor

    @pnkfelix: The error message shows that it's about overflowing discriminants. There is nothing special about -1.

  6. pnkfelix commented on Mar 9, 2015

    @pnkfelix
    Contributor

    @mahkoh my point is that the bug is not observed by all negative discriminants. But whatever, I'm not interested in fighting over how the title is phrased.

  7. mahkoh commented on Mar 9, 2015

    @mahkoh
    ContributorAuthor

    In any case the previous title was wrong because this works fine:

    fn main() { }
    
    //#[repr(C)]
    enum _X {
        A = -1,
    }
    
    impl Copy for _X { }
  8. shepmaster commented on Mar 9, 2015

    @shepmaster
    Member

    @pnkfelix I think that @mahkoh's point was that this usage of -2 does fail:

    fn main() { }
    
    #[derive(Copy)]
    enum X {
        A = -2,
        B,
        C,
    }
  9. pnkfelix commented on Mar 31, 2015

    @pnkfelix
    Contributor
  10. added a commit that references this issue on Apr 1, 2015
    4f643d7
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

    A-FFIA-type-system

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions