aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>2024-03-13 16:44:00 +0100
committerArthur Cohen <arthur.cohen@embecosm.com>2024-08-01 16:52:28 +0200
commit215139e7e81edb17447a97f7612b581eeedf8f20 (patch)
tree3aada3d61554104300f959511cf95583eb71f93a
parentb87c06fd351e0df489ac451b2b2a8c3c3c44ec72 (diff)
downloadgcc-215139e7e81edb17447a97f7612b581eeedf8f20.zip
gcc-215139e7e81edb17447a97f7612b581eeedf8f20.tar.gz
gcc-215139e7e81edb17447a97f7612b581eeedf8f20.tar.bz2
gccrs: Prevent getting immutable context with classic nr
Immutable name resolution context is not initialized when the classic name resolution is in use. It can therefore not be used, the getter would error out. gcc/rust/ChangeLog: * typecheck/rust-hir-type-check-path.cc (TypeCheckExpr::resolve_root_path): Only get immutable name resolution context when name resolution 2.0 is used. * typecheck/rust-hir-type-check-type.cc (TypeCheckType::resolve_root_path): Likewise. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
-rw-r--r--gcc/rust/typecheck/rust-hir-type-check-path.cc14
-rw-r--r--gcc/rust/typecheck/rust-hir-type-check-type.cc17
2 files changed, 17 insertions, 14 deletions
diff --git a/gcc/rust/typecheck/rust-hir-type-check-path.cc b/gcc/rust/typecheck/rust-hir-type-check-path.cc
index b0e52c4..dd6ab03 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-path.cc
+++ b/gcc/rust/typecheck/rust-hir-type-check-path.cc
@@ -199,16 +199,18 @@ TypeCheckExpr::resolve_root_path (HIR::PathInExpression &expr, size_t *offset,
bool is_root = *offset == 0;
NodeId ast_node_id = seg.get_mappings ().get_nodeid ();
- auto nr_ctx
- = Resolver2_0::ImmutableNameResolutionContext::get ().resolver ();
-
// then lookup the reference_node_id
NodeId ref_node_id = UNKNOWN_NODEID;
if (flag_name_resolution_2_0)
- // assign the ref_node_id if we've found something
- nr_ctx.lookup (expr.get_mappings ().get_nodeid ())
- .map ([&ref_node_id] (NodeId resolved) { ref_node_id = resolved; });
+ {
+ auto nr_ctx
+ = Resolver2_0::ImmutableNameResolutionContext::get ().resolver ();
+
+ // assign the ref_node_id if we've found something
+ nr_ctx.lookup (expr.get_mappings ().get_nodeid ())
+ .map ([&ref_node_id] (NodeId resolved) { ref_node_id = resolved; });
+ }
else if (!resolver->lookup_resolved_name (ast_node_id, &ref_node_id))
resolver->lookup_resolved_type (ast_node_id, &ref_node_id);
diff --git a/gcc/rust/typecheck/rust-hir-type-check-type.cc b/gcc/rust/typecheck/rust-hir-type-check-type.cc
index 588e5bc..44ebc15 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-type.cc
+++ b/gcc/rust/typecheck/rust-hir-type-check-type.cc
@@ -341,19 +341,20 @@ TypeCheckType::resolve_root_path (HIR::TypePath &path, size_t *offset,
bool is_root = *offset == 0;
NodeId ast_node_id = seg->get_mappings ().get_nodeid ();
- auto nr_ctx
- = Resolver2_0::ImmutableNameResolutionContext::get ().resolver ();
-
// then lookup the reference_node_id
NodeId ref_node_id = UNKNOWN_NODEID;
// FIXME: HACK: ARTHUR: Remove this
if (flag_name_resolution_2_0)
- // assign the ref_node_id if we've found something
- nr_ctx.lookup (path.get_mappings ().get_nodeid ())
- .map ([&ref_node_id, &path] (NodeId resolved) {
- ref_node_id = resolved;
- });
+ {
+ auto nr_ctx
+ = Resolver2_0::ImmutableNameResolutionContext::get ().resolver ();
+ // assign the ref_node_id if we've found something
+ nr_ctx.lookup (path.get_mappings ().get_nodeid ())
+ .map ([&ref_node_id, &path] (NodeId resolved) {
+ ref_node_id = resolved;
+ });
+ }
else if (!resolver->lookup_resolved_name (ast_node_id, &ref_node_id))
resolver->lookup_resolved_type (ast_node_id, &ref_node_id);