@@ -588,18 +588,22 @@ impl Context {
588
588
// foo(bar(&1))
589
589
// the lifetime of `1` doesn't outlast the call to `bar`, so it's not
590
590
// vald for the call to `foo`. To work around this all arguments to the
591
- // fmt! string are shoved into locals.
591
+ // fmt! string are shoved into locals. Furthermore, we shove the address
592
+ // of each variable because we don't want to move out of the arguments
593
+ // passed to this function.
592
594
for ( i, & e) in self . args . iter ( ) . enumerate ( ) {
593
595
if self . arg_types [ i] . is_none ( ) { loop } // error already generated
594
596
595
597
let name = self . ecx . ident_of ( fmt ! ( "__arg%u" , i) ) ;
598
+ let e = self . ecx . expr_addr_of ( e. span , e) ;
596
599
lets. push ( self . ecx . stmt_let ( e. span , false , name, e) ) ;
597
600
locals. push ( self . format_arg ( e. span , Left ( i) , name) ) ;
598
601
}
599
602
for ( & name, & e) in self . names . iter ( ) {
600
603
if !self . name_types . contains_key ( & name) { loop }
601
604
602
605
let lname = self . ecx . ident_of ( fmt ! ( "__arg%s" , name) ) ;
606
+ let e = self . ecx . expr_addr_of ( e. span , e) ;
603
607
lets. push ( self . ecx . stmt_let ( e. span , false , lname, e) ) ;
604
608
names[ * self . name_positions . get ( & name) ] =
605
609
Some ( self . format_arg ( e. span , Right ( name) , lname) ) ;
@@ -643,7 +647,7 @@ impl Context {
643
647
Right ( s) => * self . name_types . get ( & s)
644
648
} ;
645
649
646
- let argptr = self . ecx . expr_addr_of ( sp , self . ecx . expr_ident ( sp, ident) ) ;
650
+ let argptr = self . ecx . expr_ident ( sp, ident) ;
647
651
let fmt_trait = match ty {
648
652
Unknown => "Default" ,
649
653
Known ( tyname) => {
0 commit comments