]> git.lizzy.rs Git - rust.git/commitdiff
Don't erroneously deny semicolons after closure expr within parentheses in a macro
authorMichael Goulet <michael@errs.io>
Wed, 19 Oct 2022 04:55:31 +0000 (04:55 +0000)
committerMichael Goulet <michael@errs.io>
Sat, 22 Oct 2022 06:59:49 +0000 (06:59 +0000)
compiler/rustc_parse/src/parser/expr.rs
src/test/ui/parser/semi-after-closure-in-macro.rs [new file with mode: 0644]

index afa116ce1bccd1314063eed2ef24384c4058ac48..5b466cec8e15b089298bf245c4ab7976ae3c0c4e 100644 (file)
@@ -2051,6 +2051,10 @@ fn parse_closure_expr(&mut self) -> PResult<'a, P<Expr>> {
 
         if self.token.kind == TokenKind::Semi
             && matches!(self.token_cursor.frame.delim_sp, Some((Delimiter::Parenthesis, _)))
+            // HACK: This is needed so we can detect whether we're inside a macro,
+            // where regular assumptions about what tokens can follow other tokens
+            // don't necessarily apply.
+            && self.subparser_name.is_none()
         {
             // It is likely that the closure body is a block but where the
             // braces have been removed. We will recover and eat the next
diff --git a/src/test/ui/parser/semi-after-closure-in-macro.rs b/src/test/ui/parser/semi-after-closure-in-macro.rs
new file mode 100644 (file)
index 0000000..14efb61
--- /dev/null
@@ -0,0 +1,14 @@
+// check-pass
+
+// Checks that the fix in #103222 doesn't also disqualify semicolons after
+// closures within parentheses *in macros*, where they're totally allowed.
+
+macro_rules! m {
+    (($expr:expr ; )) => {
+        $expr
+    };
+}
+
+fn main() {
+    let x = m!(( ||() ; ));
+}