diff options
author | Philip Herron <herron.philip@googlemail.com> | 2023-05-30 13:45:58 +0100 |
---|---|---|
committer | Philip Herron <philip.herron@embecosm.com> | 2023-05-30 16:32:08 +0000 |
commit | bc2cac14138c5276562e8df83c01646e99a117ff (patch) | |
tree | d176a1ae08b175fef885cd2d8b517e6ee5576b8e | |
parent | d3412f6cdc6f1adee71d00cbed11faea8c5d3ef0 (diff) | |
download | gcc-bc2cac14138c5276562e8df83c01646e99a117ff.zip gcc-bc2cac14138c5276562e8df83c01646e99a117ff.tar.gz gcc-bc2cac14138c5276562e8df83c01646e99a117ff.tar.bz2 |
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>
-rw-r--r-- | gcc/rust/resolve/rust-ast-resolve-stmt.cc | 22 | ||||
-rw-r--r-- | gcc/rust/resolve/rust-ast-resolve-stmt.h | 3 | ||||
-rw-r--r-- | gcc/rust/typecheck/rust-hir-type-check-expr.cc | 12 | ||||
-rw-r--r-- | 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 2cbf6e0..9aad08d 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 52404f6..7511b22 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 221610e..c54ee79 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 0000000..b0c7e36 --- /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(); +} |