@@ -1146,6 +1146,26 @@ impl<'a, 'b> InvocationCollector<'a, 'b> {
1146
1146
}
1147
1147
}
1148
1148
}
1149
+
1150
+ // Postfix macro calls can be parsed to allow proc macros to support the syntax,
1151
+ // but they may not be expanded.
1152
+ fn check_postfix_mac_call (
1153
+ & mut self ,
1154
+ call : & mut ast:: MacCall ,
1155
+ span : Span ,
1156
+ ) -> Option < P < ast:: Expr > > {
1157
+ let postfix_self_arg = call. postfix_self_arg . take ( ) ;
1158
+ if postfix_self_arg. is_some ( ) {
1159
+ let mut err = self . cx . struct_span_err (
1160
+ span,
1161
+ & format ! ( "forbidden postfix macro call `{}`" , pprust:: path_to_string( & call. path) ) ,
1162
+ ) ;
1163
+ err. span_label ( call. path . span , "macros can't be called in postfix position" ) ;
1164
+
1165
+ err. emit ( ) ;
1166
+ }
1167
+ postfix_self_arg
1168
+ }
1149
1169
}
1150
1170
1151
1171
impl < ' a , ' b > MutVisitor for InvocationCollector < ' a , ' b > {
@@ -1175,8 +1195,13 @@ impl<'a, 'b> MutVisitor for InvocationCollector<'a, 'b> {
1175
1195
. into_inner ( ) ;
1176
1196
}
1177
1197
1178
- if let ast:: ExprKind :: MacCall ( mac) = expr. kind {
1198
+ if let ast:: ExprKind :: MacCall ( mut mac) = expr. kind {
1179
1199
self . check_attributes ( & expr. attrs ) ;
1200
+ if let Some ( postfix_self_arg) = self . check_postfix_mac_call ( & mut mac, expr. span ) {
1201
+ let mut self_arg = postfix_self_arg. into_inner ( ) ;
1202
+ ensure_sufficient_stack ( || noop_visit_expr ( & mut self_arg, self ) ) ;
1203
+ return self_arg;
1204
+ }
1180
1205
self . collect_bang ( mac, expr. span , AstFragmentKind :: Expr ) . make_expr ( ) . into_inner ( )
1181
1206
} else {
1182
1207
ensure_sufficient_stack ( || noop_visit_expr ( & mut expr, self ) ) ;
@@ -1322,8 +1347,14 @@ impl<'a, 'b> MutVisitor for InvocationCollector<'a, 'b> {
1322
1347
. map ( |expr| expr. into_inner ( ) ) ;
1323
1348
}
1324
1349
1325
- if let ast:: ExprKind :: MacCall ( mac) = expr. kind {
1350
+ if let ast:: ExprKind :: MacCall ( mut mac) = expr. kind {
1326
1351
self . check_attributes ( & expr. attrs ) ;
1352
+
1353
+ if let Some ( postfix_self_arg) = self . check_postfix_mac_call ( & mut mac, expr. span ) {
1354
+ let mut self_arg = postfix_self_arg. into_inner ( ) ;
1355
+ noop_visit_expr ( & mut self_arg, self ) ;
1356
+ return Some ( self_arg) ;
1357
+ }
1327
1358
self . collect_bang ( mac, expr. span , AstFragmentKind :: OptExpr )
1328
1359
. make_opt_expr ( )
1329
1360
. map ( |expr| expr. into_inner ( ) )
0 commit comments