diff --git a/gcc/rust/metadata/rust-export-metadata.cc b/gcc/rust/metadata/rust-export-metadata.cc index 16f94018e9d3..8fde137c763a 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 26d24ee631f5..16a838d9c07c 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 +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 cc170dca4f39..c07f254a020d 100644 --- a/gcc/rust/util/rust-hir-map.h +++ b/gcc/rust/util/rust-hir-map.h @@ -345,7 +345,7 @@ class Mappings bool node_is_module (NodeId query); void insert_ast_item (AST::Item *item); - bool lookup_ast_item (NodeId id, AST::Item **result); + tl::optional lookup_ast_item (NodeId id); HIR::ImplBlock *lookup_builtin_marker ();