]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
gccrs: Add validation for functions without body
authorPierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Wed, 22 Nov 2023 15:37:17 +0000 (16:37 +0100)
committerArthur Cohen <arthur.cohen@embecosm.com>
Tue, 30 Jan 2024 11:36:48 +0000 (12:36 +0100)
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>
gcc/rust/checks/errors/rust-ast-validation.cc

index 2743eb0ca2998ec2327b3615a66e11b96dc8b762..6fb142c78455a3dcad0ba40bff3317f7568f3066 100644 (file)
@@ -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 (),