Skip to content

Commit 81ff2c2

Browse files
committed
Change adt case handling fn to be less tied to match
1 parent 0a62158 commit 81ff2c2

File tree

3 files changed

+7
-14
lines changed

3 files changed

+7
-14
lines changed

src/librustc_trans/trans/_match.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ impl<'a, 'tcx> Opt<'a, 'tcx> {
303303
RangeResult(Result::new(bcx, l1), Result::new(bcx, l2))
304304
}
305305
Variant(disr_val, ref repr, _, _) => {
306-
adt::trans_case(bcx, &**repr, disr_val)
306+
SingleResult(Result::new(bcx, adt::trans_case(bcx, &**repr, disr_val)))
307307
}
308308
SliceLengthEqual(length, _) => {
309309
SingleResult(Result::new(bcx, C_uint(ccx, length)))

src/librustc_trans/trans/adt.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -945,23 +945,21 @@ fn load_discr(bcx: Block, ity: IntType, ptr: ValueRef, min: Disr, max: Disr)
945945
///
946946
/// This should ideally be less tightly tied to `_match`.
947947
pub fn trans_case<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, r: &Repr, discr: Disr)
948-
-> _match::OptResult<'blk, 'tcx> {
948+
-> ValueRef {
949949
match *r {
950950
CEnum(ity, _, _) => {
951-
_match::SingleResult(Result::new(bcx, C_integral(ll_inttype(bcx.ccx(), ity),
952-
discr as u64, true)))
951+
C_integral(ll_inttype(bcx.ccx(), ity), discr as u64, true)
953952
}
954953
General(ity, _, _) => {
955-
_match::SingleResult(Result::new(bcx, C_integral(ll_inttype(bcx.ccx(), ity),
956-
discr as u64, true)))
954+
C_integral(ll_inttype(bcx.ccx(), ity), discr as u64, true)
957955
}
958956
Univariant(..) => {
959957
bcx.ccx().sess().bug("no cases for univariants or structs")
960958
}
961959
RawNullablePointer { .. } |
962960
StructWrappedNullablePointer { .. } => {
963961
assert!(discr == 0 || discr == 1);
964-
_match::SingleResult(Result::new(bcx, C_bool(bcx.ccx(), discr != 0)))
962+
C_bool(bcx.ccx(), discr != 0)
965963
}
966964
}
967965
}

src/librustc_trans/trans/base.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -498,13 +498,8 @@ pub fn iter_structural_ty<'blk, 'tcx, F>(cx: Block<'blk, 'tcx>,
498498
&format!("enum-iter-variant-{}",
499499
&variant.disr_val.to_string())
500500
);
501-
match adt::trans_case(cx, &*repr, variant.disr_val) {
502-
_match::SingleResult(r) => {
503-
AddCase(llswitch, r.val, variant_cx.llbb)
504-
}
505-
_ => ccx.sess().unimpl("value from adt::trans_case \
506-
in iter_structural_ty")
507-
}
501+
let case_val = adt::trans_case(cx, &*repr, variant.disr_val);
502+
AddCase(llswitch, case_val, variant_cx.llbb);
508503
let variant_cx =
509504
iter_variant(variant_cx,
510505
&*repr,

0 commit comments

Comments
 (0)