Skip to content

Commit ee4b607

Browse files
committed
derive: assume enum repr defaults to isize
It was originally intended to be i32, but it isn't. Fixes #31886.
1 parent 235d774 commit ee4b607

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

src/libsyntax_ext/deriving/generic/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -758,7 +758,7 @@ impl<'a> TraitDef<'a> {
758758

759759
fn find_repr_type_name(diagnostic: &Handler,
760760
type_attrs: &[ast::Attribute]) -> &'static str {
761-
let mut repr_type_name = "i32";
761+
let mut repr_type_name = "isize";
762762
for a in type_attrs {
763763
for r in &attr::find_repr_attrs(diagnostic, a) {
764764
repr_type_name = match *r {

src/test/run-pass/enum-discrim-autosizing.rs

+10
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,12 @@ enum Ei64 {
4747
Bi64 = 0x8000_0000
4848
}
4949

50+
#[derive(PartialEq)]
51+
enum Eu64 {
52+
Au64 = 0,
53+
Bu64 = 0x8000_0000_0000_0000
54+
}
55+
5056
pub fn main() {
5157
assert_eq!(size_of::<Ei8>(), 1);
5258
assert_eq!(size_of::<Eu8>(), 1);
@@ -58,4 +64,8 @@ pub fn main() {
5864
assert_eq!(size_of::<Ei64>(), 8);
5965
#[cfg(target_pointer_width = "32")]
6066
assert_eq!(size_of::<Ei64>(), 4);
67+
assert_eq!(size_of::<Eu64>(), 8);
68+
69+
// ensure no i32 collisions
70+
assert!(Eu64::Au64 != Eu64::Bu64);
6171
}

0 commit comments

Comments
 (0)