From 7b60cd3a7d24f630f904e0ec38a2cb9624016634 Mon Sep 17 00:00:00 2001 From: Owen Avery Date: Tue, 15 Oct 2024 14:56:04 -0400 Subject: [PATCH] Use name resolver 2.0 for compiling break/continue gcc/rust/ChangeLog: * backend/rust-compile-expr.cc (CompileExpr::visit): Use name resolver 2.0 to lookup label definitions for break and continue statements when name resolution 2.0 is enabled. Signed-off-by: Owen Avery --- gcc/rust/backend/rust-compile-expr.cc | 41 ++++++++++++++++++++++++--- 1 file changed, 37 insertions(+), 4 deletions(-) diff --git a/gcc/rust/backend/rust-compile-expr.cc b/gcc/rust/backend/rust-compile-expr.cc index 505303640cf..12c2fc883fc 100644 --- a/gcc/rust/backend/rust-compile-expr.cc +++ b/gcc/rust/backend/rust-compile-expr.cc @@ -753,8 +753,24 @@ CompileExpr::visit (HIR::BreakExpr &expr) if (expr.has_label ()) { NodeId resolved_node_id = UNKNOWN_NODEID; - if (!ctx->get_resolver ()->lookup_resolved_label ( - expr.get_label ().get_mappings ().get_nodeid (), &resolved_node_id)) + if (flag_name_resolution_2_0) + { + auto &nr_ctx + = Resolver2_0::ImmutableNameResolutionContext::get ().resolver (); + + if (auto id + = nr_ctx.lookup (expr.get_label ().get_mappings ().get_nodeid ())) + resolved_node_id = *id; + } + else + { + NodeId tmp = UNKNOWN_NODEID; + if (ctx->get_resolver ()->lookup_resolved_label ( + expr.get_label ().get_mappings ().get_nodeid (), &tmp)) + resolved_node_id = tmp; + } + + if (resolved_node_id == UNKNOWN_NODEID) { rust_error_at ( expr.get_label ().get_locus (), @@ -799,8 +815,25 @@ CompileExpr::visit (HIR::ContinueExpr &expr) if (expr.has_label ()) { NodeId resolved_node_id = UNKNOWN_NODEID; - if (!ctx->get_resolver ()->lookup_resolved_label ( - expr.get_label ().get_mappings ().get_nodeid (), &resolved_node_id)) + if (flag_name_resolution_2_0) + { + auto &nr_ctx + = Resolver2_0::ImmutableNameResolutionContext::get ().resolver (); + + if (auto id + = nr_ctx.lookup (expr.get_label ().get_mappings ().get_nodeid ())) + resolved_node_id = *id; + } + else + { + NodeId tmp = UNKNOWN_NODEID; + + if (ctx->get_resolver ()->lookup_resolved_label ( + expr.get_label ().get_mappings ().get_nodeid (), &tmp)) + resolved_node_id = tmp; + } + + if (resolved_node_id == UNKNOWN_NODEID) { rust_error_at ( expr.get_label ().get_locus (),