Skip to content

Commit 6bb6bab

Browse files
committed
Renovate cast-to-int
1 parent 075affa commit 6bb6bab

File tree

1 file changed

+2
-16
lines changed

1 file changed

+2
-16
lines changed

src/librustc/middle/trans/expr.rs

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1644,22 +1644,8 @@ fn trans_imm_cast(bcx: block, expr: @ast::expr,
16441644
(cast_enum, cast_integral) |
16451645
(cast_enum, cast_float) => {
16461646
let bcx = bcx;
1647-
let in_tid = match ty::get(t_in).sty {
1648-
ty::ty_enum(did, _) => did,
1649-
_ => ccx.sess.bug(~"enum cast source is not enum")
1650-
};
1651-
let variants = ty::enum_variants(ccx.tcx, in_tid);
1652-
let lldiscrim_a = if variants.len() == 1 {
1653-
// Univariants don't have a discriminant field,
1654-
// because there's only one value it could have:
1655-
C_integral(T_enum_discrim(ccx),
1656-
variants[0].disr_val as u64, True)
1657-
} else {
1658-
let llenumty = T_opaque_enum_ptr(ccx);
1659-
let av_enum = PointerCast(bcx, llexpr, llenumty);
1660-
let lldiscrim_a_ptr = GEPi(bcx, av_enum, [0u, 0u]);
1661-
Load(bcx, lldiscrim_a_ptr)
1662-
};
1647+
let repr = adt::represent_type(ccx, t_in);
1648+
let lldiscrim_a = adt::trans_cast_to_int(bcx, &repr, llexpr);
16631649
match k_out {
16641650
cast_integral => int_cast(bcx, ll_t_out,
16651651
val_ty(lldiscrim_a),

0 commit comments

Comments
 (0)