@@ -3549,13 +3549,12 @@ fn trans_pat_binding(@block_ctxt cx, @ast.pat pat, ValueRef llval)
3549
3549
}
3550
3550
}
3551
3551
3552
- fn trans_alt( @block_ctxt cx, @ast. expr expr, vec [ ast . arm ] arms )
3553
- -> result {
3552
+ fn trans_alt( @block_ctxt cx, @ast. expr expr,
3553
+ vec [ ast . arm ] arms , ast . ann ann ) -> result {
3554
3554
auto expr_res = trans_expr( cx, expr) ;
3555
3555
3556
- auto last_cx = new_sub_block_ctxt( expr_res. bcx, "last") ;
3557
-
3558
3556
auto this_cx = expr_res. bcx;
3557
+ let vec[ result] arm_results = vec( ) ;
3559
3558
for ( ast. arm arm in arms) {
3560
3559
auto next_cx = new_sub_block_ctxt( expr_res. bcx, "next") ;
3561
3560
auto match_res = trans_pat_match( this_cx, arm. pat, expr_res. val,
@@ -3568,9 +3567,7 @@ fn trans_alt(@block_ctxt cx, @ast.expr expr, vec[ast.arm] arms)
3568
3567
expr_res. val) ;
3569
3568
3570
3569
auto block_res = trans_block( binding_res. bcx, arm. block) ;
3571
- if ( !is_terminated( block_res. bcx) ) {
3572
- block_res. bcx. build. Br ( last_cx. llbb) ;
3573
- }
3570
+ arm_results += vec( block_res) ;
3574
3571
3575
3572
this_cx = next_cx;
3576
3573
}
@@ -3579,9 +3576,18 @@ fn trans_alt(@block_ctxt cx, @ast.expr expr, vec[ast.arm] arms)
3579
3576
auto default_res = trans_fail( default_cx, expr. span,
3580
3577
"non-exhaustive match failure") ;
3581
3578
3582
- // FIXME: This is very wrong; we should phi together all the arm blocks,
3583
- // since this is an expression.
3584
- ret res( last_cx, C_nil ( ) ) ;
3579
+ auto expr_ty = ty. ann_to_type( ann) ;
3580
+ auto expr_llty;
3581
+ if ( ty. type_has_dynamic_size( expr_ty) ) {
3582
+ expr_llty = T_typaram_ptr ( cx. fcx. ccx. tn) ;
3583
+ } else {
3584
+ expr_llty = type_of( cx. fcx. ccx, expr_ty) ;
3585
+ if ( ty. type_is_structural( expr_ty) ) {
3586
+ expr_llty = T_ptr ( expr_llty) ;
3587
+ }
3588
+ }
3589
+
3590
+ ret join_results( cx, expr_llty, arm_results) ;
3585
3591
}
3586
3592
3587
3593
type generic_info = rec( @ty. t item_type,
@@ -4703,8 +4709,8 @@ fn trans_expr(@block_ctxt cx, @ast.expr e) -> result {
4703
4709
ret trans_do_while( cx, body, cond) ;
4704
4710
}
4705
4711
4706
- case ( ast. expr_alt( ?expr, ?arms, _ ) ) {
4707
- ret trans_alt( cx, expr, arms) ;
4712
+ case ( ast. expr_alt( ?expr, ?arms, ?ann ) ) {
4713
+ ret trans_alt( cx, expr, arms, ann ) ;
4708
4714
}
4709
4715
4710
4716
case ( ast. expr_block( ?blk, _) ) {
0 commit comments