Skip to content

Commit

Permalink
Add validation for functions without body
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
P-E-P committed Dec 5, 2023
1 parent ef365e1 commit 8e7c439
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions gcc/rust/checks/errors/rust-ast-validation.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 (),
Expand Down

0 comments on commit 8e7c439

Please sign in to comment.