public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Arthur Cohen <cohenarthur@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc r14-8576] gccrs: Allow const and async specifiers in functions
Date: Tue, 30 Jan 2024 11:58:40 +0000 (GMT)	[thread overview]
Message-ID: <20240130115840.7E47038582AF@sourceware.org> (raw)

https://gcc.gnu.org/g:68990dbeadc5f4b90c0aa14387cb80d0f411aa43

commit r14-8576-g68990dbeadc5f4b90c0aa14387cb80d0f411aa43
Author: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Date:   Wed Nov 22 10:35:44 2023 +0100

    gccrs: 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>

Diff:
---
 gcc/rust/parse/rust-parse-impl.h | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/gcc/rust/parse/rust-parse-impl.h b/gcc/rust/parse/rust-parse-impl.h
index a1ad4f11993a..acceec302a2d 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 ())
     {

                 reply	other threads:[~2024-01-30 11:58 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240130115840.7E47038582AF@sourceware.org \
    --to=cohenarthur@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).