]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Fix NR2.0 compiler ICE caused by Generics in Enums
authorLiam Naddell <liamnprg@gmail.com>
Tue, 17 Dec 2024 16:48:03 +0000 (11:48 -0500)
committerCohenArthur <arthur.cohen@embecosm.com>
Thu, 2 Jan 2025 09:34:36 +0000 (09:34 +0000)
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 <liam.naddell@mail.utoronto.ca>
gcc/rust/resolve/rust-late-name-resolver-2.0.cc
gcc/rust/resolve/rust-late-name-resolver-2.0.h
gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc
gcc/testsuite/rust/compile/issue-3304.rs [new file with mode: 0644]

index 6d450bc59569b9a592dbcfab3ad7ed85abf175cc..a331e24908f4edaaad68b16611c8172957fcb42d 100644 (file)
@@ -295,6 +295,13 @@ Late::visit (AST::StructStruct &s)
   ctx.scoped (Rib::Kind::Item, s.get_node_id (), s_vis);
 }
 
+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)
 {
index 98cf09205bf44bf5459b395e9634c40f214c5fdc..7260f99507d1e2635a877a2b4dbe85fd6b64d0b0 100644 (file)
@@ -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 &);
 
index 01c5d26f4c159d2ca72896c37b1f1bce7584f4f8..8fa4809d7158217121dd35bccad7bb848a5bb15d 100644 (file)
@@ -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);
 
diff --git a/gcc/testsuite/rust/compile/issue-3304.rs b/gcc/testsuite/rust/compile/issue-3304.rs
new file mode 100644 (file)
index 0000000..6ab614f
--- /dev/null
@@ -0,0 +1,10 @@
+// { dg-additional-options "-frust-name-resolution-2.0" }
+#[lang = "sized"]
+trait Sized {}
+
+pub enum ROption<T> {
+    RSome(T),
+    RNone,
+}
+
+fn main() {}