From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wr1-x434.google.com (mail-wr1-x434.google.com [IPv6:2a00:1450:4864:20::434]) by sourceware.org (Postfix) with ESMTPS id 7CA873857C7E for ; Tue, 30 Jan 2024 12:11:38 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 7CA873857C7E 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 7CA873857C7E Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::434 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616730; cv=none; b=aBBNd46LfZJv97M3gxjfnm6pzIv9KXy/xuLtIu8qb5deXXJw1a/R/F63qShf4GqvbxYvW/p7Jx/0NxbjwiUXVewJj389cF2ccv2LihKvYfdU5wu2YTH+PRwb6mE/pW5Jsid7wT+U/QejlO/qKUdHDxp5RuSLShouDLxAm3UXgUU= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616730; c=relaxed/simple; bh=UoJRc1bkZHjxdnrsydb3aUnoPpkT44TombNUGjiUXU4=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=Xi+mrs6Gc4vaRFzfIe2lloU8uj0cRhoAyrNzVoaXy22p+/eYdXpKOFuaFc34TepAcHh0vlPKgPfhWMYf8rBQdFXF16U3iIVumts61EqU3exDqNsTQZnNLV+rZdZFBCWBT7Z5CBhIH6DeWHerQuJ0rz88Zkgb+HKF1V5ValCECEU= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-wr1-x434.google.com with SMTP id ffacd0b85a97d-33934567777so3029406f8f.1 for ; Tue, 30 Jan 2024 04:11:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1706616696; x=1707221496; 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=nB5Y/pE8eC3pgLib4epj/PNs7fzwaFqAJ5cV6cRW1jg=; b=Aip8YZucVQUzKNEOBQEMunG0Ec3A3BOXOvzVbKZb5uM6qEzLbU4qDTnZHatB+WoChD 4MHzPTcSEzbDEnQgknNJS54KSVQhLfj9E02ROBfENUeubp1yRj+pk8BJ/YplgpFOpuAK vAbI5y7a/WraMz76YIktJXAOVGIYZ9Dw8nTiqrJus/K20jTaH4HHJ2r5WemN6bRkv2Cn wYpBOp8Sx18wDoAvIibdh7M+xB3+LAnMjzbInQ51eGRCpR8mhPOLIMT6SkuQPLlQI2sh rkSrZcutOebC4jpSYSQeLrNQnwDetpoPDG1ykeyDgL21nzmnaNqcZaM5FH+v48IlkSsA /b+A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706616696; x=1707221496; 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=nB5Y/pE8eC3pgLib4epj/PNs7fzwaFqAJ5cV6cRW1jg=; b=pYsnDkx6Acp1P1Um+p+ekBmXyYpRte4F7qgfhwWpqUgBEu9ykmxtb5Cs+0pFHUpXZI jTVH5qITW8PAR/ppgkyiBjkQw/fxBh/JyItMM8hmzTSRmRnIs//AAN9jgmSh1xpNgMLJ oqPrTIBIpsRt9KO5zcNkWFN+GAmVx98kTEbv5bvQeb0v+33ouX7TdED22Asz8Yd1Wnbo a0bv67crf1qXLR9FmrAWMgHYXmvjhqZD9QhcklDIaX0pfFf2O2YnLObDrBrLGkHmbBli V2wLN2I3+1tocbrr+CZ7TYOLa/CMFSA0vtXDk/l1uImQ5DFulQFPlB+7w+lY8vPTAGYE r3/A== X-Gm-Message-State: AOJu0Yyrcupoao9ovoXiywUamEK0G5ysIqaJfwQEWNFzCAzkOzTUvjVF oE4ggajj/oHCR8/KiY/DuVRncuael5DZvSGZMDvP6B3Q8kJeYYhnsheNLpWFFCNDXdLWpGPjJCb oPg== X-Google-Smtp-Source: AGHT+IE6FmQC8N9+SH37rbe961+Lzua7X2XyZMZys2wR+dd3cCMwhWhjdEOnsGYTRDeAVv+Une+1rQ== X-Received: by 2002:adf:d1cf:0:b0:33a:eda2:baf7 with SMTP id b15-20020adfd1cf000000b0033aeda2baf7mr4267073wrd.63.1706616696619; Tue, 30 Jan 2024 04:11:36 -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.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 04:11:36 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Pierre-Emmanuel Patry Subject: [COMMITTED 063/101] gccrs: Add validation for functions without body Date: Tue, 30 Jan 2024 13:07:19 +0100 Message-ID: <20240130121026.807464-66-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.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=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: Pierre-Emmanuel Patry Add checks in the ast validation pass to error out with functions (either free or associated) without a definition. gcc/rust/ChangeLog: * checks/errors/rust-ast-validation.cc (ASTValidation::visit): Add a validation check and emit an error depending on the context. Signed-off-by: Pierre-Emmanuel Patry --- gcc/rust/checks/errors/rust-ast-validation.cc | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/gcc/rust/checks/errors/rust-ast-validation.cc b/gcc/rust/checks/errors/rust-ast-validation.cc index 2743eb0ca29..6fb142c7845 100644 --- a/gcc/rust/checks/errors/rust-ast-validation.cc +++ b/gcc/rust/checks/errors/rust-ast-validation.cc @@ -109,6 +109,16 @@ ASTValidation::visit (AST::Function &function) function.get_self_param ()->get_locus (), "% parameter is only allowed in associated functions"); + if (!function.has_body ()) + { + if (context.back () == Context::INHERENT_IMPL + || context.back () == Context::TRAIT_IMPL) + rust_error_at (function.get_locus (), + "associated function in % without body"); + else if (context.back () != Context::TRAIT) + rust_error_at (function.get_locus (), "free function without a body"); + } + if (function.is_variadic ()) rust_error_at ( function.get_function_params ().back ()->get_locus (), -- 2.42.1