Skip to content

Commit c2a19b9

Browse files
committed
---
yaml --- r: 34535 b: refs/heads/snap-stage3 c: abae612 h: refs/heads/master i: 34533: 13d5666 34531: 9eeef7b 34527: 6b6afa1 v: v3
1 parent a1358fb commit c2a19b9

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
refs/heads/master: cd6f24f9d14ac90d167386a56e7a6ac1f0318195
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
4-
refs/heads/snap-stage3: f76e28aa1c093c59671749006e1a7ae203d66b7c
4+
refs/heads/snap-stage3: abae61257c4d866bb321bfb80ad16b7531736f7e
55
refs/heads/try: d324a424d8f84b1eb049b12cf34182bda91b0024
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b

branches/snap-stage3/src/librustc/middle/check_const.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,11 +138,12 @@ fn check_expr(sess: Session, def_map: resolve::DefMap,
138138
expr_call(callee, _, false) => {
139139
match def_map.find(callee.id) {
140140
Some(def_struct(*)) => {} // OK.
141+
Some(def_variant(*)) => {} // OK.
141142
_ => {
142143
sess.span_err(
143144
e.span,
144145
~"function calls in constants are limited to \
145-
structure constructors");
146+
struct and enum constructors");
146147
}
147148
}
148149
}

branches/snap-stage3/src/librustc/middle/trans/consts.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,24 @@ fn const_expr(cx: @crate_ctxt, e: @ast::expr) -> ValueRef {
454454
C_named_struct(llty, ~[ llstructbody ])
455455
}
456456
}
457+
Some(ast::def_variant(tid, vid)) => {
458+
let ety = ty::expr_ty(cx.tcx, e);
459+
let degen = ty::enum_is_univariant(cx.tcx, tid);
460+
let size = shape::static_size_of_enum(cx, ety);
461+
462+
let discrim = base::get_discrim_val(cx, e.span, tid, vid);
463+
let c_args = C_struct(args.map(|a| const_expr(cx, *a)));
464+
465+
let fields = if !degen {
466+
~[discrim, c_args]
467+
} else if size == 0 {
468+
~[discrim]
469+
} else {
470+
~[c_args]
471+
};
472+
473+
C_struct(fields)
474+
}
457475
_ => cx.sess.span_bug(e.span, ~"expected a struct def")
458476
}
459477
}

0 commit comments

Comments
 (0)