https://gcc.gnu.org/g:c7687ef1f7a9d2683bb45dcbf547b42aae856075

commit c7687ef1f7a9d2683bb45dcbf547b42aae856075
Author: Owen Avery <powerboat9.ga...@gmail.com>
Date:   Wed Feb 28 20:19:04 2024 -0500

    Visit constant items without expressions properly
    
    gcc/rust/ChangeLog:
    
            * resolve/rust-default-resolver.cc
            (DefaultResolver::visit):
            Verify constant item has expression before attempting to visit
            the later.
    
    Signed-off-by: Owen Avery <powerboat9.ga...@gmail.com>

Diff:
---
 gcc/rust/resolve/rust-default-resolver.cc | 15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)

diff --git a/gcc/rust/resolve/rust-default-resolver.cc 
b/gcc/rust/resolve/rust-default-resolver.cc
index c54cabad2e5d..ca831840298e 100644
--- a/gcc/rust/resolve/rust-default-resolver.cc
+++ b/gcc/rust/resolve/rust-default-resolver.cc
@@ -449,13 +449,16 @@ DefaultResolver::visit (AST::EnumItemDiscriminant &item)
 void
 DefaultResolver::visit (AST::ConstantItem &item)
 {
-  auto expr_vis = [this, &item] () {
-    item.get_expr ().accept_vis (*this);
-    visit (item.get_type ());
-  };
+  if (item.has_expr ())
+    {
+      auto expr_vis = [this, &item] () {
+       item.get_expr ().accept_vis (*this);
+       visit (item.get_type ());
+      };
 
-  // FIXME: Why do we need a Rib here?
-  ctx.scoped (Rib::Kind::Item, item.get_node_id (), expr_vis);
+      // FIXME: Why do we need a Rib here?
+      ctx.scoped (Rib::Kind::Item, item.get_node_id (), expr_vis);
+    }
 }
 
 void

Reply via email to