@@ -3562,7 +3562,9 @@ impl<'c> Translation<'c> {
35623562                    CastKind :: BitCast  | CastKind :: PointerToIntegral  | CastKind :: NoOp  => { 
35633563                        ctx. decay_ref  = DecayRef :: Yes 
35643564                    } 
3565-                     CastKind :: FunctionToPointerDecay  | CastKind :: BuiltinFnToFnPtr  => { 
3565+                     CastKind :: ArrayToPointerDecay 
3566+                     | CastKind :: FunctionToPointerDecay 
3567+                     | CastKind :: BuiltinFnToFnPtr  => { 
35663568                        ctx. needs_address  = true ; 
35673569                    } 
35683570                    _ => { } 
@@ -4070,7 +4072,41 @@ impl<'c> Translation<'c> {
40704072
40714073            Paren ( _,  val)  => self . convert_expr ( ctx,  val,  override_ty) , 
40724074
4073-             CompoundLiteral ( _,  val)  => self . convert_expr ( ctx,  val,  override_ty) , 
4075+             CompoundLiteral ( qty,  val)  => { 
4076+                 let  val = self . convert_expr ( ctx,  val,  override_ty) ?; 
4077+ 
4078+                 if  !ctx. needs_address ( )  || ctx. is_static  || ctx. is_const  { 
4079+                     // Statics and consts have their intermediates' lifetimes extended. 
4080+                     return  Ok ( val) ; 
4081+                 } 
4082+ 
4083+                 // C compound literals are lvalues, but equivalent Rust expressions generally are not. 
4084+                 // So if an address is needed, store it in an intermediate variable first. 
4085+                 let  fresh_name = self . renamer . borrow_mut ( ) . fresh ( ) ; 
4086+                 let  fresh_ty = self . convert_type ( override_ty. unwrap_or ( qty) . ctype ) ?; 
4087+ 
4088+                 val. and_then ( |val| { 
4089+                     let  fresh_stmt = { 
4090+                         let  mutbl = if  qty. qualifiers . is_const  { 
4091+                             Mutability :: Immutable 
4092+                         }  else  { 
4093+                             Mutability :: Mutable 
4094+                         } ; 
4095+ 
4096+                         let  local = mk ( ) . local ( 
4097+                             mk ( ) . set_mutbl ( mutbl) . ident_pat ( & fresh_name) , 
4098+                             Some ( fresh_ty) , 
4099+                             Some ( val) , 
4100+                         ) ; 
4101+                         mk ( ) . local_stmt ( Box :: new ( local) ) 
4102+                     } ; 
4103+ 
4104+                     Ok ( WithStmts :: new ( 
4105+                         vec ! [ fresh_stmt] , 
4106+                         mk ( ) . ident_expr ( fresh_name) , 
4107+                     ) ) 
4108+                 } ) 
4109+             } 
40744110
40754111            InitList ( ty,  ref  ids,  opt_union_field_id,  _)  => { 
40764112                self . convert_init_list ( ctx,  ty,  ids,  opt_union_field_id) 
0 commit comments