From 01092b83913733d26f2c4d9bfdc22ff2eb0b0bbb Mon Sep 17 00:00:00 2001 From: Owen Avery Date: Tue, 26 Mar 2024 15:58:48 -0400 Subject: [PATCH] Avoid parsing const unsafe/extern functions as async gcc/rust/ChangeLog: * parse/rust-parse-impl.h (Parser::parse_vis_item): Call parse_function instead of parse_async_item when finding UNSAFE or EXTERN_KW during lookahead. gcc/testsuite/ChangeLog: * rust/compile/func-const-unsafe.rs: New test. Signed-off-by: Owen Avery --- gcc/rust/parse/rust-parse-impl.h | 4 ++-- gcc/testsuite/rust/compile/func-const-unsafe.rs | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/rust/compile/func-const-unsafe.rs diff --git a/gcc/rust/parse/rust-parse-impl.h b/gcc/rust/parse/rust-parse-impl.h index b6c2ca3fc0c9..263ca634ea5c 100644 --- a/gcc/rust/parse/rust-parse-impl.h +++ b/gcc/rust/parse/rust-parse-impl.h @@ -1382,10 +1382,10 @@ Parser::parse_vis_item (AST::AttrVec outer_attrs) case IDENTIFIER: case UNDERSCORE: return parse_const_item (std::move (vis), std::move (outer_attrs)); - case UNSAFE: - case EXTERN_KW: case ASYNC: return parse_async_item (std::move (vis), std::move (outer_attrs)); + case UNSAFE: + case EXTERN_KW: case FN_KW: return parse_function (std::move (vis), std::move (outer_attrs)); default: diff --git a/gcc/testsuite/rust/compile/func-const-unsafe.rs b/gcc/testsuite/rust/compile/func-const-unsafe.rs new file mode 100644 index 000000000000..9c932bd1cb54 --- /dev/null +++ b/gcc/testsuite/rust/compile/func-const-unsafe.rs @@ -0,0 +1 @@ +pub const unsafe fn foo() {}