public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r14-7625] gccrs: Add missing name resolution to item statements
@ 2024-01-16 17:46 Arthur Cohen
  0 siblings, 0 replies; only message in thread
From: Arthur Cohen @ 2024-01-16 17:46 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:56e29f4d5de8134db5f7772adc13154f3efccf43

commit r14-7625-g56e29f4d5de8134db5f7772adc13154f3efccf43
Author: Philip Herron <herron.philip@googlemail.com>
Date:   Tue May 30 13:45:58 2023 +0100

    gccrs: Add missing name resolution to item statements
    
    This fixes the issue but there are two cleanups to do at some point.
    
      1. misc namesapce this is a scope AST namespace where we dump resolution
         info when its not defined here. This occurs in the case such as nested
         scopes where the nested scope is popped and we hit an assertion.
         Outside of name resolution this requirement shouldnt really apply
         it should be permissive to allow for this
    
      2. We reuse our existing name resolution pieces here for Traits and impl
         blocks we should start doing this for the other statements.
    
    Fixes #2238
    
    gcc/rust/ChangeLog:
    
            * resolve/rust-ast-resolve-stmt.cc (ResolveStmt::visit): add name resolution
            * resolve/rust-ast-resolve-stmt.h: likewise
            * typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): insert resolved node
    
    gcc/testsuite/ChangeLog:
    
            * rust/compile/issue-2238.rs: New test.
    
    Signed-off-by: Philip Herron <herron.philip@googlemail.com>

Diff:
---
 gcc/rust/resolve/rust-ast-resolve-stmt.cc      | 22 ++++++++++++++++++++++
 gcc/rust/resolve/rust-ast-resolve-stmt.h       |  3 +++
 gcc/rust/typecheck/rust-hir-type-check-expr.cc | 12 ++++++++++--
 gcc/testsuite/rust/compile/issue-2238.rs       | 15 +++++++++++++++
 4 files changed, 50 insertions(+), 2 deletions(-)

diff --git a/gcc/rust/resolve/rust-ast-resolve-stmt.cc b/gcc/rust/resolve/rust-ast-resolve-stmt.cc
index 01e848424bf..04dfdfed0ff 100644
--- a/gcc/rust/resolve/rust-ast-resolve-stmt.cc
+++ b/gcc/rust/resolve/rust-ast-resolve-stmt.cc
@@ -16,6 +16,7 @@
 // along with GCC; see the file COPYING3.  If not see
 // <http://www.gnu.org/licenses/>.
 
+#include "rust-ast-resolve-toplevel.h"
 #include "rust-ast-resolve-item.h"
 #include "rust-ast-resolve-stmt.h"
 #include "rust-ast-resolve-implitem.h"
@@ -35,5 +36,26 @@ ResolveStmt::visit (AST::ExternBlock &extern_block)
     }
 }
 
+void
+ResolveStmt::visit (AST::Trait &trait)
+{
+  ResolveTopLevel::go (&trait, prefix, canonical_prefix);
+  ResolveItem::go (&trait, prefix, canonical_prefix);
+}
+
+void
+ResolveStmt::visit (AST::InherentImpl &impl_block)
+{
+  ResolveTopLevel::go (&impl_block, prefix, canonical_prefix);
+  ResolveItem::go (&impl_block, prefix, canonical_prefix);
+}
+
+void
+ResolveStmt::visit (AST::TraitImpl &impl_block)
+{
+  ResolveTopLevel::go (&impl_block, prefix, canonical_prefix);
+  ResolveItem::go (&impl_block, prefix, canonical_prefix);
+}
+
 } // namespace Resolver
 } // namespace Rust
diff --git a/gcc/rust/resolve/rust-ast-resolve-stmt.h b/gcc/rust/resolve/rust-ast-resolve-stmt.h
index 38219203450..99680684a59 100644
--- a/gcc/rust/resolve/rust-ast-resolve-stmt.h
+++ b/gcc/rust/resolve/rust-ast-resolve-stmt.h
@@ -359,6 +359,9 @@ public:
   }
 
   void visit (AST::ExternBlock &extern_block) override;
+  void visit (AST::Trait &trait) override;
+  void visit (AST::InherentImpl &impl_block) override;
+  void visit (AST::TraitImpl &impl_block) override;
 
 private:
   ResolveStmt (const CanonicalPath &prefix,
diff --git a/gcc/rust/typecheck/rust-hir-type-check-expr.cc b/gcc/rust/typecheck/rust-hir-type-check-expr.cc
index 60e63bcd542..101ed082a27 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-expr.cc
+++ b/gcc/rust/typecheck/rust-hir-type-check-expr.cc
@@ -1207,8 +1207,16 @@ TypeCheckExpr::visit (HIR::MethodCallExpr &expr)
   context->insert_type (expr.get_method_name ().get_mappings (), lookup);
 
   // set up the resolved name on the path
-  resolver->insert_resolved_name (expr.get_mappings ().get_nodeid (),
-				  resolved_node_id);
+  if (resolver->get_name_scope ().decl_was_declared_here (resolved_node_id))
+    {
+      resolver->insert_resolved_name (expr.get_mappings ().get_nodeid (),
+				      resolved_node_id);
+    }
+  else
+    {
+      resolver->insert_resolved_misc (expr.get_mappings ().get_nodeid (),
+				      resolved_node_id);
+    }
 
   // return the result of the function back
   infered = function_ret_tyty;
diff --git a/gcc/testsuite/rust/compile/issue-2238.rs b/gcc/testsuite/rust/compile/issue-2238.rs
new file mode 100644
index 00000000000..b0c7e36ea44
--- /dev/null
+++ b/gcc/testsuite/rust/compile/issue-2238.rs
@@ -0,0 +1,15 @@
+fn main() {
+    struct Foo;
+
+    trait Bar {
+        fn foo(&self);
+    }
+
+    impl Bar for Foo {
+        fn foo(&self) {}
+        // { dg-warning "unused name" "" { target *-*-* } .-1 }
+    }
+
+    let s = Foo;
+    s.foo();
+}

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2024-01-16 17:46 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-01-16 17:46 [gcc r14-7625] gccrs: Add missing name resolution to item statements Arthur Cohen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).