Change adt case handling fn to be less tied to match

This commit is contained in:
Niko Matsakis 2015-10-21 17:33:08 -04:00
parent 0a62158a4e
commit 81ff2c2f8e
3 changed files with 7 additions and 14 deletions
src/librustc_trans/trans

@ -303,7 +303,7 @@ impl<'a, 'tcx> Opt<'a, 'tcx> {
RangeResult(Result::new(bcx, l1), Result::new(bcx, l2))
}
Variant(disr_val, ref repr, _, _) => {
adt::trans_case(bcx, &**repr, disr_val)
SingleResult(Result::new(bcx, adt::trans_case(bcx, &**repr, disr_val)))
}
SliceLengthEqual(length, _) => {
SingleResult(Result::new(bcx, C_uint(ccx, length)))

@ -945,15 +945,13 @@ fn load_discr(bcx: Block, ity: IntType, ptr: ValueRef, min: Disr, max: Disr)
///
/// This should ideally be less tightly tied to `_match`.
pub fn trans_case<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, r: &Repr, discr: Disr)
-> _match::OptResult<'blk, 'tcx> {
-> ValueRef {
match *r {
CEnum(ity, _, _) => {
_match::SingleResult(Result::new(bcx, C_integral(ll_inttype(bcx.ccx(), ity),
discr as u64, true)))
C_integral(ll_inttype(bcx.ccx(), ity), discr as u64, true)
}
General(ity, _, _) => {
_match::SingleResult(Result::new(bcx, C_integral(ll_inttype(bcx.ccx(), ity),
discr as u64, true)))
C_integral(ll_inttype(bcx.ccx(), ity), discr as u64, true)
}
Univariant(..) => {
bcx.ccx().sess().bug("no cases for univariants or structs")
@ -961,7 +959,7 @@ pub fn trans_case<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, r: &Repr, discr: Disr)
RawNullablePointer { .. } |
StructWrappedNullablePointer { .. } => {
assert!(discr == 0 || discr == 1);
_match::SingleResult(Result::new(bcx, C_bool(bcx.ccx(), discr != 0)))
C_bool(bcx.ccx(), discr != 0)
}
}
}

@ -498,13 +498,8 @@ pub fn iter_structural_ty<'blk, 'tcx, F>(cx: Block<'blk, 'tcx>,
&format!("enum-iter-variant-{}",
&variant.disr_val.to_string())
);
match adt::trans_case(cx, &*repr, variant.disr_val) {
_match::SingleResult(r) => {
AddCase(llswitch, r.val, variant_cx.llbb)
}
_ => ccx.sess().unimpl("value from adt::trans_case \
in iter_structural_ty")
}
let case_val = adt::trans_case(cx, &*repr, variant.disr_val);
AddCase(llswitch, case_val, variant_cx.llbb);
let variant_cx =
iter_variant(variant_cx,
&*repr,