From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 7905) id 6C22A38582B4; Tue, 30 Jan 2024 11:59:37 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6C22A38582B4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1706615977; bh=+E8RMipza6xUfyRWnfZkqnNOmQYl2v4LWZ+ckKFNAbs=; h=From:To:Subject:Date:From; b=n717RRMHVLCSSyKm5XeU/WdqGVihBKdxqy8EdrrZknvjQQptUytwC7gOrsnQ7FyWk 2QVCSPzScyeEG0+QHD5f1VTRlu6EA2+W2JGmaKGcplKlLl7q+WEbHuP7npI+8grYT6 v45VATnOiuQklBAk5L2njFhSwMXEb/NL9WlHwrBs= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Arthur Cohen To: gcc-cvs@gcc.gnu.org Subject: [gcc r14-8587] gccrs: Add validation for functions without body X-Act-Checkin: gcc X-Git-Author: Pierre-Emmanuel Patry X-Git-Refname: refs/heads/trunk X-Git-Oldrev: 7a989394795a740dd4bcabbba251428cc9df08f1 X-Git-Newrev: 04fd5a043b08fdc4d4e60499b8fd83d02007a737 Message-Id: <20240130115937.6C22A38582B4@sourceware.org> Date: Tue, 30 Jan 2024 11:59:37 +0000 (GMT) List-Id: https://gcc.gnu.org/g:04fd5a043b08fdc4d4e60499b8fd83d02007a737 commit r14-8587-g04fd5a043b08fdc4d4e60499b8fd83d02007a737 Author: Pierre-Emmanuel Patry Date: Wed Nov 22 16:37:17 2023 +0100 gccrs: Add validation for functions without body 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 Diff: --- 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 2743eb0ca299..6fb142c78455 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 (),