From: Philip Herron <philip.her...@embecosm.com> When resolving local enum's within a Block the name resolution info is not at the top of the stack so this patch introduces a new mappings class for miscellaneous name resolutions which can be used during path analaysis.
Fixes #1272 gcc/rust/ChangeLog: * resolve/rust-name-resolver.h: Add miscellenaous item mappings. * resolve/rust-name-resolver.cc (Resolver::insert_resolved_misc): Use new mappings. (Resolver::lookup_resolved_misc): Likewise. * typecheck/rust-hir-type-check-path.cc (TypeCheckExpr::resolve_segments): Adapt function to insert into miscelleanous mappings. * checks/lints/rust-lint-marklive.cc (MarkLive::find_ref_node_id): Allow lookup in miscelleanous mappings in mark-live phase. gcc/testsuite/ChangeLog: * rust/compile/issue-1272.rs: New test. --- gcc/rust/checks/lints/rust-lint-marklive.cc | 7 +++++-- gcc/rust/resolve/rust-name-resolver.cc | 20 +++++++++++++++++++ gcc/rust/resolve/rust-name-resolver.h | 6 ++++++ .../typecheck/rust-hir-type-check-path.cc | 5 +++++ gcc/testsuite/rust/compile/issue-1272.rs | 8 ++++++++ 5 files changed, 44 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/rust/compile/issue-1272.rs diff --git a/gcc/rust/checks/lints/rust-lint-marklive.cc b/gcc/rust/checks/lints/rust-lint-marklive.cc index 14115c86f26..c914b549257 100644 --- a/gcc/rust/checks/lints/rust-lint-marklive.cc +++ b/gcc/rust/checks/lints/rust-lint-marklive.cc @@ -273,8 +273,11 @@ MarkLive::find_ref_node_id (NodeId ast_node_id, NodeId &ref_node_id) { if (!resolver->lookup_resolved_name (ast_node_id, &ref_node_id)) { - bool ok = resolver->lookup_resolved_type (ast_node_id, &ref_node_id); - rust_assert (ok); + if (!resolver->lookup_resolved_type (ast_node_id, &ref_node_id)) + { + bool ok = resolver->lookup_resolved_misc (ast_node_id, &ref_node_id); + rust_assert (ok); + } } } diff --git a/gcc/rust/resolve/rust-name-resolver.cc b/gcc/rust/resolve/rust-name-resolver.cc index 77d98d5f364..b94713d3c30 100644 --- a/gcc/rust/resolve/rust-name-resolver.cc +++ b/gcc/rust/resolve/rust-name-resolver.cc @@ -499,5 +499,25 @@ Resolver::lookup_resolved_macro (NodeId refId, NodeId *defId) return true; } +void +Resolver::insert_resolved_misc (NodeId refId, NodeId defId) +{ + auto it = misc_resolved_items.find (refId); + rust_assert (it == misc_resolved_items.end ()); + + misc_resolved_items[refId] = defId; +} + +bool +Resolver::lookup_resolved_misc (NodeId refId, NodeId *defId) +{ + auto it = misc_resolved_items.find (refId); + if (it == misc_resolved_items.end ()) + return false; + + *defId = it->second; + return true; +} + } // namespace Resolver } // namespace Rust diff --git a/gcc/rust/resolve/rust-name-resolver.h b/gcc/rust/resolve/rust-name-resolver.h index 6f4dda06a5c..302b0de15cc 100644 --- a/gcc/rust/resolve/rust-name-resolver.h +++ b/gcc/rust/resolve/rust-name-resolver.h @@ -126,6 +126,9 @@ public: void insert_resolved_macro (NodeId refId, NodeId defId); bool lookup_resolved_macro (NodeId refId, NodeId *defId); + void insert_resolved_misc (NodeId refId, NodeId defId); + bool lookup_resolved_misc (NodeId refId, NodeId *defId); + // proxy for scoping Scope &get_name_scope () { return name_scope; } Scope &get_type_scope () { return type_scope; } @@ -202,6 +205,9 @@ private: std::map<NodeId, NodeId> resolved_labels; std::map<NodeId, NodeId> resolved_macros; + // misc + std::map<NodeId, NodeId> misc_resolved_items; + // keep track of the current module scope ids std::vector<NodeId> current_module_stack; }; diff --git a/gcc/rust/typecheck/rust-hir-type-check-path.cc b/gcc/rust/typecheck/rust-hir-type-check-path.cc index f404ea64bcc..305d73f76f9 100644 --- a/gcc/rust/typecheck/rust-hir-type-check-path.cc +++ b/gcc/rust/typecheck/rust-hir-type-check-path.cc @@ -462,6 +462,11 @@ TypeCheckExpr::resolve_segments (NodeId root_resolved_node_id, resolver->insert_resolved_type (expr_mappings.get_nodeid (), resolved_node_id); } + else + { + resolver->insert_resolved_misc (expr_mappings.get_nodeid (), + resolved_node_id); + } infered = tyseg; } diff --git a/gcc/testsuite/rust/compile/issue-1272.rs b/gcc/testsuite/rust/compile/issue-1272.rs new file mode 100644 index 00000000000..08adaaf944b --- /dev/null +++ b/gcc/testsuite/rust/compile/issue-1272.rs @@ -0,0 +1,8 @@ +fn main() -> i32 { + enum E { + X(u8), + } + let _v = E::X(4); + + 0 +} -- 2.39.1