public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r14-8587] gccrs: Add validation for functions without body
@ 2024-01-30 11:59 Arthur Cohen
0 siblings, 0 replies; only message in thread
From: Arthur Cohen @ 2024-01-30 11:59 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:04fd5a043b08fdc4d4e60499b8fd83d02007a737
commit r14-8587-g04fd5a043b08fdc4d4e60499b8fd83d02007a737
Author: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
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 <pierre-emmanuel.patry@embecosm.com>
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 (),
"%<self%> 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 %<impl%> 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 (),
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2024-01-30 11:59 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-01-30 11:59 [gcc r14-8587] gccrs: Add validation for functions without body Arthur Cohen
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).