From: Philip Herron <philip.herron@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
@@ -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);
+ }
}
}
@@ -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
@@ -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;
};
@@ -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;
}
new file mode 100644
@@ -0,0 +1,8 @@
+fn main() -> i32 {
+ enum E {
+ X(u8),
+ }
+ let _v = E::X(4);
+
+ 0
+}