From 7b2d548681c9d23d08735d90f9f9451aa212d7c1 Mon Sep 17 00:00:00 2001 From: Pierre-Emmanuel Patry Date: Tue, 10 Dec 2024 14:52:59 +0100 Subject: [PATCH] Do not visit subitems for unit structs Unit structs don't have any sub items to visit and therefore do not require their own scope. gcc/rust/ChangeLog: * resolve/rust-late-name-resolver-2.0.cc (Late::visit): Prevent new scope creation for unit structs. * resolve/rust-toplevel-name-resolver-2.0.cc (TopLevel::visit): Likewise. Signed-off-by: Pierre-Emmanuel Patry --- gcc/rust/resolve/rust-late-name-resolver-2.0.cc | 3 ++- gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/gcc/rust/resolve/rust-late-name-resolver-2.0.cc b/gcc/rust/resolve/rust-late-name-resolver-2.0.cc index a96dc1ccf346..5ba57bac4430 100644 --- a/gcc/rust/resolve/rust-late-name-resolver-2.0.cc +++ b/gcc/rust/resolve/rust-late-name-resolver-2.0.cc @@ -271,7 +271,8 @@ void Late::visit (AST::StructStruct &s) { auto s_vis = [this, &s] () { AST::DefaultASTVisitor::visit (s); }; - ctx.scoped (Rib::Kind::Item, s.get_node_id (), s_vis); + if (!s.is_unit_struct ()) + ctx.scoped (Rib::Kind::Item, s.get_node_id (), s_vis); } void 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 01c5d26f4c15..a93416b5b098 100644 --- a/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc +++ b/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc @@ -264,7 +264,8 @@ TopLevel::visit (AST::StructStruct &struct_item) } }; - ctx.scoped (Rib::Kind::Item, struct_item.get_node_id (), generic_vis); + if (!struct_item.is_unit_struct ()) + ctx.scoped (Rib::Kind::Item, struct_item.get_node_id (), generic_vis); insert_or_error_out (struct_item.get_struct_name (), struct_item, Namespace::Types);