aboutsummaryrefslogtreecommitdiff
path: root/gcc/rust/checks/errors/rust-ast-validation.cc
diff options
context:
space:
mode:
authorPierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>2023-11-08 16:50:50 +0100
committerArthur Cohen <arthur.cohen@embecosm.com>2024-01-16 19:13:13 +0100
commit93ca83c5efd6908b6c5602642004d0364bf9144b (patch)
tree8461fd36bb771bcbb409eb9a23432324811d6ac1 /gcc/rust/checks/errors/rust-ast-validation.cc
parentea59190d54612f9f0e09c77a0601023ef43f861d (diff)
downloadgcc-93ca83c5efd6908b6c5602642004d0364bf9144b.zip
gcc-93ca83c5efd6908b6c5602642004d0364bf9144b.tar.gz
gcc-93ca83c5efd6908b6c5602642004d0364bf9144b.tar.bz2
gccrs: Add validation pass for label name
Prevent from using reserved keyword in label name. gcc/rust/ChangeLog: * ast/rust-ast-visitor.cc (DefaultASTVisitor::visit): Check if there is a label before visit. * checks/errors/rust-ast-validation.cc (ASTValidation::visit): Emit an error when a label has a forbidden name. * checks/errors/rust-ast-validation.h: Add function prototype. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Diffstat (limited to 'gcc/rust/checks/errors/rust-ast-validation.cc')
-rw-r--r--gcc/rust/checks/errors/rust-ast-validation.cc15
1 files changed, 15 insertions, 0 deletions
diff --git a/gcc/rust/checks/errors/rust-ast-validation.cc b/gcc/rust/checks/errors/rust-ast-validation.cc
index 3af5655..44dec61 100644
--- a/gcc/rust/checks/errors/rust-ast-validation.cc
+++ b/gcc/rust/checks/errors/rust-ast-validation.cc
@@ -37,6 +37,21 @@ ASTValidation::visit (AST::Lifetime &lifetime)
}
void
+ASTValidation::visit (AST::LoopLabel &label)
+{
+ auto name = label.get_lifetime ().get_lifetime_name ();
+ auto lifetime_name = '\'' + name;
+ auto &keywords = Values::Keywords::keywords;
+ if (keywords.find (name) != keywords.end ())
+ rust_error_at (label.get_locus (), "invalid label name %qs",
+ lifetime_name.c_str ());
+
+ // WARNING: Do not call ContextualASTVisitor, we don't want to visit the
+ // lifetime
+ // Maybe we should refactor LoopLabel instead ?
+}
+
+void
ASTValidation::visit (AST::ConstantItem &const_item)
{
if (!const_item.has_expr () && context.back () != Context::TRAIT_IMPL)