Skip to content

Commit

Permalink
Don't erroneously deny semicolons after closure expr within parenthes…
Browse files Browse the repository at this point in the history
…es in a macro
  • Loading branch information
compiler-errors committed Oct 22, 2022
1 parent eecde58 commit 3d7b1f0
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
4 changes: 4 additions & 0 deletions compiler/rustc_parse/src/parser/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2051,6 +2051,10 @@ impl<'a> Parser<'a> {

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
Expand Down
14 changes: 14 additions & 0 deletions src/test/ui/parser/semi-after-closure-in-macro.rs
Original file line number Diff line number Diff line change
@@ -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!(( ||() ; ));
}

0 comments on commit 3d7b1f0

Please sign in to comment.