[085/125] gccrs: Unit struct constructor shall be resolved

Message ID 20240801145809.366388-87-arthur.cohen@embecosm.com
State Committed
Commit 97539b7c20eb08d5b6532016654ecc6ba6c9a09f
Headers
Series [001/125] Rust: Make 'tree'-level 'MAIN_NAME_P' work |

Commit Message

Arthur Cohen Aug. 1, 2024, 2:57 p.m. UTC
  From: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>

Unit struct have a special constructor that should be added to the struct
namespace in order to be resolved later when called. As it is a function
it should be added in the value namespace.

gcc/rust/ChangeLog:

	* resolve/rust-toplevel-name-resolver-2.0.cc (GlobbingVisitor::visit):
	Add the struct constructor when the struct is a unit.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
---
 gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
  

Patch

diff --git a/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc b/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc
index 4134b9a4620..75d9bb82131 100644
--- a/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc
+++ b/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc
@@ -68,8 +68,13 @@  void
 GlobbingVisitor::visit (AST::StructStruct &struct_item)
 {
   if (struct_item.get_visibility ().is_public ())
-    ctx.insert_shadowable (struct_item.get_identifier (),
-			   struct_item.get_node_id (), Namespace::Values);
+    {
+      ctx.insert_shadowable (struct_item.get_identifier (),
+			     struct_item.get_node_id (), Namespace::Types);
+      if (struct_item.is_unit_struct ())
+	ctx.insert_shadowable (struct_item.get_identifier (),
+			       struct_item.get_node_id (), Namespace::Values);
+    }
 }
 
 void