Skip to content

Commit

Permalink
derive: assume enum repr defaults to isize
Browse files Browse the repository at this point in the history
It was originally intended to be i32, but it isn't.

Fixes rust-lang#31886.
  • Loading branch information
durka committed Mar 10, 2016
1 parent 2321994 commit 4c8a933
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/libsyntax_ext/deriving/generic/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -757,7 +757,7 @@ impl<'a> TraitDef<'a> {

fn find_repr_type_name(diagnostic: &Handler,
type_attrs: &[ast::Attribute]) -> &'static str {
let mut repr_type_name = "i32";
let mut repr_type_name = "isize";
for a in type_attrs {
for r in &attr::find_repr_attrs(diagnostic, a) {
repr_type_name = match *r {
Expand Down
4 changes: 4 additions & 0 deletions src/test/run-pass/enum-discrim-autosizing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ enum Ei64 {
Bi64 = 0x8000_0000
}

#[derive(PartialEq)]
enum Eu64 {
Au64 = 0,
Bu64 = 0x8000_0000_0000_0000
Expand All @@ -60,4 +61,7 @@ pub fn main() {
assert_eq!(size_of::<Eu32>(), 4);
assert_eq!(size_of::<Ei64>(), 8);
assert_eq!(size_of::<Eu64>(), 8);

// ensure no i32 collisions
assert!(Eu64::Au64 != Eu64::Bu64);
}

0 comments on commit 4c8a933

Please sign in to comment.