From patchwork Tue Jan 30 12:07:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 1892923 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=embecosm.com header.i=@embecosm.com header.a=rsa-sha256 header.s=google header.b=CP+THBjL; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TPQ4s2jZrz23dQ for ; Tue, 30 Jan 2024 23:50:37 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 53A883870C29 for ; Tue, 30 Jan 2024 12:50:35 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x330.google.com (mail-wm1-x330.google.com [IPv6:2a00:1450:4864:20::330]) by sourceware.org (Postfix) with ESMTPS id 135333857715 for ; Tue, 30 Jan 2024 12:11:56 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 135333857715 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 135333857715 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::330 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616766; cv=none; b=ivxbCVyKePDiqLJ3Mo4nFeW3qKtYn6RxQF+dx90KELi14YmD5DO5lTRgVtZIgX19QYMwhsz7peFdYaMrHFtRp4GbgL3mZu+7ONwWA8QQUxq1kPoncNWTiW9oVvzjGYh2nhohk5W9zIVsKfdJS+d08XG8fdDwP1QEb6tC/9WdCog= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616766; c=relaxed/simple; bh=WLmEbuZuCNSzxnWiTdJoX7lGY8hInPsouNyCN9PkNvY=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=hf1Rr9PzDbj+KktubztlUVVnV2B19aNhqjLmahc/EBzqB+CEm2F+DBhFhn3emD5JitVtGgUj+943F3dgSn/oW7WpNdfqK776HUyBDCSHBuZE6r7aCYhU18fx7HdOjyDvo8p9rePVJFSxB6Dh/klZNLfxyA9z9KvevLA5JJxxbmM= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-wm1-x330.google.com with SMTP id 5b1f17b1804b1-40eebe7767cso31016615e9.1 for ; Tue, 30 Jan 2024 04:11:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1706616714; x=1707221514; 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=UHRqBOxOtqWYWRSwQg/aqnHJ0bDUu14A9mOmF+1PYW8=; b=CP+THBjL/6Aq+Wp5G/YTAg0AaNgr9pQBNs6FV3BUX2yD5M2Cn0kw9kda7es/Y4XvYd EYcN2qibUM8h69AiZlQDIGWXku/jkQ6GgqzMsowJ+YEVhFgjBlbjcAawZ+r6BRZqJpmk 25h/IbnYW/DYuLVu4QTBjy7CEj7XfhtidrscDKIsl0k8D4uwQPSL54ERyL4pxCaM45yv QhauAWRCqO7h5mlWUDBER2MODx3hsChgPe6jgW1avbCunWHp1/1XtDeGGJgG6a0HtD9b QUu5aHgo7t9qDjhusQbZMl+UF066MrsC5Zwc6OwvVpOobu1ea6K0+SPbL5wziR2lHN+f yN1w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706616714; x=1707221514; 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=UHRqBOxOtqWYWRSwQg/aqnHJ0bDUu14A9mOmF+1PYW8=; b=KlKr0BuAYt6ge8OUVKqn77eeKx8IWLtF1Og/lbvWRJTjM7Y4/Sw+fcicGTUrh0mZ2Y rz827y1Rg8RLYhYiFUq6nKvz0tp52f0+owm32bHLqsn7CmVPQkeRyrFEvvxdP5zdxofc CfuEHeHV1IS0m+jE9MxXlO5G/U9u3za21lNOGYIfb7YSvXfbSLY6CbCtufDJJzN7vA+N izzVIRcYo921oV6xmSV1Jtqvqt1o5ITmeeVZTkba27o15mpjNs/1XVxe8p33nQXwJinN kPNWMfxaZCoC5muiCggPD73m3XkCw3BnbKWx1Oljj4ch7AbX5W4fQxDTqm6iqXj1AVjK nynw== X-Gm-Message-State: AOJu0YyPIHOFGA2qfrFXOwD2pmaR+m6wRTb2Yism92suE3T8bqNZ13IS 8eYSL5P2poxVYaKnBKrae3V2YwYN5I91I2E7RzdnNWKOpAGIe6ibjRu8k3a4dnwTC42d9xhdL4t XSA== X-Google-Smtp-Source: AGHT+IEuFg1/xFxTbIDVM0enewBY2jNVo8P2aA1xyqld+s9aow9WACHowPX2gimJxOnynFQ/dfAOOw== X-Received: by 2002:a5d:53c5:0:b0:339:39c3:d274 with SMTP id a5-20020a5d53c5000000b0033939c3d274mr6953363wrw.36.1706616714182; Tue, 30 Jan 2024 04:11:54 -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.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 04:11:53 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Kushal Pal Subject: [COMMITTED 089/101] gccrs: Handle `async` functions in traits Date: Tue, 30 Jan 2024 13:07:45 +0100 Message-ID: <20240130121026.807464-92-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> MIME-Version: 1.0 X-Spam-Status: No, score=-14.2 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=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: arthur.cohen@embecosm.com Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org From: Kushal Pal Fixes #2785 gcc/rust/ChangeLog: * checks/errors/rust-ast-validation.cc (ASTValidation::visit): Added check for `async` functions inside trait. * parse/rust-parse-impl.h (Parser::parse_trait_item): Added switch-case for ASYNC token. gcc/testsuite/ChangeLog: * rust/compile/issue-2785.rs: New test. Signed-off-by: Kushal Pal --- gcc/rust/checks/errors/rust-ast-validation.cc | 13 ++++++++++--- gcc/rust/parse/rust-parse-impl.h | 1 + gcc/testsuite/rust/compile/issue-2785.rs | 9 +++++++++ 3 files changed, 20 insertions(+), 3 deletions(-) create mode 100644 gcc/testsuite/rust/compile/issue-2785.rs diff --git a/gcc/rust/checks/errors/rust-ast-validation.cc b/gcc/rust/checks/errors/rust-ast-validation.cc index b50e9cdf858..0ed5d060894 100644 --- a/gcc/rust/checks/errors/rust-ast-validation.cc +++ b/gcc/rust/checks/errors/rust-ast-validation.cc @@ -141,9 +141,16 @@ ASTValidation::visit (AST::TraitFunctionDecl &decl) { const auto &qualifiers = decl.get_qualifiers (); - if (context.back () == Context::TRAIT && qualifiers.is_const ()) - rust_error_at (decl.get_identifier ().get_locus (), ErrorCode::E0379, - "functions in traits cannot be declared const"); + if (context.back () == Context::TRAIT) + { + // may change soon + if (qualifiers.is_async ()) + rust_error_at (decl.get_identifier ().get_locus (), ErrorCode::E0706, + "functions in traits cannot be declared %"); + if (qualifiers.is_const ()) + rust_error_at (decl.get_identifier ().get_locus (), ErrorCode::E0379, + "functions in traits cannot be declared const"); + } } void diff --git a/gcc/rust/parse/rust-parse-impl.h b/gcc/rust/parse/rust-parse-impl.h index dfa2762c5c3..3055a3959cf 100644 --- a/gcc/rust/parse/rust-parse-impl.h +++ b/gcc/rust/parse/rust-parse-impl.h @@ -5096,6 +5096,7 @@ Parser::parse_trait_item () // else, fallthrough to function // TODO: find out how to disable gcc "implicit fallthrough" error gcc_fallthrough (); + case ASYNC: case UNSAFE: case EXTERN_KW: case FN_KW: { diff --git a/gcc/testsuite/rust/compile/issue-2785.rs b/gcc/testsuite/rust/compile/issue-2785.rs new file mode 100644 index 00000000000..08f6346f60b --- /dev/null +++ b/gcc/testsuite/rust/compile/issue-2785.rs @@ -0,0 +1,9 @@ +// { dg-additional-options "-frust-edition=2018" } +trait Foo { + async fn foo(){} + // { dg-error "functions in traits cannot be declared .async." "" { target *-*-* } .-1 } + async fn bar(); + // { dg-error "functions in traits cannot be declared .async." "" { target *-*-* } .-1 } +} + +fn main() {}