@@ -760,16 +760,11 @@ impl<'a, 'b> Context<'a, 'b> {
760760 /// Actually builds the expression which the format_args! block will be
761761 /// expanded to.
762762 fn into_expr ( self ) -> P < ast:: Expr > {
763- let mut locals =
764- Vec :: with_capacity ( ( 0 ..self . args . len ( ) ) . map ( |i| self . arg_unique_types [ i] . len ( ) ) . sum ( ) ) ;
765- let mut counts = Vec :: with_capacity ( self . count_args . len ( ) ) ;
766- let mut pats = Vec :: with_capacity ( self . args . len ( ) ) ;
763+ let mut args = Vec :: with_capacity (
764+ self . arg_unique_types . iter ( ) . map ( |v| v. len ( ) ) . sum :: < usize > ( ) + self . count_args . len ( ) ,
765+ ) ;
767766 let mut heads = Vec :: with_capacity ( self . args . len ( ) ) ;
768767
769- let names_pos: Vec < _ > = ( 0 ..self . args . len ( ) )
770- . map ( |i| Ident :: from_str_and_span ( & format ! ( "arg{}" , i) , self . macsp ) )
771- . collect ( ) ;
772-
773768 // First, build up the static array which will become our precompiled
774769 // format "string"
775770 let pieces = self . ecx . expr_vec_slice ( self . fmtsp , self . str_pieces ) ;
@@ -787,11 +782,8 @@ impl<'a, 'b> Context<'a, 'b> {
787782 // of each variable because we don't want to move out of the arguments
788783 // passed to this function.
789784 for ( i, e) in self . args . into_iter ( ) . enumerate ( ) {
790- let name = names_pos[ i] ;
791- let span = self . ecx . with_def_site_ctxt ( e. span ) ;
792- pats. push ( self . ecx . pat_ident ( span, name) ) ;
793785 for arg_ty in self . arg_unique_types [ i] . iter ( ) {
794- locals . push ( Context :: format_arg ( self . ecx , self . macsp , e. span , arg_ty, name ) ) ;
786+ args . push ( Context :: format_arg ( self . ecx , self . macsp , e. span , arg_ty, i ) ) ;
795787 }
796788 heads. push ( self . ecx . expr_addr_of ( e. span , e) ) ;
797789 }
@@ -800,15 +792,11 @@ impl<'a, 'b> Context<'a, 'b> {
800792 Exact ( i) => i,
801793 _ => panic ! ( "should never happen" ) ,
802794 } ;
803- let name = names_pos[ index] ;
804795 let span = spans_pos[ index] ;
805- counts . push ( Context :: format_arg ( self . ecx , self . macsp , span, & Count , name ) ) ;
796+ args . push ( Context :: format_arg ( self . ecx , self . macsp , span, & Count , index ) ) ;
806797 }
807798
808- // Now create a vector containing all the arguments
809- let args = locals. into_iter ( ) . chain ( counts. into_iter ( ) ) ;
810-
811- let args_array = self . ecx . expr_vec ( self . macsp , args. collect ( ) ) ;
799+ let args_array = self . ecx . expr_vec ( self . macsp , args) ;
812800
813801 // Constructs an AST equivalent to:
814802 //
@@ -838,7 +826,7 @@ impl<'a, 'b> Context<'a, 'b> {
838826 // But the nested match expression is proved to perform not as well
839827 // as series of let's; the first approach does.
840828 let args_match = {
841- let pat = self . ecx . pat_tuple ( self . macsp , pats ) ;
829+ let pat = self . ecx . pat_ident ( self . macsp , Ident :: new ( sym :: _args , self . macsp ) ) ;
842830 let arm = self . ecx . arm ( self . macsp , pat, args_array) ;
843831 let head = self . ecx . expr ( self . macsp , ast:: ExprKind :: Tup ( heads) ) ;
844832 self . ecx . expr_match ( self . macsp , head, vec ! [ arm] )
@@ -877,10 +865,11 @@ impl<'a, 'b> Context<'a, 'b> {
877865 macsp : Span ,
878866 mut sp : Span ,
879867 ty : & ArgumentType ,
880- arg : Ident ,
868+ arg_index : usize ,
881869 ) -> P < ast:: Expr > {
882870 sp = ecx. with_def_site_ctxt ( sp) ;
883- let arg = ecx. expr_ident ( sp, arg) ;
871+ let arg = ecx. expr_ident ( sp, Ident :: new ( sym:: _args, sp) ) ;
872+ let arg = ecx. expr ( sp, ast:: ExprKind :: Field ( arg, Ident :: new ( sym:: integer ( arg_index) , sp) ) ) ;
884873 let trait_ = match * ty {
885874 Placeholder ( trait_) if trait_ == "<invalid>" => return DummyResult :: raw_expr ( sp, true ) ,
886875 Placeholder ( trait_) => trait_,
0 commit comments