diff options
author | Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com> | 2024-05-04 04:10:08 +0200 |
---|---|---|
committer | Arthur Cohen <arthur.cohen@embecosm.com> | 2025-03-17 16:35:27 +0100 |
commit | ba56cdb52711990414a50dd52c853cefcdd23f53 (patch) | |
tree | d738b8c45e78231f8ae2c131774de65d3ee96c7a /gcc | |
parent | 3c1653b7b01cfad21fc1768dbfb6972e108bac30 (diff) | |
download | gcc-ba56cdb52711990414a50dd52c853cefcdd23f53.zip gcc-ba56cdb52711990414a50dd52c853cefcdd23f53.tar.gz gcc-ba56cdb52711990414a50dd52c853cefcdd23f53.tar.bz2 |
gccrs: Change lookup_ast_item's return type
Wrap the function's return type within an optional.
gcc/rust/ChangeLog:
* metadata/rust-export-metadata.cc (ExportContext::emit_trait):
Adapt call site to the new return type.
(ExportContext::emit_function): Likewise.
(ExportContext::emit_macro): Likewise.
* util/rust-hir-map.cc (Mappings::lookup_ast_item): Change the
function's return type.
* util/rust-hir-map.h: Update the function's prototype.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/rust/metadata/rust-export-metadata.cc | 15 | ||||
-rw-r--r-- | gcc/rust/util/rust-hir-map.cc | 9 | ||||
-rw-r--r-- | gcc/rust/util/rust-hir-map.h | 2 |
3 files changed, 10 insertions, 16 deletions
diff --git a/gcc/rust/metadata/rust-export-metadata.cc b/gcc/rust/metadata/rust-export-metadata.cc index 46afe35..79c5f30 100644 --- a/gcc/rust/metadata/rust-export-metadata.cc +++ b/gcc/rust/metadata/rust-export-metadata.cc @@ -56,10 +56,8 @@ void ExportContext::emit_trait (const HIR::Trait &trait) { // lookup the AST node for this - AST::Item *item = nullptr; - bool ok - = mappings.lookup_ast_item (trait.get_mappings ().get_nodeid (), &item); - rust_assert (ok); + AST::Item *item + = mappings.lookup_ast_item (trait.get_mappings ().get_nodeid ()).value (); std::stringstream oss; AST::Dump dumper (oss); @@ -72,9 +70,8 @@ void ExportContext::emit_function (const HIR::Function &fn) { // lookup the AST node for this - AST::Item *item = nullptr; - bool ok = mappings.lookup_ast_item (fn.get_mappings ().get_nodeid (), &item); - rust_assert (ok); + AST::Item *item + = mappings.lookup_ast_item (fn.get_mappings ().get_nodeid ()).value (); // is this a CFG macro or not if (item->is_marked_for_strip ()) @@ -119,9 +116,7 @@ ExportContext::emit_macro (NodeId macro) std::stringstream oss; AST::Dump dumper (oss); - AST::Item *item; - auto ok = mappings.lookup_ast_item (macro, &item); - rust_assert (ok); + AST::Item *item = mappings.lookup_ast_item (macro).value (); dumper.go (*item); diff --git a/gcc/rust/util/rust-hir-map.cc b/gcc/rust/util/rust-hir-map.cc index 7418fa4..03b3343 100644 --- a/gcc/rust/util/rust-hir-map.cc +++ b/gcc/rust/util/rust-hir-map.cc @@ -1225,15 +1225,14 @@ Mappings::insert_ast_item (AST::Item *item) ast_item_mappings[item->get_node_id ()] = item; } -bool -Mappings::lookup_ast_item (NodeId id, AST::Item **result) +tl::optional<AST::Item *> +Mappings::lookup_ast_item (NodeId id) { auto it = ast_item_mappings.find (id); if (it == ast_item_mappings.end ()) - return false; + return tl::nullopt; - *result = it->second; - return true; + return it->second; } HIR::ImplBlock * diff --git a/gcc/rust/util/rust-hir-map.h b/gcc/rust/util/rust-hir-map.h index c70af5b..bb7318e 100644 --- a/gcc/rust/util/rust-hir-map.h +++ b/gcc/rust/util/rust-hir-map.h @@ -345,7 +345,7 @@ public: bool node_is_module (NodeId query); void insert_ast_item (AST::Item *item); - bool lookup_ast_item (NodeId id, AST::Item **result); + tl::optional<AST::Item *> lookup_ast_item (NodeId id); HIR::ImplBlock *lookup_builtin_marker (); |