@@ -508,11 +508,8 @@ impl ExprCollector<'_> {
508
508
}
509
509
ast:: Expr :: MacroCall ( e) => {
510
510
let macro_ptr = AstPtr :: new ( & e) ;
511
- let mut id = None ;
512
- self . collect_macro_call ( e, macro_ptr. clone ( ) , true , |this, expansion| {
513
- if let Some ( it) = expansion {
514
- id. get_or_insert ( this. collect_expr ( it) ) ;
515
- }
511
+ let id = self . collect_macro_call ( e, macro_ptr. clone ( ) , true , |this, expansion| {
512
+ expansion. map ( |it| this. collect_expr ( it) )
516
513
} ) ;
517
514
match id {
518
515
Some ( id) => {
@@ -537,13 +534,17 @@ impl ExprCollector<'_> {
537
534
} )
538
535
}
539
536
540
- fn collect_macro_call < F : FnOnce ( & mut Self , Option < T > ) , T : ast :: AstNode > (
537
+ fn collect_macro_call < F , T , U > (
541
538
& mut self ,
542
539
mcall : ast:: MacroCall ,
543
540
syntax_ptr : AstPtr < ast:: MacroCall > ,
544
541
record_diagnostics : bool ,
545
542
collector : F ,
546
- ) {
543
+ ) -> U
544
+ where
545
+ F : FnOnce ( & mut Self , Option < T > ) -> U ,
546
+ T : ast:: AstNode ,
547
+ {
547
548
// File containing the macro call. Expansion errors will be attached here.
548
549
let outer_file = self . expander . current_file_id ;
549
550
@@ -559,8 +560,7 @@ impl ExprCollector<'_> {
559
560
path,
560
561
} ) ;
561
562
}
562
- collector ( self , None ) ;
563
- return ;
563
+ return collector ( self , None ) ;
564
564
}
565
565
} ;
566
566
@@ -634,7 +634,6 @@ impl ExprCollector<'_> {
634
634
let syntax_ptr = AstPtr :: new ( & stmt. expr ( ) . unwrap ( ) ) ;
635
635
636
636
let prev_stmt = self . statements_in_scope . len ( ) ;
637
- let mut tail = None ;
638
637
self . collect_macro_call ( m, macro_ptr. clone ( ) , false , |this, expansion| {
639
638
match expansion {
640
639
Some ( expansion) => {
@@ -643,7 +642,6 @@ impl ExprCollector<'_> {
643
642
statements. statements ( ) . for_each ( |stmt| this. collect_stmt ( stmt) ) ;
644
643
if let Some ( expr) = statements. expr ( ) {
645
644
let expr = this. collect_expr ( expr) ;
646
- tail = Some ( expr) ;
647
645
this. statements_in_scope
648
646
. push ( Statement :: Expr { expr, has_semi } ) ;
649
647
}
@@ -654,6 +652,7 @@ impl ExprCollector<'_> {
654
652
}
655
653
}
656
654
} ) ;
655
+
657
656
let mut macro_exprs = smallvec ! [ ] ;
658
657
for stmt in & self . statements_in_scope [ prev_stmt..] {
659
658
match * stmt {
@@ -664,7 +663,6 @@ impl ExprCollector<'_> {
664
663
Statement :: Expr { expr, .. } => macro_exprs. push ( expr) ,
665
664
}
666
665
}
667
- macro_exprs. extend ( tail) ;
668
666
if !macro_exprs. is_empty ( ) {
669
667
self . source_map
670
668
. macro_call_to_exprs
@@ -894,15 +892,11 @@ impl ExprCollector<'_> {
894
892
ast:: Pat :: MacroPat ( mac) => match mac. macro_call ( ) {
895
893
Some ( call) => {
896
894
let macro_ptr = AstPtr :: new ( & call) ;
897
- let mut pat = None ;
898
- self . collect_macro_call ( call, macro_ptr, true , |this, expanded_pat| {
899
- pat = Some ( this. collect_pat_opt_ ( expanded_pat) ) ;
900
- } ) ;
901
-
902
- match pat {
903
- Some ( pat) => return pat,
904
- None => Pat :: Missing ,
905
- }
895
+ let pat =
896
+ self . collect_macro_call ( call, macro_ptr, true , |this, expanded_pat| {
897
+ this. collect_pat_opt_ ( expanded_pat)
898
+ } ) ;
899
+ return pat;
906
900
}
907
901
None => Pat :: Missing ,
908
902
} ,
0 commit comments