diff options
author | Kushal Pal <kushalpal109@gmail.com> | 2024-01-26 11:25:10 +0530 |
---|---|---|
committer | CohenArthur <arthur.cohen@embecosm.com> | 2024-02-05 17:08:39 +0000 |
commit | 37a6e44c4c3fcc90b2a19ba75741d4827d525a81 (patch) | |
tree | b657cf4a97c63c99d5816cdda388242045ba4ee1 | |
parent | a9ed0b1594fc3d95bdfb999fbce6d93424d26868 (diff) | |
download | gcc-37a6e44c4c3fcc90b2a19ba75741d4827d525a81.zip gcc-37a6e44c4c3fcc90b2a19ba75741d4827d525a81.tar.gz gcc-37a6e44c4c3fcc90b2a19ba75741d4827d525a81.tar.bz2 |
Add checks for Trait functions
Since we want to use AST::Function class for trait functions as well, we
need to check against specific conditions in ASTValidation phase.
gcc/rust/ChangeLog:
* checks/errors/rust-ast-validation.cc (ASTValidation::visit):
Add checks for Trait functions.
Signed-off-by: Kushal Pal <kushalpal109@gmail.com>
-rw-r--r-- | gcc/rust/checks/errors/rust-ast-validation.cc | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/gcc/rust/checks/errors/rust-ast-validation.cc b/gcc/rust/checks/errors/rust-ast-validation.cc index ccb071f..d1c8273 100644 --- a/gcc/rust/checks/errors/rust-ast-validation.cc +++ b/gcc/rust/checks/errors/rust-ast-validation.cc @@ -95,24 +95,28 @@ ASTValidation::visit (AST::Union &item) void ASTValidation::visit (AST::Function &function) { - std::set<Context> valid_context - = {Context::INHERENT_IMPL, Context::TRAIT_IMPL}; - const auto &qualifiers = function.get_qualifiers (); if (qualifiers.is_async () && qualifiers.is_const ()) rust_error_at (function.get_locus (), "functions cannot be both %<const%> and %<async%>"); - if (qualifiers.is_const () && context.back () == Context::TRAIT_IMPL) + if (qualifiers.is_const () + && (context.back () == Context::TRAIT_IMPL + || context.back () == Context::TRAIT)) rust_error_at (function.get_locus (), ErrorCode::E0379, - "functions in traits cannot be declared const"); + "functions in traits cannot be declared %<const%>"); // may change soon - if (qualifiers.is_async () && context.back () == Context::TRAIT_IMPL) + if (qualifiers.is_async () + && (context.back () == Context::TRAIT_IMPL + || context.back () == Context::TRAIT)) rust_error_at (function.get_locus (), ErrorCode::E0706, "functions in traits cannot be declared %<async%>"); - if (valid_context.find (context.back ()) == valid_context.end () + // if not an associated function but has a self parameter + if (context.back () != Context::TRAIT + && context.back () != Context::TRAIT_IMPL + && context.back () != Context::INHERENT_IMPL && function.has_self_param ()) rust_error_at ( function.get_self_param ()->get_locus (), |