From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm1-x329.google.com (mail-wm1-x329.google.com [IPv6:2a00:1450:4864:20::329]) by sourceware.org (Postfix) with ESMTPS id 7DCDA3857C51 for ; Wed, 7 Feb 2024 12:44:18 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 7DCDA3857C51 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 7DCDA3857C51 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::329 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-x329.google.com with SMTP id 5b1f17b1804b1-40fc654a718so4832675e9.2 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=vfLelqwHkEnAeeKs+Y14EnxQPTsOzcurIY+DCLEps4k2pgXJ6kumnkoU/M3Z/3rXDL FyaAZPWx8/GTwyINNjhslT+yNC+hOuhZyXhC26Qjf6i4qFBterFAk84ju4b7NPDk+aJ7 /WwSIzgVNMgN0jRl1aWdi3rECpIoUBKO7hjUv0EX3+7qOaRE6eSEuoAu0UUF1IfRQAGy YTHIEA4467dGrhndpSaWjoi6INUZL+NK+4X/D3gRTO1C5BR5zbX9jRZHFeN1Pm8UplmZ yFUBoaa/HIlyXGoont1EOQJUCqpw/feR2Fx84mfFImP354kyJzLJbahsduBH6NRl+FEi gWAw== X-Gm-Message-State: AOJu0Yz3audeAWswAskkRYItHulhJHmu2SBn9Ggi99VwIrpqqNjnLoCH 0G8UYm0wrz7dtQYvI95cN7jmz0xoT0MCh/D1/NLZkvSGldgMqprBfwjLGJsxKg== X-Google-Smtp-Source: AGHT+IFSfkxUetPHzcIvirGjNDNtkHiG9rpmpUOBFwpGTkBZgNuI+JLR/goTDQWBLn5ZHmLvM4ckgQ== 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> Reply-To: arthur.cohen@embecosm.com MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-13.4 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: 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 (), -- 2.42.1