@@ -48,22 +48,33 @@ impl<'a> Ctx<'a> {
48
48
pub ( super ) fn lower_macro_stmts ( mut self , stmts : ast:: MacroStmts ) -> ItemTree {
49
49
self . tree . top_level = stmts
50
50
. statements ( )
51
- . filter_map ( |stmt| match stmt {
52
- ast:: Stmt :: Item ( item) => Some ( item) ,
53
- // Macro calls can be both items and expressions. The syntax library always treats
54
- // them as expressions here, so we undo that.
55
- ast:: Stmt :: ExprStmt ( es) => match es. expr ( ) ? {
56
- ast:: Expr :: MacroCall ( call) => {
57
- cov_mark:: hit!( macro_call_in_macro_stmts_is_added_to_item_tree) ;
58
- Some ( call. into ( ) )
59
- }
51
+ . filter_map ( |stmt| {
52
+ match stmt {
53
+ ast:: Stmt :: Item ( item) => Some ( item) ,
54
+ // Macro calls can be both items and expressions. The syntax library always treats
55
+ // them as expressions here, so we undo that.
56
+ ast:: Stmt :: ExprStmt ( es) => match es. expr ( ) ? {
57
+ ast:: Expr :: MacroExpr ( expr) => {
58
+ cov_mark:: hit!( macro_call_in_macro_stmts_is_added_to_item_tree) ;
59
+ Some ( expr. macro_call ( ) ?. into ( ) )
60
+ }
61
+ _ => None ,
62
+ } ,
60
63
_ => None ,
61
- } ,
62
- _ => None ,
64
+ }
63
65
} )
64
66
. flat_map ( |item| self . lower_mod_item ( & item) )
65
67
. collect ( ) ;
66
68
69
+ if let Some ( ast:: Expr :: MacroExpr ( tail_macro) ) = stmts. expr ( ) {
70
+ if let Some ( call) = tail_macro. macro_call ( ) {
71
+ cov_mark:: hit!( macro_stmt_with_trailing_macro_expr) ;
72
+ if let Some ( mod_item) = self . lower_mod_item ( & call. into ( ) ) {
73
+ self . tree . top_level . push ( mod_item) ;
74
+ }
75
+ }
76
+ }
77
+
67
78
self . tree
68
79
}
69
80
@@ -75,7 +86,7 @@ impl<'a> Ctx<'a> {
75
86
// Macro calls can be both items and expressions. The syntax library always treats
76
87
// them as expressions here, so we undo that.
77
88
ast:: Stmt :: ExprStmt ( es) => match es. expr ( ) ? {
78
- ast:: Expr :: MacroCall ( call ) => self . lower_mod_item ( & call . into ( ) ) ,
89
+ ast:: Expr :: MacroExpr ( expr ) => self . lower_mod_item ( & expr . macro_call ( ) ? . into ( ) ) ,
79
90
_ => None ,
80
91
} ,
81
92
_ => None ,
0 commit comments