From patchwork Wed Feb 7 11:44:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 197919 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp2204923dyb; Wed, 7 Feb 2024 04:55:51 -0800 (PST) X-Google-Smtp-Source: AGHT+IGCIC7vldpoQ3IxpKLILYAlQ5UrFvI3yTdrtQx+Oz5vZRmGU0stuLEUz3c4n5BCl5jIpxf1 X-Received: by 2002:ad4:5dec:0:b0:68c:c145:c90d with SMTP id jn12-20020ad45dec000000b0068cc145c90dmr683151qvb.49.1707310551293; Wed, 07 Feb 2024 04:55:51 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707310551; cv=pass; d=google.com; s=arc-20160816; b=wwFiVV7dLHsitKXh0DkhE9oGYkkMbNqKh3+XNKN90iBrHW42xJD4tf8rh97ry0/X3s 1cX7JGR6wyDDoeNWQPoL5q5jjBKRHsxJDp/GTgmIEujwF61r2G7ldfIZtjkS+I3auFyC /7Jjx4fvbjpdMlQlG9NYBL+GwO17IKUUh9GpP2TRFdMOmQiqLRmTW2xoy+E7KaZ4tcro N7N/LjIwG5jodC0WGfVD2lqIUcbk7zMam1odelrdkXmm0ucR4hceKjorGlFpX9L/XYmr NG37UyZ57invUhQnwTnT6RRGiQxdx1mVTAedyiPYcANJJm1JuNWwE+9oWErD4zfG0kyq /ZZw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:reply-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature:arc-filter:dmarc-filter:delivered-to; bh=wqNHLuLzlt/JmKsodfYBzj0FDtZBhZkR1ufIl17mH2k=; fh=f6HgfqAKQGYzbvwcp/F6Pk/F4YBNK9A4a2Cc4u0ELMs=; b=mHIBII5TBVBsnNjZCq+GwPQNEm+nXv2r/fA9pB740WLRAcK+TymAddh6yL6ZR8azdY beAl2vVkJJIB1TS+I2a9ZnTm90gQ0hS21nwlfeDa2rKO4o0oYJXgPC6jV8vgfq9IEMzw kITLIYnj2448rpMya//RTfeVcjhTwrlGHTPUTygBZSRVgCoCfdLBaU5/IbZnyQlhE526 9co+B0yUbjnE85kFdIQWDlVL+BNgLF6kPtu/HFHyniDT86hj2gO+pQd+mO5kdpLuwJvq WLmuq2dY7r/Ipd5t4fKEwe+xX1HQKi0rDIaWNsL7ss9ML6oNvmC6ldNVXhpAJ5y1oSGU 7bmA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=NQ0tgDdO; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" X-Forwarded-Encrypted: i=2; AJvYcCWXoiQ5En7uSldx+VGLQNXhkmLOgJ0OAIRbhJ02Aw9bNGbIZp0BsHoM0o3xeDoGVRNxz7DfbVPjVHfPe9OPrQ3+58zzCw== Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id kd12-20020a056214400c00b0068cc01da4d1si579881qvb.420.2024.02.07.04.55.51 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Feb 2024 04:55:51 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=NQ0tgDdO; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 058C63857C5B for ; Wed, 7 Feb 2024 12:55:51 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x336.google.com (mail-wm1-x336.google.com [IPv6:2a00:1450:4864:20::336]) by sourceware.org (Postfix) with ESMTPS id AF5BB385801C for ; Wed, 7 Feb 2024 12:44:18 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org AF5BB385801C 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 AF5BB385801C Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::336 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1707309868; cv=none; b=U1qe7pKKl5H0mgNBhhu0ECYE3WktCTEcNQKruGDNpYuL4omp679+zLXUfOL6NzVLSu3ukQmsalv0hB0ouoPfCr3oO7teHmhHDgczViNW4e1HHo7tb6j2XhAl2xsIGGaJE67jbd7kgL//ajwW7AUvFaCJAvXwE6adoLOL8VsAtNU= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1707309868; c=relaxed/simple; bh=mS31iCIkKmBLyOuai7/+dNRSqZPKTnVVU/Q1IbT2glo=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=Qx/LFI9JAACB8GquFO6ivYUDeLkytZXTQXbLe5Yzk9wutotLbdF6gIWM1uOn4avfvvTEsVl5CIvr9iBDnbHZ0XTy4Kj2v8ZaEQE5ry6ISZftAbNaPiSR7LF9UOrvLhx7SuI2G9uRo5MaDfx0swJSZIIiPX+3CtUV0dQ/4712gDU= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-wm1-x336.google.com with SMTP id 5b1f17b1804b1-40fe79f1aaaso4936015e9.0 for ; Wed, 07 Feb 2024 04:44:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1707309857; x=1707914657; 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=wqNHLuLzlt/JmKsodfYBzj0FDtZBhZkR1ufIl17mH2k=; b=NQ0tgDdO5+CWcVHW0WYSFqw4QNmp3b8fecnUOqEm+aOLLY7ox/OmiF8HT0NseNwxBc kUCMP5Rv5AXvE5c0to7vmTX0DDntJ20bBSbgC2v33hq5wNRDHRq+62BsNEhAJwDn5vhG xqBj2TDeFK6iDmF3/B9kFHJ0Fr+BZPF8N91dZiKC/0VX3Q6rwy5a4E0bffSlrjqQnxPN Ep1nKoLkUKxn18SqVd4mAqyOWEzIDZHaLRJ98p4MKrRgWrf4zyDoxuXQNrl5NPx5sX2y vtbtxHz6hC6avGzqcLENoRXXDHJe+WWXOHvHPhmkE9FV/TbrThXxahGbgzvryTxsS26o I+6A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707309857; x=1707914657; 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=wqNHLuLzlt/JmKsodfYBzj0FDtZBhZkR1ufIl17mH2k=; b=M6wAZBqXQ/B/FPqsUDn5VD6owwP1hrLGLpu1pNfYkD1HIa0dVq16JQy1v1Rs89Qjdr y4Gj28DEh7s0TvKwCTvu0l3ubMYsPtAJfVMzU2Aa4HIU/3O5EkBffuuoCQPIQCeiBF2W aViniKxSKp+4icFeE5qbYSSjuUrAVSl/d7t4n8VScc9B42+sT0S/HJSJwvNLDitBSrwi pst89vBY5av+UeWNNKzrLuKg4NQMl8HHMUS443i1F6xoIdfGYBpR02nxo/vc+cUa9VFw FL6/f0TDBC9mo9S9pTdMkz8KKlEV7zOVRG4TyhAZGEcPYR8mmEoLLtP1eqI7wfe+IEwG /xpA== X-Gm-Message-State: AOJu0YxJ5yzVek2N6ut19EtE5gN9CHn3gvba2XgLCnonhs/z0CAUuiPL flm0cMcRnyu+aDGfWnaptqF8HWzqM11GFWhYuEhXrUlrW+qeDpMsICmykDdl/Hk7GZgtdhbVglH iyQ== X-Received: by 2002:a05:600c:1f90:b0:40e:a7cf:10e0 with SMTP id je16-20020a05600c1f9000b0040ea7cf10e0mr4814591wmb.20.1707309857296; Wed, 07 Feb 2024 04:44:17 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCWwWLkwuC6iYiPzCRhdJaxrAeXEmqoUB8utQT4qMHWfEiE064J1HpHzP5zTAx/RoSAZ80CkrY41DgnT3yiihprSUP/MtRku Received: from platypus.sou.embecosm-corp.com ([212.69.42.53]) by smtp.gmail.com with ESMTPSA id x19-20020a05600c2a5300b0040fbdd6f69bsm5044188wme.33.2024.02.07.04.44.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Feb 2024 04:44:16 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Kushal Pal Subject: [COMMITTED 20/25] gccrs: Add checks for Trait functions Date: Wed, 7 Feb 2024 12:44:06 +0100 Message-ID: <20240207114419.1100894-21-arthur.cohen@embecosm.com> X-Mailer: git-send-email 2.42.1 In-Reply-To: <20240207114419.1100894-2-arthur.cohen@embecosm.com> References: <20240207114419.1100894-2-arthur.cohen@embecosm.com> MIME-Version: 1.0 X-Spam-Status: No, score=-13.9 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 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+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790244868803947324 X-GMAIL-MSGID: 1790244868803947324 From: Kushal Pal Since we want to use AST::Function class for trait functions as well, we need to check against specific conditions in ASTValidation phase. gcc/rust/ChangeLog: * checks/errors/rust-ast-validation.cc (ASTValidation::visit): Add checks for Trait functions. Signed-off-by: Kushal Pal --- gcc/rust/checks/errors/rust-ast-validation.cc | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/gcc/rust/checks/errors/rust-ast-validation.cc b/gcc/rust/checks/errors/rust-ast-validation.cc index ccb071f74b0..d1c8273a0b3 100644 --- a/gcc/rust/checks/errors/rust-ast-validation.cc +++ b/gcc/rust/checks/errors/rust-ast-validation.cc @@ -95,24 +95,28 @@ ASTValidation::visit (AST::Union &item) void ASTValidation::visit (AST::Function &function) { - std::set valid_context - = {Context::INHERENT_IMPL, Context::TRAIT_IMPL}; - const auto &qualifiers = function.get_qualifiers (); if (qualifiers.is_async () && qualifiers.is_const ()) rust_error_at (function.get_locus (), "functions cannot be both % and %"); - if (qualifiers.is_const () && context.back () == Context::TRAIT_IMPL) + if (qualifiers.is_const () + && (context.back () == Context::TRAIT_IMPL + || context.back () == Context::TRAIT)) rust_error_at (function.get_locus (), ErrorCode::E0379, - "functions in traits cannot be declared const"); + "functions in traits cannot be declared %"); // may change soon - if (qualifiers.is_async () && context.back () == Context::TRAIT_IMPL) + if (qualifiers.is_async () + && (context.back () == Context::TRAIT_IMPL + || context.back () == Context::TRAIT)) rust_error_at (function.get_locus (), ErrorCode::E0706, "functions in traits cannot be declared %"); - if (valid_context.find (context.back ()) == valid_context.end () + // if not an associated function but has a self parameter + if (context.back () != Context::TRAIT + && context.back () != Context::TRAIT_IMPL + && context.back () != Context::INHERENT_IMPL && function.has_self_param ()) rust_error_at ( function.get_self_param ()->get_locus (),