Allow for missing invisible close delim when reparsing an expression.
This can happen when invalid syntax is passed to a declarative macro. We shouldn't be too strict about the token stream position once the parser has rejected the invalid syntax. Fixes #139248.
This commit is contained in:
parent
e643f59f6d
commit
eb5d8923fc
3 changed files with 53 additions and 1 deletions
|
@ -793,7 +793,12 @@ impl<'a> Parser<'a> {
|
||||||
self.bump();
|
self.bump();
|
||||||
Some(res)
|
Some(res)
|
||||||
} else {
|
} 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.
|
||||||
|
self.dcx()
|
||||||
|
.span_delayed_bug(self.token.span, "no close delim with reparsing {mv_kind:?}");
|
||||||
|
None
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
|
|
14
tests/ui/macros/no-close-delim-issue-139248.rs
Normal file
14
tests/ui/macros/no-close-delim-issue-139248.rs
Normal file
|
@ -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
tests/ui/macros/no-close-delim-issue-139248.stderr
Normal file
33
tests/ui/macros/no-close-delim-issue-139248.stderr
Normal file
|
@ -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…
Add table
Add a link
Reference in a new issue