Skip to content

Commit

Permalink
nr2.0: Resolve Self inside impl blocks
Browse files Browse the repository at this point in the history
gcc/rust/ChangeLog:

	* resolve/rust-toplevel-name-resolver-2.0.cc
	(TopLevel::visit): Insert a definition for Self when visiting
	InherentImpl and TraitImpl instances.
	* resolve/rust-toplevel-name-resolver-2.0.h
	(TopLevel::visit): Add visitors for InherentImpl and TraitImpl.

gcc/testsuite/ChangeLog:

	* rust/compile/nr2/exclude: Remove entries.

Signed-off-by: Owen Avery <[email protected]>
  • Loading branch information
powerboat9 committed Jan 8, 2025
1 parent 5bccf14 commit 7566092
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 3 deletions.
26 changes: 26 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 @@ -103,6 +103,32 @@ TopLevel::visit (AST::Trait &trait)
DefaultResolver::visit (trait);
}

void
TopLevel::visit (AST::InherentImpl &impl)
{
auto inner_fn = [this, &impl] () {
insert_or_error_out (Identifier ("Self", impl.get_type ().get_locus ()),
impl.get_type (), Namespace::Types);

AST::DefaultASTVisitor::visit (impl);
};

ctx.scoped (Rib::Kind::TraitOrImpl, impl.get_node_id (), inner_fn);
}

void
TopLevel::visit (AST::TraitImpl &impl)
{
auto inner_fn = [this, &impl] () {
insert_or_error_out (Identifier ("Self", impl.get_type ().get_locus ()),
impl.get_type (), Namespace::Types);

AST::DefaultASTVisitor::visit (impl);
};

ctx.scoped (Rib::Kind::TraitOrImpl, impl.get_node_id (), inner_fn);
}

void
TopLevel::visit (AST::TraitItemType &trait_item)
{
Expand Down
2 changes: 2 additions & 0 deletions gcc/rust/resolve/rust-toplevel-name-resolver-2.0.h
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,8 @@ class TopLevel : public DefaultResolver

void visit (AST::Module &module) override;
void visit (AST::Trait &trait) override;
void visit (AST::InherentImpl &impl) override;
void visit (AST::TraitImpl &impl) override;
void visit (AST::TraitItemType &trait_item) override;
void visit (AST::MacroRulesDefinition &macro) override;
void visit (AST::Function &function) override;
Expand Down
3 changes: 0 additions & 3 deletions gcc/testsuite/rust/compile/nr2/exclude
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,11 @@ generics6.rs
generics9.rs
if_let_expr.rs
issue-1019.rs
issue-1031.rs
issue-1034.rs
issue-1129-2.rs
issue-1130.rs
issue-1173.rs
issue-1272.rs
issue-1289.rs
issue-1447.rs
issue-1483.rs
issue-1725-1.rs
Expand Down Expand Up @@ -85,7 +83,6 @@ issue-855.rs
issue-925.rs
iterators1.rs
lookup_err1.rs
macros/mbe/macro-issue1233.rs
macros/mbe/macro-issue1400.rs
macros/mbe/macro13.rs
macros/mbe/macro15.rs
Expand Down

0 comments on commit 7566092

Please sign in to comment.