From 198d3ee34fbeec1749c184e30cc13b3d323f90dc Mon Sep 17 00:00:00 2001 From: Liam Naddell Date: Tue, 17 Dec 2024 11:48:03 -0500 Subject: Fix NR2.0 compiler ICE caused by Generics in Enums gcc/rust/ChangeLog: * resolve/rust-late-name-resolver-2.0.cc: Change the late name resolver to enter proper lexical scope during typechecking * resolve/rust-late-name-resolver-2.0.h: Add needed prototype to header * resolve/rust-toplevel-name-resolver-2.0.cc: Add generic parameters to enum's scoped RIB to allow for proper name resolution on types. gcc/testsuite/ChangeLog: * rust/compile/issue-3304.rs: Add small test for generics+enums combination for NR2.0 Signed-off-by: Liam Naddell --- gcc/rust/resolve/rust-late-name-resolver-2.0.cc | 7 +++++++ gcc/rust/resolve/rust-late-name-resolver-2.0.h | 1 + gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc | 9 +++++++++ 3 files changed, 17 insertions(+) (limited to 'gcc/rust') 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 6d450bc..a331e24 100644 --- a/gcc/rust/resolve/rust-late-name-resolver-2.0.cc +++ b/gcc/rust/resolve/rust-late-name-resolver-2.0.cc @@ -296,6 +296,13 @@ Late::visit (AST::StructStruct &s) } void +Late::visit (AST::Enum &s) +{ + auto s_vis = [this, &s] () { AST::DefaultASTVisitor::visit (s); }; + ctx.scoped (Rib::Kind::Item, s.get_node_id (), s_vis); +} + +void Late::visit (AST::StructExprStruct &s) { auto resolved = ctx.types.resolve_path (s.get_struct_name ().get_segments ()); diff --git a/gcc/rust/resolve/rust-late-name-resolver-2.0.h b/gcc/rust/resolve/rust-late-name-resolver-2.0.h index 98cf092..7260f99 100644 --- a/gcc/rust/resolve/rust-late-name-resolver-2.0.h +++ b/gcc/rust/resolve/rust-late-name-resolver-2.0.h @@ -52,6 +52,7 @@ public: void visit (AST::StructExprStructBase &) override; void visit (AST::StructExprStructFields &) override; void visit (AST::StructStruct &) override; + void visit (AST::Enum &) override; void visit (AST::GenericArgs &) override; void visit (AST::GenericArg &); 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 01c5d26..8fa4809 100644 --- a/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc +++ b/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc @@ -332,6 +332,15 @@ TopLevel::visit (AST::EnumItemDiscriminant &variant) void TopLevel::visit (AST::Enum &enum_item) { + auto generic_vis = [this, &enum_item] () { + for (auto &g : enum_item.get_generic_params ()) + { + g->accept_vis (*this); + } + }; + + ctx.scoped (Rib::Kind::Item, enum_item.get_node_id (), generic_vis); + insert_or_error_out (enum_item.get_identifier (), enum_item, Namespace::Types); -- cgit v1.1