From af34aa18c6fa1f9ab88e63ce1ec03e1c5aaed69f Mon Sep 17 00:00:00 2001 From: Pierre-Emmanuel Patry Date: Wed, 24 Apr 2024 22:32:54 +0200 Subject: gccrs: Change lookup_hir_to_node return type to optional Optional are more convenient to use and avoid uninitialized data. gcc/rust/ChangeLog: * backend/rust-compile-expr.cc (CompileExpr::generate_closure_function): Adapt code for new optional return type. * checks/errors/privacy/rust-privacy-reporter.cc (PrivacyReporter::check_base_type_privacy): Likewise. * util/rust-hir-map.cc (Mappings::lookup_hir_to_node): Change return type to an optional. * util/rust-hir-map.h: Adapt function prototype with the new return type. Signed-off-by: Pierre-Emmanuel Patry --- gcc/rust/backend/rust-compile-expr.cc | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'gcc/rust/backend/rust-compile-expr.cc') diff --git a/gcc/rust/backend/rust-compile-expr.cc b/gcc/rust/backend/rust-compile-expr.cc index 28b901e..e2fa6dd 100644 --- a/gcc/rust/backend/rust-compile-expr.cc +++ b/gcc/rust/backend/rust-compile-expr.cc @@ -2216,10 +2216,12 @@ CompileExpr::generate_closure_function (HIR::ClosureExpr &expr, const Resolver::CanonicalPath &parent_canonical_path = closure_tyty.get_ident ().path; - NodeId node_id; - bool ok = ctx->get_mappings ().lookup_hir_to_node ( - expr.get_mappings ().get_hirid (), &node_id); - rust_assert (ok); + + tl::optional nid = ctx->get_mappings ().lookup_hir_to_node ( + expr.get_mappings ().get_hirid ()); + rust_assert (nid.has_value ()); + auto node_id = nid.value (); + Resolver::CanonicalPath path = parent_canonical_path.append ( Resolver::CanonicalPath::new_seg (node_id, "{{closure}}")); -- cgit v1.1