mozilla/rust — pull request #13271 by stepancheg (2014-04-03 01:25:30+00:00)
Title: Make constant of enum type properly aligned

This patch fixes issue #13186.

Previously, function `middle::trans::trans_const` result for expression:

```
Aaa
```

from enum:

```
enum Eee {
Aaa,
Bbb(u64)
}
```

was unaligned:

```
{ i8 0, [7 x i8] undef }
```

With patch applied, aligner is added to the result:

```
{ i8 0, [7 x i8] undef, [0 x i64] zeroinitializer }
```

Currently, aligner is an integer of alignment size. Technically speaking
it is incorrect. Probably, beffer aligner would be empty struct with
zero-length arrays for all enum variants. For instance, for enum

```
enum Foo {
Bar(int),
Baz(bool),
Qux(Quux),
}
```

correct aligner could be

```
struct FooAligner {
bar_aligner: [int, 0],
baz_aligner: [bool, 0],
qux_aligner: [Quux, 0],
}
```

Note, that unlike unions in C, enum members in Rust may have different
offsets, because they have different alignments. This should probably be
fixed one day (by inserting aligner before value and padding, not after),
but it requires much larger patch.