From 1eaf085607f39111370e2c485ca819da7e14dfd1 Mon Sep 17 00:00:00 2001 From: Owen Avery Date: Tue, 7 Jan 2025 14:03:13 -0500 Subject: [PATCH] nr2.0: Resolve Self inside impl blocks 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 --- .../rust-toplevel-name-resolver-2.0.cc | 26 +++++++++++++++++++ .../resolve/rust-toplevel-name-resolver-2.0.h | 2 ++ gcc/testsuite/rust/compile/nr2/exclude | 3 --- 3 files changed, 28 insertions(+), 3 deletions(-) diff --git a/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc b/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc index a88adabb094..61e9ea4a928 100644 --- a/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc +++ b/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc @@ -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) { diff --git a/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.h b/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.h index 4b8a51cff9c..ff86cf48ba8 100644 --- a/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.h +++ b/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.h @@ -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 ¯o) override; void visit (AST::Function &function) override; diff --git a/gcc/testsuite/rust/compile/nr2/exclude b/gcc/testsuite/rust/compile/nr2/exclude index af7d105debc..9b1ee7ceaf9 100644 --- a/gcc/testsuite/rust/compile/nr2/exclude +++ b/gcc/testsuite/rust/compile/nr2/exclude @@ -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 @@ -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