Skip to content

Commit 6cdc283

Browse files
committed
Also need to pad out "C-like" enum consts (paths as well as calls).
1 parent 877fc8d commit 6cdc283

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

src/librustc/middle/trans/consts.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,13 @@ pub fn const_expr(cx: @crate_ctxt, e: @ast::expr) -> ValueRef {
434434
let lldiscrim = base::get_discrim_val(cx, e.span,
435435
enum_did,
436436
variant_did);
437-
C_struct(~[lldiscrim])
437+
// However, we still have to pad it out to the
438+
// size of the full enum; see the expr_call case,
439+
// below.
440+
let ety = ty::expr_ty(cx.tcx, e);
441+
let size = machine::static_size_of_enum(cx, ety);
442+
let padding = C_null(T_array(T_i8(), size));
443+
C_struct(~[lldiscrim, padding])
438444
}
439445
Some(ast::def_struct(_)) => {
440446
let ety = ty::expr_ty(cx.tcx, e);
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
enum E { V0, V16(u16) }
12+
const C: (E, u16, u16) = (V0, 0x600D, 0xBAD);
13+
14+
fn main() {
15+
let (_, n, _) = C;
16+
assert n != 0xBAD;
17+
assert n == 0x600D;
18+
}

0 commit comments

Comments
 (0)