@@ -3,8 +3,8 @@ use Position::*;
33
44use rustc_ast as ast;
55use rustc_ast:: ptr:: P ;
6- use rustc_ast:: token;
76use rustc_ast:: tokenstream:: TokenStream ;
7+ use rustc_ast:: { token, BlockCheckMode , UnsafeSource } ;
88use rustc_data_structures:: fx:: { FxHashMap , FxHashSet } ;
99use rustc_errors:: { pluralize, Applicability , DiagnosticBuilder } ;
1010use rustc_expand:: base:: { self , * } ;
@@ -838,12 +838,15 @@ impl<'a, 'b> Context<'a, 'b> {
838838 //
839839 // But the nested match expression is proved to perform not as well
840840 // as series of let's; the first approach does.
841- let pat = self . ecx . pat_tuple ( self . macsp , pats) ;
842- let arm = self . ecx . arm ( self . macsp , pat, args_array) ;
843- let head = self . ecx . expr ( self . macsp , ast:: ExprKind :: Tup ( heads) ) ;
844- let result = self . ecx . expr_match ( self . macsp , head, vec ! [ arm] ) ;
841+ let args_match = {
842+ let pat = self . ecx . pat_tuple ( self . macsp , pats) ;
843+ let arm = self . ecx . arm ( self . macsp , pat, args_array) ;
844+ let head = self . ecx . expr ( self . macsp , ast:: ExprKind :: Tup ( heads) ) ;
845+ self . ecx . expr_match ( self . macsp , head, vec ! [ arm] )
846+ } ;
845847
846- let args_slice = self . ecx . expr_addr_of ( self . macsp , result) ;
848+ let ident = Ident :: from_str_and_span ( "args" , self . macsp ) ;
849+ let args_slice = self . ecx . expr_ident ( self . macsp , ident) ;
847850
848851 // Now create the fmt::Arguments struct with all our locals we created.
849852 let ( fn_name, fn_args) = if self . all_pieces_simple {
@@ -857,7 +860,20 @@ impl<'a, 'b> Context<'a, 'b> {
857860 } ;
858861
859862 let path = self . ecx . std_path ( & [ sym:: fmt, sym:: Arguments , Symbol :: intern ( fn_name) ] ) ;
860- self . ecx . expr_call_global ( self . macsp , path, fn_args)
863+ let arguments = self . ecx . expr_call_global ( self . macsp , path, fn_args) ;
864+ let body = self . ecx . expr_block ( P ( ast:: Block {
865+ stmts : vec ! [ self . ecx. stmt_expr( arguments) ] ,
866+ id : ast:: DUMMY_NODE_ID ,
867+ rules : BlockCheckMode :: Unsafe ( UnsafeSource :: CompilerGenerated ) ,
868+ span : self . macsp ,
869+ tokens : None ,
870+ } ) ) ;
871+
872+ let ident = Ident :: from_str_and_span ( "args" , self . macsp ) ;
873+ let binding_mode = ast:: BindingMode :: ByRef ( ast:: Mutability :: Not ) ;
874+ let pat = self . ecx . pat_ident_binding_mode ( self . macsp , ident, binding_mode) ;
875+ let arm = self . ecx . arm ( self . macsp , pat, body) ;
876+ self . ecx . expr_match ( self . macsp , args_match, vec ! [ arm] )
861877 }
862878
863879 fn format_arg (
0 commit comments