public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r14-8861] gccrs: Add checks for Trait functions
@ 2024-02-07 12:44 Arthur Cohen
0 siblings, 0 replies; only message in thread
From: Arthur Cohen @ 2024-02-07 12:44 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:4be51abd5e829b2b9e8f4b7bc48212c17cf4c3f9
commit r14-8861-g4be51abd5e829b2b9e8f4b7bc48212c17cf4c3f9
Author: Kushal Pal <kushalpal109@gmail.com>
Date: Fri Jan 26 11:25:10 2024 +0530
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>
Diff:
---
gcc/rust/checks/errors/rust-ast-validation.cc | 18 +++++++++++-------
1 file 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 ccb071f74b09..d1c8273a0b3f 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 (),
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2024-02-07 12:44 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-02-07 12:44 [gcc r14-8861] gccrs: Add checks for Trait functions Arthur Cohen
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).