File tree Expand file tree Collapse file tree 2 files changed +26
-1
lines changed Expand file tree Collapse file tree 2 files changed +26
-1
lines changed Original file line number Diff line number Diff line change @@ -551,9 +551,17 @@ impl ExprCollector<'_> {
551551 }
552552 }
553553 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 ( ) ;
555556 let tail = e. expr ( ) . map ( |e| self . collect_expr ( e) ) ;
556557
558+ if e. syntax ( ) . children ( ) . next ( ) . is_none ( ) {
559+ // HACK: make sure that macros that expand to nothing aren't treated as a `()`
560+ // expression when used in block tail position.
561+ cov_mark:: hit!( empty_macro_in_trailing_position_is_removed) ;
562+ return None ;
563+ }
564+
557565 self . alloc_expr ( Expr :: MacroStmts { tail, statements } , syntax_ptr)
558566 }
559567 ast:: Expr :: UnderscoreExpr ( _) => self . alloc_expr ( Expr :: Underscore , syntax_ptr) ,
Original file line number Diff line number Diff line change @@ -1648,3 +1648,20 @@ fn main() {
16481648 "# ] ] ,
16491649 ) ;
16501650}
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