@@ -1146,6 +1146,26 @@ impl<'a, 'b> InvocationCollector<'a, 'b> {
11461146 }
11471147 }
11481148 }
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+ }
11491169}
11501170
11511171impl < ' a , ' b > MutVisitor for InvocationCollector < ' a , ' b > {
@@ -1175,8 +1195,13 @@ impl<'a, 'b> MutVisitor for InvocationCollector<'a, 'b> {
11751195 . into_inner ( ) ;
11761196 }
11771197
1178- if let ast:: ExprKind :: MacCall ( mac) = expr. kind {
1198+ if let ast:: ExprKind :: MacCall ( mut mac) = expr. kind {
11791199 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+ }
11801205 self . collect_bang ( mac, expr. span , AstFragmentKind :: Expr ) . make_expr ( ) . into_inner ( )
11811206 } else {
11821207 ensure_sufficient_stack ( || noop_visit_expr ( & mut expr, self ) ) ;
@@ -1322,8 +1347,14 @@ impl<'a, 'b> MutVisitor for InvocationCollector<'a, 'b> {
13221347 . map ( |expr| expr. into_inner ( ) ) ;
13231348 }
13241349
1325- if let ast:: ExprKind :: MacCall ( mac) = expr. kind {
1350+ if let ast:: ExprKind :: MacCall ( mut mac) = expr. kind {
13261351 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+ }
13271358 self . collect_bang ( mac, expr. span , AstFragmentKind :: OptExpr )
13281359 . make_opt_expr ( )
13291360 . map ( |expr| expr. into_inner ( ) )
0 commit comments