@@ -410,15 +410,11 @@ fn expand_format_args<'hir>(
410
410
let format_options = use_format_options. then ( || {
411
411
// Generate:
412
412
// &[format_spec_0, format_spec_1, format_spec_2]
413
- let elements: Vec < _ > = fmt
414
- . template
415
- . iter ( )
416
- . filter_map ( |piece| {
417
- let FormatArgsPiece :: Placeholder ( placeholder) = piece else { return None } ;
418
- Some ( make_format_spec ( ctx, macsp, placeholder, & mut argmap) )
419
- } )
420
- . collect ( ) ;
421
- ctx. expr_array_ref ( macsp, ctx. arena . alloc_from_iter ( elements) )
413
+ let elements = ctx. arena . alloc_from_iter ( fmt. template . iter ( ) . filter_map ( |piece| {
414
+ let FormatArgsPiece :: Placeholder ( placeholder) = piece else { return None } ;
415
+ Some ( make_format_spec ( ctx, macsp, placeholder, & mut argmap) )
416
+ } ) ) ;
417
+ ctx. expr_array_ref ( macsp, elements)
422
418
} ) ;
423
419
424
420
let arguments = fmt. arguments . all_args ( ) ;
@@ -477,10 +473,8 @@ fn expand_format_args<'hir>(
477
473
// <core::fmt::Argument>::new_debug(&arg2),
478
474
// …
479
475
// ]
480
- let elements: Vec < _ > = arguments
481
- . iter ( )
482
- . zip ( argmap)
483
- . map ( |( arg, ( ( _, ty) , placeholder_span) ) | {
476
+ let elements = ctx. arena . alloc_from_iter ( arguments. iter ( ) . zip ( argmap) . map (
477
+ |( arg, ( ( _, ty) , placeholder_span) ) | {
484
478
let placeholder_span =
485
479
placeholder_span. unwrap_or ( arg. expr . span ) . with_ctxt ( macsp. ctxt ( ) ) ;
486
480
let arg_span = match arg. kind {
@@ -493,9 +487,9 @@ fn expand_format_args<'hir>(
493
487
hir:: ExprKind :: AddrOf ( hir:: BorrowKind :: Ref , hir:: Mutability :: Not , arg) ,
494
488
) ) ;
495
489
make_argument ( ctx, placeholder_span, ref_arg, ty)
496
- } )
497
- . collect ( ) ;
498
- ctx. expr_array_ref ( macsp, ctx . arena . alloc_from_iter ( elements) )
490
+ } ,
491
+ ) ) ;
492
+ ctx. expr_array_ref ( macsp, elements)
499
493
} else {
500
494
// Generate:
501
495
// &match (&arg0, &arg1, &…) {
@@ -528,19 +522,14 @@ fn expand_format_args<'hir>(
528
522
make_argument ( ctx, placeholder_span, arg, ty)
529
523
} ,
530
524
) ) ;
531
- let elements: Vec < _ > = arguments
532
- . iter ( )
533
- . map ( |arg| {
534
- let arg_expr = ctx. lower_expr ( & arg. expr ) ;
535
- ctx. expr (
536
- arg. expr . span . with_ctxt ( macsp. ctxt ( ) ) ,
537
- hir:: ExprKind :: AddrOf ( hir:: BorrowKind :: Ref , hir:: Mutability :: Not , arg_expr) ,
538
- )
539
- } )
540
- . collect ( ) ;
541
- let args_tuple = ctx
542
- . arena
543
- . alloc ( ctx. expr ( macsp, hir:: ExprKind :: Tup ( ctx. arena . alloc_from_iter ( elements) ) ) ) ;
525
+ let elements = ctx. arena . alloc_from_iter ( arguments. iter ( ) . map ( |arg| {
526
+ let arg_expr = ctx. lower_expr ( & arg. expr ) ;
527
+ ctx. expr (
528
+ arg. expr . span . with_ctxt ( macsp. ctxt ( ) ) ,
529
+ hir:: ExprKind :: AddrOf ( hir:: BorrowKind :: Ref , hir:: Mutability :: Not , arg_expr) ,
530
+ )
531
+ } ) ) ;
532
+ let args_tuple = ctx. arena . alloc ( ctx. expr ( macsp, hir:: ExprKind :: Tup ( elements) ) ) ;
544
533
let array = ctx. arena . alloc ( ctx. expr ( macsp, hir:: ExprKind :: Array ( args) ) ) ;
545
534
let match_arms = ctx. arena . alloc_from_iter ( [ ctx. arm ( args_pat, array) ] ) ;
546
535
let match_expr = ctx. arena . alloc ( ctx. expr_match (
0 commit comments