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/util | |
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/util')
-rw-r--r-- | gcc/rust/util/rust-hir-map.cc | 9 | ||||
-rw-r--r-- | gcc/rust/util/rust-hir-map.h | 2 |
2 files changed, 5 insertions, 6 deletions
diff --git a/gcc/rust/util/rust-hir-map.cc b/gcc/rust/util/rust-hir-map.cc index 78ce17d..b8d3937 100644 --- a/gcc/rust/util/rust-hir-map.cc +++ b/gcc/rust/util/rust-hir-map.cc @@ -779,15 +779,14 @@ Mappings::lookup_node_to_hir (NodeId id) return {it->second}; } -bool -Mappings::lookup_hir_to_node (HirId id, NodeId *ref) +tl::optional<NodeId> +Mappings::lookup_hir_to_node (HirId id) { auto it = hirIdToNodeMappings.find (id); if (it == hirIdToNodeMappings.end ()) - return false; + return tl::nullopt; - *ref = it->second; - return true; + return {it->second}; } void diff --git a/gcc/rust/util/rust-hir-map.h b/gcc/rust/util/rust-hir-map.h index c2b3e27..6fd0e7a 100644 --- a/gcc/rust/util/rust-hir-map.h +++ b/gcc/rust/util/rust-hir-map.h @@ -171,7 +171,7 @@ public: void insert_node_to_hir (NodeId id, HirId ref); tl::optional<HirId> lookup_node_to_hir (NodeId id); - bool lookup_hir_to_node (HirId id, NodeId *ref); + tl::optional<NodeId> lookup_hir_to_node (HirId id); void insert_location (HirId id, location_t locus); location_t lookup_location (HirId id); |