@@ -760,16 +760,11 @@ impl<'a, 'b> Context<'a, 'b> {
760
760
/// Actually builds the expression which the format_args! block will be
761
761
/// expanded to.
762
762
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
+ ) ;
767
766
let mut heads = Vec :: with_capacity ( self . args . len ( ) ) ;
768
767
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
-
773
768
// First, build up the static array which will become our precompiled
774
769
// format "string"
775
770
let pieces = self . ecx . expr_vec_slice ( self . fmtsp , self . str_pieces ) ;
@@ -787,11 +782,8 @@ impl<'a, 'b> Context<'a, 'b> {
787
782
// of each variable because we don't want to move out of the arguments
788
783
// passed to this function.
789
784
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) ) ;
793
785
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 ) ) ;
795
787
}
796
788
heads. push ( self . ecx . expr_addr_of ( e. span , e) ) ;
797
789
}
@@ -800,15 +792,11 @@ impl<'a, 'b> Context<'a, 'b> {
800
792
Exact ( i) => i,
801
793
_ => panic ! ( "should never happen" ) ,
802
794
} ;
803
- let name = names_pos[ index] ;
804
795
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 ) ) ;
806
797
}
807
798
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) ;
812
800
813
801
// Constructs an AST equivalent to:
814
802
//
@@ -838,7 +826,7 @@ impl<'a, 'b> Context<'a, 'b> {
838
826
// But the nested match expression is proved to perform not as well
839
827
// as series of let's; the first approach does.
840
828
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 ) ) ;
842
830
let arm = self . ecx . arm ( self . macsp , pat, args_array) ;
843
831
let head = self . ecx . expr ( self . macsp , ast:: ExprKind :: Tup ( heads) ) ;
844
832
self . ecx . expr_match ( self . macsp , head, vec ! [ arm] )
@@ -877,10 +865,11 @@ impl<'a, 'b> Context<'a, 'b> {
877
865
macsp : Span ,
878
866
mut sp : Span ,
879
867
ty : & ArgumentType ,
880
- arg : Ident ,
868
+ arg_index : usize ,
881
869
) -> P < ast:: Expr > {
882
870
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) ) ) ;
884
873
let trait_ = match * ty {
885
874
Placeholder ( trait_) if trait_ == "<invalid>" => return DummyResult :: raw_expr ( sp, true ) ,
886
875
Placeholder ( trait_) => trait_,
0 commit comments