aboutsummaryrefslogtreecommitdiff
path: root/gcc/rust/checks/errors/rust-ast-validation.cc
diff options
context:
space:
mode:
authorPierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>2023-11-22 16:37:17 +0100
committerArthur Cohen <arthur.cohen@embecosm.com>2024-01-30 12:36:48 +0100
commit04fd5a043b08fdc4d4e60499b8fd83d02007a737 (patch)
tree7b5aadd52f39ea315d2b1de96ed594bd89f9e8c5 /gcc/rust/checks/errors/rust-ast-validation.cc
parent7a989394795a740dd4bcabbba251428cc9df08f1 (diff)
downloadgcc-04fd5a043b08fdc4d4e60499b8fd83d02007a737.zip
gcc-04fd5a043b08fdc4d4e60499b8fd83d02007a737.tar.gz
gcc-04fd5a043b08fdc4d4e60499b8fd83d02007a737.tar.bz2
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>
Diffstat (limited to 'gcc/rust/checks/errors/rust-ast-validation.cc')
-rw-r--r--gcc/rust/checks/errors/rust-ast-validation.cc10
1 files changed, 10 insertions, 0 deletions
diff --git a/gcc/rust/checks/errors/rust-ast-validation.cc b/gcc/rust/checks/errors/rust-ast-validation.cc
index 2743eb0..6fb142c 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 (),