gccrs: Fix issue with parsing unsafe block expression statements

gcc/rust/ChangeLog:

	* parse/rust-parse-impl.h
	(Parser::parse_stmt): Handle unsafe expression statements.

gcc/testsuite/ChangeLog:

	* rust/compile/issue-1422.rs: New test.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
This commit is contained in:
Owen Avery
2023-01-26 22:59:49 -05:00
committed by Arthur Cohen
parent 990ae497b8
commit d2a499a988
2 changed files with 16 additions and 1 deletions

View File

@@ -6131,7 +6131,15 @@ Parser<ManagedTokenSource>::parse_stmt (ParseRestrictions restrictions)
/* if any of these (should be all possible VisItem prefixes), parse a
* VisItem can't parse item because would require reparsing outer
* attributes */
return parse_vis_item (std::move (outer_attrs));
// may also be unsafe block
if (lexer.peek_token (1)->get_id () == LEFT_CURLY)
{
return parse_expr_stmt (std::move (outer_attrs), restrictions);
}
else
{
return parse_vis_item (std::move (outer_attrs));
}
break;
case SUPER:
case SELF:

View File

@@ -0,0 +1,7 @@
macro_rules! test {
() => { unsafe {} };
}
fn main() {
test!();
}