diff options
author | Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com> | 2024-04-24 22:32:54 +0200 |
---|---|---|
committer | Arthur Cohen <arthur.cohen@embecosm.com> | 2025-03-17 16:35:23 +0100 |
commit | af34aa18c6fa1f9ab88e63ce1ec03e1c5aaed69f (patch) | |
tree | 08aeef05493a924c4017d6e3cfd9790ad2ad3a11 /gcc/rust/backend/rust-compile-expr.cc | |
parent | 709371a1f09dd77a292a8555134aa2c54ce74728 (diff) | |
download | gcc-af34aa18c6fa1f9ab88e63ce1ec03e1c5aaed69f.zip gcc-af34aa18c6fa1f9ab88e63ce1ec03e1c5aaed69f.tar.gz gcc-af34aa18c6fa1f9ab88e63ce1ec03e1c5aaed69f.tar.bz2 |
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 <pierre-emmanuel.patry@embecosm.com>
Diffstat (limited to 'gcc/rust/backend/rust-compile-expr.cc')
-rw-r--r-- | gcc/rust/backend/rust-compile-expr.cc | 10 |
1 files changed, 6 insertions, 4 deletions
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<NodeId> 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}}")); |