Skip to content

Commit 0d4fc55

Browse files
committed
Fix generic param redefined bug
When we name-resolve generic parameters their declaration gets inserted in to the upper-most rib on the stack. Then when this is referenced we lookup the relevant binding starting from the uppermost rib this lead to the 2nd extern item adding the same binding into the same rib which caused this clash. To fix this we need to have a seperate rib for each declaration so as reusing the same names don't clash with each other. Fixes #1131
1 parent fc22f12 commit 0d4fc55

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

gcc/rust/resolve/rust-ast-resolve-item.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -955,6 +955,15 @@ class ResolveExternItem : public ResolverBase
955955

956956
void visit (AST::ExternalFunctionItem &function) override
957957
{
958+
NodeId scope_node_id = function.get_node_id ();
959+
resolver->get_name_scope ().push (scope_node_id);
960+
resolver->get_type_scope ().push (scope_node_id);
961+
resolver->get_label_scope ().push (scope_node_id);
962+
resolver->push_new_name_rib (resolver->get_name_scope ().peek ());
963+
resolver->push_new_type_rib (resolver->get_type_scope ().peek ());
964+
resolver->push_new_label_rib (resolver->get_type_scope ().peek ());
965+
966+
// resolve the generics
958967
if (function.has_generics ())
959968
{
960969
for (auto &generic : function.get_generic_params ())
@@ -971,6 +980,11 @@ class ResolveExternItem : public ResolverBase
971980
{
972981
ResolveType::go (param.get_type ().get (), param.get_node_id ());
973982
}
983+
984+
// done
985+
resolver->get_name_scope ().pop ();
986+
resolver->get_type_scope ().pop ();
987+
resolver->get_label_scope ().pop ();
974988
}
975989

976990
void visit (AST::ExternalStaticItem &item) override
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
extern "rust-intrinsic" {
2+
fn size_of<T>() -> usize;
3+
fn offset<T>(dst: *const T, offset: isize) -> *const T;
4+
}

0 commit comments

Comments
 (0)