Skip to content

Commit

Permalink
nr2.0: Handle "Self" properly in trait definitions
Browse files Browse the repository at this point in the history
gcc/rust/ChangeLog:

	* ast/rust-ast-visitor.cc
	(DefaultASTVisitor::visit): Visit implicit Self parameters of
	traits.
	* resolve/rust-late-name-resolver-2.0.cc
	(Late::visit): Resolve implicit Self parameters of traits.
	* resolve/rust-late-name-resolver-2.0.h:
	(Late::visit): Add trait visitor.
	* resolve/rust-toplevel-name-resolver-2.0.cc
	(TopLevel::visit): Insert resolutions for Self type parameters
	as well.

gcc/testsuite/ChangeLog:

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

Signed-off-by: Owen Avery <[email protected]>
  • Loading branch information
powerboat9 committed Dec 24, 2024
1 parent b5c354d commit f1eab67
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 7 deletions.
2 changes: 2 additions & 0 deletions gcc/rust/ast/rust-ast-visitor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -997,6 +997,8 @@ DefaultASTVisitor::visit (AST::Trait &trait)

visit_inner_attrs (trait);

visit (trait.get_implicit_self ());

for (auto &generic : trait.get_generic_params ())
visit (generic);

Expand Down
10 changes: 10 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 @@ -287,6 +287,16 @@ Late::visit (AST::TypePath &type)
DefaultResolver::visit (type);
}

void
Late::visit (AST::Trait &trait)
{
// kind of weird how this is done
ctx.map_usage (Usage (trait.get_implicit_self ().get_node_id ()),
Definition (trait.get_node_id ()));

DefaultResolver::visit (trait);
}

void
Late::visit (AST::StructStruct &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 @@ -48,6 +48,7 @@ class Late : public DefaultResolver
void visit (AST::PathInExpression &) override;
void visit (AST::LangItemPath &) override;
void visit (AST::TypePath &) override;
void visit (AST::Trait &) override;
void visit (AST::StructExprStruct &) override;
void visit (AST::StructExprStructBase &) override;
void visit (AST::StructExprStructFields &) override;
Expand Down
7 changes: 2 additions & 5 deletions gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc
Original file line number Diff line number Diff line change
Expand Up @@ -280,11 +280,8 @@ TopLevel::visit (AST::StructStruct &struct_item)
void
TopLevel::visit (AST::TypeParam &type_param)
{
// Hacky and weird, find a better solution
// We should probably not even insert self in the first place ?
if (type_param.get_type_representation ().as_string () != "Self")
insert_or_error_out (type_param.get_type_representation (), type_param,
Namespace::Types);
insert_or_error_out (type_param.get_type_representation (), type_param,
Namespace::Types);
}

void
Expand Down
2 changes: 0 additions & 2 deletions gcc/testsuite/rust/compile/nr2/exclude
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ issue-2190-2.rs
issue-2238.rs
issue-2304.rs
issue-2330.rs
issue-2375.rs
issue-2478.rs
issue-2479.rs
issue-2723-1.rs
Expand Down Expand Up @@ -182,7 +181,6 @@ issue-2987.rs
issue-3045-1.rs
issue-3045-2.rs
issue-3046.rs
unknown-associated-item.rs
issue-3030.rs
issue-3035.rs
issue-3139-1.rs
Expand Down

0 comments on commit f1eab67

Please sign in to comment.