diff options
author | M V V S Manoj Kumar <mvvsmanojkumar@gmail.com> | 2023-11-21 22:04:24 +0530 |
---|---|---|
committer | Arthur Cohen <arthur.cohen@embecosm.com> | 2024-01-30 12:36:45 +0100 |
commit | d5c582396c66e9e0499ecee67129f1ff1dd55889 (patch) | |
tree | 61cb49982a68cb1e2884fe1fb5676c906658d29a /gcc/rust/parse | |
parent | 2c843a047dd3c596b4daabe247e52e1d6475e4d6 (diff) | |
download | gcc-d5c582396c66e9e0499ecee67129f1ff1dd55889.zip gcc-d5c582396c66e9e0499ecee67129f1ff1dd55889.tar.gz gcc-d5c582396c66e9e0499ecee67129f1ff1dd55889.tar.bz2 |
gccrs: Added support to Parse ASYNC function
Fixes issue #2650
The parser now parses ASYNC functions. Added ASYNC case to parse_item
Added a new function parse_async_item which is called in
parse_vis_item to handle the ASYNC case. Parse_async_item
also checks the current Rust edition and generates an error if the
edition is 2015
gcc/rust/ChangeLog:
* parse/rust-parse-impl.h (Parser::parse_item): Likewise.
(Parser::parse_vis_item): Likewise.
(Parser::parse_async_item): Likewise.
* parse/rust-parse.h: Made declaration for parse_async_item.
gcc/testsuite/ChangeLog:
* rust/compile/issue-2650-1.rs: New test.(edition=2018)
* rust/compile/issue-2650-2.rs: New test.(edition=2015)
Signed-off-by: M V V S Manoj Kumar <mvvsmanojkumar@gmail.com>
Diffstat (limited to 'gcc/rust/parse')
-rw-r--r-- | gcc/rust/parse/rust-parse-impl.h | 40 | ||||
-rw-r--r-- | gcc/rust/parse/rust-parse.h | 2 |
2 files changed, 42 insertions, 0 deletions
diff --git a/gcc/rust/parse/rust-parse-impl.h b/gcc/rust/parse/rust-parse-impl.h index 37eddc1..53b3839 100644 --- a/gcc/rust/parse/rust-parse-impl.h +++ b/gcc/rust/parse/rust-parse-impl.h @@ -30,6 +30,7 @@ #include "rust-dir-owner.h" #include "rust-attribute-values.h" #include "rust-keyword-values.h" +#include "rust-session-manager.h" #include "optional.h" @@ -1113,6 +1114,8 @@ Parser<ManagedTokenSource>::parse_item (bool called_from_statement) add_error (std::move (error)); } return nullptr; + + case ASYNC: case PUB: case MOD: case EXTERN_KW: @@ -1389,6 +1392,10 @@ Parser<ManagedTokenSource>::parse_vis_item (AST::AttrVec outer_attrs) lexer.skip_token (1); // TODO: is this right thing to do? return nullptr; } + // for async functions + case ASYNC: + return parse_async_item (std::move (vis), std::move (outer_attrs)); + case STATIC_KW: return parse_static_item (std::move (vis), std::move (outer_attrs)); case AUTO: @@ -1429,6 +1436,39 @@ Parser<ManagedTokenSource>::parse_vis_item (AST::AttrVec outer_attrs) return nullptr; } +template <typename ManagedTokenSource> +std::unique_ptr<AST::Function> +Parser<ManagedTokenSource>::parse_async_item (AST::Visibility vis, + AST::AttrVec outer_attrs) +{ + const_TokenPtr t = lexer.peek_token (); + if (Session::get_instance ().options.get_edition () + == CompileOptions::Edition::E2015) + { + add_error (Error (t->get_locus (), ErrorCode::E0670, + "%<async fn%> is not permitted in Rust 2015")); + add_error ( + Error::Hint (t->get_locus (), + "to use %<async fn%>, switch to Rust 2018 or later")); + } + + t = lexer.peek_token (1); + + switch (t->get_id ()) + { + case UNSAFE: + case FN_KW: + return parse_function (std::move (vis), std::move (outer_attrs)); + + default: + add_error ( + Error (t->get_locus (), "expected item, found keyword %<async%>")); + + lexer.skip_token (1); + return nullptr; + } +} + // Parses a macro rules definition syntax extension whatever thing. template <typename ManagedTokenSource> std::unique_ptr<AST::MacroRulesDefinition> diff --git a/gcc/rust/parse/rust-parse.h b/gcc/rust/parse/rust-parse.h index e873d52..d371846 100644 --- a/gcc/rust/parse/rust-parse.h +++ b/gcc/rust/parse/rust-parse.h @@ -357,6 +357,8 @@ private: std::unique_ptr<AST::ExternBlock> parse_extern_block (AST::Visibility vis, AST::AttrVec outer_attrs); std::unique_ptr<AST::Function> parse_method (); + std::unique_ptr<AST::Function> parse_async_item (AST::Visibility vis, + AST::AttrVec outer_attrs); // Expression-related (Pratt parsed) std::unique_ptr<AST::Expr> |