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 #31886.
  • Loading branch information
durka committed Mar 18, 2016
1 parent 235d774 commit ee4b607
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/libsyntax_ext/deriving/generic/mod.rs
Expand Up @@ -758,7 +758,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
10 changes: 10 additions & 0 deletions src/test/run-pass/enum-discrim-autosizing.rs
Expand Up @@ -47,6 +47,12 @@ enum Ei64 {
Bi64 = 0x8000_0000
}

#[derive(PartialEq)]
enum Eu64 {
Au64 = 0,
Bu64 = 0x8000_0000_0000_0000
}

pub fn main() {
assert_eq!(size_of::<Ei8>(), 1);
assert_eq!(size_of::<Eu8>(), 1);
Expand All @@ -58,4 +64,8 @@ pub fn main() {
assert_eq!(size_of::<Ei64>(), 8);
#[cfg(target_pointer_width = "32")]
assert_eq!(size_of::<Ei64>(), 4);
assert_eq!(size_of::<Eu64>(), 8);

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

0 comments on commit ee4b607

Please sign in to comment.