From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm1-x32e.google.com (mail-wm1-x32e.google.com [IPv6:2a00:1450:4864:20::32e]) by sourceware.org (Postfix) with ESMTPS id 6A1C738582AF for ; Tue, 30 Jan 2024 12:11:15 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 6A1C738582AF Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=embecosm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=embecosm.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 6A1C738582AF Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::32e ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616686; cv=none; b=LBzZuQ7Mgz/9jXNIrEZyAua7dc5lEFBj8WpWNoBXDzWRZIuktQXmNEu38KfgRY498oxt/B7hMCJW9bdla1mGpeCpvuXAaKZWMzE+KR9T2EMKHxJxByQwauXeZF0p3AkojNxWcFMRksgMkNyFLHqYCpEUwMu/m1MpGqc0GOJ+fRE= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616686; c=relaxed/simple; bh=VuhQbL6y+Nqu6SlxLin+D5zxWSOv9vafi/+uJoUwgBA=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=E+EP7T+OpAtSSOSb7kbso4qnvHpnOoub08gthzQFwlkVN1ioza334LmwPRyJIEDMVkm2qSzHE1GWo+wkl1H8a+hHeGIo3VlGBy4WczxBYl7nkOy4q3RufNX0hkdr0pJJ6yMTrO+a4qJJPEJG4bi37bJ7BWLdNU6hbaKMx1Xym08= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-wm1-x32e.google.com with SMTP id 5b1f17b1804b1-40ef3f351d2so12561265e9.1 for ; Tue, 30 Jan 2024 04:11:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1706616674; x=1707221474; darn=gcc.gnu.org; h=content-transfer-encoding:mime-version:reply-to:references :in-reply-to:message-id:date:subject:cc:to:from:from:to:cc:subject :date:message-id:reply-to; bh=BICrr66xJU+6tF/NHZ8Rq1bmcWtq7X62yN12NOXM4+4=; b=QepjgyjK8bM1md4r8MPPrZo8Per00zeIFYT8zyTVYv6BxYFZsXY9LR21wRXjrf7j4T 5gxIPW7ZRQgc8ZYT9MPCql/H/3Q2AiIN0QWgH1U4106RRm9wD3Bdum1y2lDD88OaEs+B nq/siAn1WJNcRqq+uqIYcyh0BVGyOW5AE1+FnotQu0AxUr5N4WlL6YDooUKO0gnYrOZh W699ofgrk3KI082bqfhSSWNq78wTdxm35cWBVtss4iHGSWIy94adyFsruQY/55W14ZN/ ksNk7p8dY15IsHoX3qrwvmFfT1LjhrUPkvL9lyvqU46MhcWXYEQj0CJfEPr+GNIeywGK 6R+A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706616674; x=1707221474; h=content-transfer-encoding:mime-version:reply-to:references :in-reply-to:message-id:date:subject:cc:to:from:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=BICrr66xJU+6tF/NHZ8Rq1bmcWtq7X62yN12NOXM4+4=; b=gwOcXKk9kopzikiU8i2s11vgL1/R6z0KT+d5HuGjeJKCKwl3uQ4Lf78MfSCZCQYOcQ RVybOUcAxWkPbt5h+2GrZbWFfNdIySg7YMDnH13dS3iYXKsQoyar35BiZTxJ3VZ4lDsP Y1nz7QLUrv6NA2WgxgsYA7awXvM9pqVosH/3oRMJpvDd1rXmwt/m7GYN1zi7l5D+I1cr O1QQSxRDWZug6p2TqcT2ltOtW7F+0g1hFP5usV7gQZmr/MYMFI8BiBfG9wVFG+cl1R04 8aLsZ3rKhGgiPJ1ewTRwwJZ7TiZAMVyeR6+b7v0uXMmq4JhcA8gbxHvizwyAMiPJWDYm Lmdg== X-Gm-Message-State: AOJu0YwyMxxQKqh+5/8SiMxBVK3/VGL5pFzMHxaH4yGSO0Uq4lNzbWw5 Q6fo99+ihojuajQX1ak3FY6ecfUcPljIiPxCi/nNoNWZHgux16DgxudmNGFP9Q== X-Google-Smtp-Source: AGHT+IHZfC7W6aZnHSo2uRgfVIRM+MflQwglu8vo5iUDAydGOvyG4kI9fuZ9w/x2P1O6UArZTUE8CA== X-Received: by 2002:a5d:5002:0:b0:33a:ec95:3168 with SMTP id e2-20020a5d5002000000b0033aec953168mr1376826wrt.13.1706616674250; Tue, 30 Jan 2024 04:11:14 -0800 (PST) Received: from platypus.localdomain ([62.23.166.218]) by smtp.gmail.com with ESMTPSA id f9-20020a056000036900b00339307d9d31sm10569894wrf.112.2024.01.30.04.11.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 04:11:14 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, M V V S Manoj Kumar Subject: [COMMITTED 032/101] gccrs: Added support to Parse ASYNC function Date: Tue, 30 Jan 2024 13:06:48 +0100 Message-ID: <20240130121026.807464-35-arthur.cohen@embecosm.com> X-Mailer: git-send-email 2.42.1 In-Reply-To: <20240130121026.807464-2-arthur.cohen@embecosm.com> References: <20240130121026.807464-2-arthur.cohen@embecosm.com> Reply-To: arthur.cohen@embecosm.com MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-14.1 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: From: M V V S Manoj Kumar 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 --- gcc/rust/parse/rust-parse-impl.h | 40 ++++++++++++++++++++++ gcc/rust/parse/rust-parse.h | 2 ++ gcc/testsuite/rust/compile/issue-2650-1.rs | 5 +++ gcc/testsuite/rust/compile/issue-2650-2.rs | 5 +++ 4 files changed, 52 insertions(+) create mode 100644 gcc/testsuite/rust/compile/issue-2650-1.rs create mode 100644 gcc/testsuite/rust/compile/issue-2650-2.rs diff --git a/gcc/rust/parse/rust-parse-impl.h b/gcc/rust/parse/rust-parse-impl.h index 37eddc1b753..53b3839db37 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::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::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::parse_vis_item (AST::AttrVec outer_attrs) return nullptr; } +template +std::unique_ptr +Parser::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, + "% is not permitted in Rust 2015")); + add_error ( + Error::Hint (t->get_locus (), + "to use %, 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 %")); + + lexer.skip_token (1); + return nullptr; + } +} + // Parses a macro rules definition syntax extension whatever thing. template std::unique_ptr diff --git a/gcc/rust/parse/rust-parse.h b/gcc/rust/parse/rust-parse.h index e873d5292cd..d3718467b48 100644 --- a/gcc/rust/parse/rust-parse.h +++ b/gcc/rust/parse/rust-parse.h @@ -357,6 +357,8 @@ private: std::unique_ptr parse_extern_block (AST::Visibility vis, AST::AttrVec outer_attrs); std::unique_ptr parse_method (); + std::unique_ptr parse_async_item (AST::Visibility vis, + AST::AttrVec outer_attrs); // Expression-related (Pratt parsed) std::unique_ptr diff --git a/gcc/testsuite/rust/compile/issue-2650-1.rs b/gcc/testsuite/rust/compile/issue-2650-1.rs new file mode 100644 index 00000000000..381398e19f5 --- /dev/null +++ b/gcc/testsuite/rust/compile/issue-2650-1.rs @@ -0,0 +1,5 @@ +// { dg-additional-options "-frust-edition=2018" } + +pub async fn a() -> u32 { + 1 +} diff --git a/gcc/testsuite/rust/compile/issue-2650-2.rs b/gcc/testsuite/rust/compile/issue-2650-2.rs new file mode 100644 index 00000000000..5132e6e1158 --- /dev/null +++ b/gcc/testsuite/rust/compile/issue-2650-2.rs @@ -0,0 +1,5 @@ +// { dg-additional-options "-frust-edition=2015" } + +pub async fn a() -> u32 { // { dg-error "'async fn' is not permitted in Rust 2015" } + 1 +} -- 2.42.1