Skip to content

Allow for missing invisible close delim when reparsing an expression. #139298

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion compiler/rustc_parse/src/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -793,7 +793,10 @@ impl<'a> Parser<'a> {
self.bump();
Some(res)
} else {
panic!("no close delim when reparsing {mv_kind:?}");
// This can occur when invalid syntax is passed to a decl macro. E.g. see #139248,
// where the reparse attempt of an invalid expr consumed the trailing invisible
// delimiter.
None
}
} else {
None
Expand Down
14 changes: 14 additions & 0 deletions tests/ui/macros/no-close-delim-issue-139248.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// This code caused a "no close delim when reparsing Expr" ICE in #139248.

macro_rules! m {
(static a : () = $e:expr) => {
static a : () = $e;
//~^ ERROR macro expansion ends with an incomplete expression: expected expression
}
}

m! { static a : () = (if b) }
//~^ error: expected `{`, found `)`
//~| error: expected `{`, found `)`

fn main() {}
33 changes: 33 additions & 0 deletions tests/ui/macros/no-close-delim-issue-139248.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
error: expected `{`, found `)`
--> $DIR/no-close-delim-issue-139248.rs:10:27
|
LL | m! { static a : () = (if b) }
| ^ expected `{`
|
note: the `if` expression is missing a block after this condition
--> $DIR/no-close-delim-issue-139248.rs:10:26
|
LL | m! { static a : () = (if b) }
| ^

error: expected `{`, found `)`
--> $DIR/no-close-delim-issue-139248.rs:10:27
|
LL | m! { static a : () = (if b) }
| ^ expected `{`
|
note: the `if` expression is missing a block after this condition
--> $DIR/no-close-delim-issue-139248.rs:10:26
|
LL | m! { static a : () = (if b) }
| ^
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`

error: macro expansion ends with an incomplete expression: expected expression
--> $DIR/no-close-delim-issue-139248.rs:5:28
|
LL | static a : () = $e;
| ^ expected expression

error: aborting due to 3 previous errors

Loading