File tree 2 files changed +23
-1
lines changed 2 files changed +23
-1
lines changed Original file line number Diff line number Diff line change @@ -551,8 +551,13 @@ impl ExprCollector<'_> {
551
551
}
552
552
}
553
553
ast:: Expr :: MacroStmts ( e) => {
554
- let statements = e. statements ( ) . filter_map ( |s| self . collect_stmt ( s) ) . collect ( ) ;
554
+ let statements: Box < [ _ ] > =
555
+ e. statements ( ) . filter_map ( |s| self . collect_stmt ( s) ) . collect ( ) ;
555
556
let tail = e. expr ( ) . map ( |e| self . collect_expr ( e) ) ;
557
+ if statements. is_empty ( ) && tail. is_none ( ) {
558
+ cov_mark:: hit!( empty_macro_in_trailing_position_is_removed) ;
559
+ return None ;
560
+ }
556
561
557
562
self . alloc_expr ( Expr :: MacroStmts { tail, statements } , syntax_ptr)
558
563
}
Original file line number Diff line number Diff line change @@ -1648,3 +1648,20 @@ fn main() {
1648
1648
"# ] ] ,
1649
1649
) ;
1650
1650
}
1651
+
1652
+ #[ test]
1653
+ fn trailing_empty_macro ( ) {
1654
+ cov_mark:: check!( empty_macro_in_trailing_position_is_removed) ;
1655
+ check_no_mismatches (
1656
+ r#"
1657
+ macro_rules! m2 {
1658
+ ($($t:tt)*) => {$($t)*};
1659
+ }
1660
+
1661
+ fn macrostmts() -> u8 {
1662
+ m2! { 0 }
1663
+ m2! {}
1664
+ }
1665
+ "# ,
1666
+ ) ;
1667
+ }
You can’t perform that action at this time.
0 commit comments