From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 7905) id 6272F385828F; Tue, 16 Jan 2024 17:46:17 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6272F385828F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1705427177; bh=141s1sZFYg9Vn3qrsYajWslx9TzTsbnoWi1RYUpYnJw=; h=From:To:Subject:Date:From; b=Aj/LyZ+Xl0aeHEr45mvWYZZOn6/+WAN9tMTkpAhBIBujJc42asPdy+jGZJ8pBjawk Y4Q9nNYSNUmVj1PWy/ljorpuBBAtI4tMfU7S7TG5C79ayrUyvjaYFh7zjU/pOoljc0 0YjOiyZSOqaCyY9v61Vpg7yGEAx/Ju9KVcaoSEqw= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Arthur Cohen To: gcc-cvs@gcc.gnu.org Subject: [gcc r14-7625] gccrs: Add missing name resolution to item statements X-Act-Checkin: gcc X-Git-Author: Philip Herron X-Git-Refname: refs/heads/trunk X-Git-Oldrev: 546fbc6289b43ed59fc18d353084faf53c5bcced X-Git-Newrev: 56e29f4d5de8134db5f7772adc13154f3efccf43 Message-Id: <20240116174617.6272F385828F@sourceware.org> Date: Tue, 16 Jan 2024 17:46:17 +0000 (GMT) List-Id: https://gcc.gnu.org/g:56e29f4d5de8134db5f7772adc13154f3efccf43 commit r14-7625-g56e29f4d5de8134db5f7772adc13154f3efccf43 Author: Philip Herron 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 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 // . +#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(); +}