diff options
author | Kushal Pal <kushalpal109@gmail.com> | 2024-01-26 11:25:10 +0530 |
---|---|---|
committer | Arthur Cohen <arthur.cohen@embecosm.com> | 2024-02-07 12:40:23 +0100 |
commit | 4be51abd5e829b2b9e8f4b7bc48212c17cf4c3f9 (patch) | |
tree | 199292cc6e69494e1677056baaa4db66e5d40702 /gcc/rust | |
parent | 4287f316e48398832aae30e288af887198206c68 (diff) | |
download | gcc-4be51abd5e829b2b9e8f4b7bc48212c17cf4c3f9.zip gcc-4be51abd5e829b2b9e8f4b7bc48212c17cf4c3f9.tar.gz gcc-4be51abd5e829b2b9e8f4b7bc48212c17cf4c3f9.tar.bz2 |
gccrs: 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>
Diffstat (limited to 'gcc/rust')
-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 (), |