@@ -3379,9 +3379,10 @@ impl<'c> Translation<'c> {
33793379 }
33803380
33813381 BinaryConditional ( ty, lhs, rhs) => {
3382+ let rhs = self . convert_expr ( ctx, rhs, None ) ?;
3383+
33823384 if ctx. is_unused ( ) {
33833385 let mut lhs = self . convert_condition ( ctx, false , lhs) ?;
3384- let rhs = self . convert_expr ( ctx, rhs, None ) ?;
33853386 lhs. merge_unsafe ( rhs. is_unsafe ( ) ) ;
33863387
33873388 lhs. and_then ( |val| {
@@ -3397,19 +3398,27 @@ impl<'c> Translation<'c> {
33973398 ) )
33983399 } )
33993400 } else {
3400- self . name_reference_write_read ( ctx, lhs) ?. result_map (
3401- |NamedReference {
3402- rvalue : lhs_val, ..
3403- } | {
3404- let cond = self . match_bool ( ctx, true , ty. ctype , lhs_val. clone ( ) ) ?;
3405- let ite = mk ( ) . ifte_expr (
3406- cond,
3407- mk ( ) . block ( vec ! [ mk( ) . expr_stmt( lhs_val) ] ) ,
3408- Some ( self . convert_expr ( ctx, rhs, None ) ?. to_expr ( ) ) ,
3409- ) ;
3410- Ok ( ite)
3411- } ,
3412- )
3401+ let mut lhs = self . convert_expr ( ctx. used ( ) , lhs, None ) ?;
3402+ lhs. merge_unsafe ( rhs. is_unsafe ( ) ) ;
3403+ let fresh_name = self . renamer . borrow_mut ( ) . fresh ( ) ;
3404+
3405+ lhs. and_then ( |lhs| {
3406+ let fresh_stmt = mk ( ) . local_stmt ( Box :: new ( mk ( ) . local (
3407+ mk ( ) . ident_pat ( & fresh_name) ,
3408+ None ,
3409+ Some ( lhs) ,
3410+ ) ) ) ;
3411+
3412+ let cond =
3413+ self . match_bool ( ctx, true , ty. ctype , mk ( ) . ident_expr ( & fresh_name) ) ?;
3414+ let ite = mk ( ) . ifte_expr (
3415+ cond,
3416+ mk ( ) . block ( vec ! [ mk( ) . expr_stmt( mk( ) . ident_expr( & fresh_name) ) ] ) ,
3417+ Some ( rhs. to_expr ( ) ) ,
3418+ ) ;
3419+
3420+ Ok ( WithStmts :: new ( vec ! [ fresh_stmt] , ite) )
3421+ } )
34133422 }
34143423 }
34153424
0 commit comments