From: Owen Avery Date: Fri, 27 Jan 2023 03:59:49 +0000 (-0500) Subject: gccrs: Fix issue with parsing unsafe block expression statements X-Git-Tag: basepoints/gcc-14~95 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d2a499a9881c7c079d2a722b57c7fcf022a864dd;p=thirdparty%2Fgcc.git 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 --- diff --git a/gcc/rust/parse/rust-parse-impl.h b/gcc/rust/parse/rust-parse-impl.h index 1e5b2dc85ede..db32803ddbea 100644 --- a/gcc/rust/parse/rust-parse-impl.h +++ b/gcc/rust/parse/rust-parse-impl.h @@ -6131,7 +6131,15 @@ Parser::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: diff --git a/gcc/testsuite/rust/compile/issue-1422.rs b/gcc/testsuite/rust/compile/issue-1422.rs new file mode 100644 index 000000000000..b178cda185e5 --- /dev/null +++ b/gcc/testsuite/rust/compile/issue-1422.rs @@ -0,0 +1,7 @@ +macro_rules! test { + () => { unsafe {} }; +} + +fn main() { + test!(); +}