Skip to content

Commit 8626c3f

Browse files
committed
---
yaml --- r: 41700 b: refs/heads/master c: 4526424 h: refs/heads/master v: v3
1 parent 6829f26 commit 8626c3f

File tree

3 files changed

+28
-25
lines changed

3 files changed

+28
-25
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: f38e9724e6fbc99668b523f30c7e6ca25c20645b
2+
refs/heads/master: 452642422dda045b89cbcb2b7d011c85c5202d5d
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 2f46b763da2c098913884f101b6d71d69af41b49
55
refs/heads/try: 3d5418789064fdb463e872a4e651af1c628a3650

trunk/src/librustc/middle/trans/base.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -779,6 +779,30 @@ fn trans_external_path(ccx: @crate_ctxt, did: ast::def_id, t: ty::t)
779779
};
780780
}
781781
782+
fn get_discrim_val(cx: @crate_ctxt, span: span, enum_did: ast::def_id,
783+
variant_did: ast::def_id) -> ValueRef {
784+
// Can't use `discrims` from the crate context here because
785+
// those discriminants have an extra level of indirection,
786+
// and there's no LLVM constant load instruction.
787+
let mut lldiscrim_opt = None;
788+
for ty::enum_variants(cx.tcx, enum_did).each |variant_info| {
789+
if variant_info.id == variant_did {
790+
lldiscrim_opt = Some(C_int(cx,
791+
variant_info.disr_val));
792+
break;
793+
}
794+
}
795+
796+
match lldiscrim_opt {
797+
None => {
798+
cx.tcx.sess.span_bug(span, ~"didn't find discriminant?!");
799+
}
800+
Some(found_lldiscrim) => {
801+
found_lldiscrim
802+
}
803+
}
804+
}
805+
782806
fn lookup_discriminant(ccx: @crate_ctxt, vid: ast::def_id) -> ValueRef {
783807
unsafe {
784808
let _icx = ccx.insn_ctxt("lookup_discriminant");

trunk/src/librustc/middle/trans/consts.rs

Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -416,31 +416,10 @@ fn const_expr(cx: @crate_ctxt, e: @ast::expr) -> ValueRef {
416416
// variants.
417417
let ety = ty::expr_ty(cx.tcx, e);
418418
let llty = type_of::type_of(cx, ety);
419+
let lldiscrim = base::get_discrim_val(cx, e.span,
420+
enum_did,
421+
variant_did);
419422

420-
// Can't use `discrims` from the crate context here
421-
// because those discriminants have an extra level of
422-
// indirection, and there's no LLVM constant load
423-
// instruction.
424-
let mut lldiscrim_opt = None;
425-
for ty::enum_variants(cx.tcx, enum_did).each
426-
|variant_info| {
427-
if variant_info.id == variant_did {
428-
lldiscrim_opt = Some(C_int(cx,
429-
variant_info.disr_val));
430-
break;
431-
}
432-
}
433-
434-
let lldiscrim;
435-
match lldiscrim_opt {
436-
None => {
437-
cx.tcx.sess.span_bug(e.span,
438-
~"didn't find discriminant?!");
439-
}
440-
Some(found_lldiscrim) => {
441-
lldiscrim = found_lldiscrim;
442-
}
443-
}
444423
let fields = if ty::enum_is_univariant(cx.tcx, enum_did) {
445424
~[lldiscrim]
446425
} else {

0 commit comments

Comments
 (0)