Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nr2.0: Resolve type aliases inside trait definitions #3330

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
22 changes: 22 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,28 @@ Late::visit (AST::TypePath &type)
DefaultResolver::visit (type);
}

void
Late::visit (AST::Trait &trait)
{
// kind of weird how this is done
// names are resolved to the node id of trait.get_implicit_self ()
// which is then resolved to the node id of trait
// we set up the latter mapping here
ctx.map_usage (Usage (trait.get_implicit_self ().get_node_id ()),
Definition (trait.get_node_id ()));

DefaultResolver::visit (trait);
}

void
Late::visit (AST::TraitItemType &trait_item)
{
std::ignore = ctx.types.insert (trait_item.get_identifier (),
trait_item.get_node_id ());

DefaultResolver::visit (trait_item);
}

void
Late::visit (AST::StructStruct &s)
{
Expand Down
2 changes: 2 additions & 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,8 @@ 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::TraitItemType &) 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
7 changes: 0 additions & 7 deletions gcc/testsuite/rust/compile/nr2/exclude
Original file line number Diff line number Diff line change
Expand Up @@ -74,19 +74,15 @@ issue-2139.rs
issue-2142.rs
issue-2165.rs
issue-2166.rs
issue-2190-1.rs
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
issue-2723-2.rs
issue-2772-2.rs
issue-2775.rs
issue-2747.rs
issue-2782.rs
issue-2812.rs
issue-850.rs
Expand All @@ -99,7 +95,6 @@ macros/mbe/macro-issue1233.rs
macros/mbe/macro-issue1400.rs
macros/mbe/macro13.rs
macros/mbe/macro15.rs
macros/mbe/macro20.rs
macros/mbe/macro23.rs
macros/mbe/macro40.rs
macros/mbe/macro43.rs
Expand Down Expand Up @@ -182,7 +177,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 All @@ -200,7 +194,6 @@ iflet.rs
issue-3033.rs
issue-3009.rs
issue-2323.rs
issue-2953-1.rs
issue-2953-2.rs
issue-1773.rs
issue-2905-1.rs
Expand Down
Loading