aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorPierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>2023-11-22 10:35:44 +0100
committerP-E-P <32375388+P-E-P@users.noreply.github.com>2023-12-01 09:14:09 +0000
commit804830a0258aadcaf26683abb86019ed96a33c14 (patch)
tree9087766649603dd43cdd14af7457e6443e4ba150 /gcc
parent6b9657a645057800d19b1ecf7447f693d54c1e13 (diff)
downloadgcc-804830a0258aadcaf26683abb86019ed96a33c14.zip
gcc-804830a0258aadcaf26683abb86019ed96a33c14.tar.gz
gcc-804830a0258aadcaf26683abb86019ed96a33c14.tar.bz2
Allow const and async specifiers in functions
We need to account for const specifiers in async parsing as const can be used in the syntax before the async keyword. gcc/rust/ChangeLog: * parse/rust-parse-impl.h (Parser::parse_vis_item): Allow parsing async items in const. (Parser::parse_async_item): Account for const offset during async lookahead. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Diffstat (limited to 'gcc')
-rw-r--r--gcc/rust/parse/rust-parse-impl.h8
1 files changed, 6 insertions, 2 deletions
diff --git a/gcc/rust/parse/rust-parse-impl.h b/gcc/rust/parse/rust-parse-impl.h
index 3c8d81b..b8c40c3 100644
--- a/gcc/rust/parse/rust-parse-impl.h
+++ b/gcc/rust/parse/rust-parse-impl.h
@@ -1383,6 +1383,8 @@ Parser<ManagedTokenSource>::parse_vis_item (AST::AttrVec outer_attrs)
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 FN_KW:
return parse_function (std::move (vis), std::move (outer_attrs));
default:
@@ -1445,7 +1447,9 @@ std::unique_ptr<AST::Function>
Parser<ManagedTokenSource>::parse_async_item (AST::Visibility vis,
AST::AttrVec outer_attrs)
{
- const_TokenPtr t = lexer.peek_token ();
+ auto offset = (lexer.peek_token ()->get_id () == CONST) ? 1 : 0;
+ const_TokenPtr t = lexer.peek_token (offset);
+
if (Session::get_instance ().options.get_edition ()
== CompileOptions::Edition::E2015)
{
@@ -1456,7 +1460,7 @@ Parser<ManagedTokenSource>::parse_async_item (AST::Visibility vis,
"to use %<async fn%>, switch to Rust 2018 or later"));
}
- t = lexer.peek_token (1);
+ t = lexer.peek_token (offset + 1);
switch (t->get_id ())
{