Skip to content

Commit

Permalink
Fix NR2.0 compiler ICE caused by Generics in Enums
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
liamnaddell committed Dec 25, 2024
1 parent af5fdee commit debe715
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 0 deletions.
7 changes: 7 additions & 0 deletions gcc/rust/resolve/rust-late-name-resolver-2.0.cc
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,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)
{
Expand Down
1 change: 1 addition & 0 deletions gcc/rust/resolve/rust-late-name-resolver-2.0.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ class Late : public DefaultResolver
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 &);

Expand Down
9 changes: 9 additions & 0 deletions gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
10 changes: 10 additions & 0 deletions gcc/testsuite/rust/compile/issue-3304.rs
Original file line number Diff line number Diff line change
@@ -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() {}

0 comments on commit debe715

Please sign in to comment.