From f7031e6a2cefc31f38604189ff3d98af2321aebb Mon Sep 17 00:00:00 2001 From: Pierre-Emmanuel Patry Date: Fri, 3 May 2024 14:54:06 +0200 Subject: gccrs: Change return type to optional in get_lang_item Wrap the function's return type with an optional. gcc/rust/ChangeLog: * typecheck/rust-autoderef.cc: Adapt calling code to new return type. * typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): Likewise. (TypeCheckExpr::resolve_operator_overload): Likewise. * typecheck/rust-tyty-bounds.cc (TypeBoundsProbe::assemble_builtin_candidate): Likewise. * typecheck/rust-tyty.cc (ClosureType::setup_fn_once_output): Likewise. * util/rust-hir-map.cc (Mappings::get_lang_item): Change return type. * util/rust-hir-map.h: Update the function's prototype. Signed-off-by: Pierre-Emmanuel Patry --- gcc/rust/util/rust-hir-map.cc | 10 ++++------ gcc/rust/util/rust-hir-map.h | 7 +++---- 2 files changed, 7 insertions(+), 10 deletions(-) (limited to 'gcc/rust/util') diff --git a/gcc/rust/util/rust-hir-map.cc b/gcc/rust/util/rust-hir-map.cc index c77ffea..4a78ae1 100644 --- a/gcc/rust/util/rust-hir-map.cc +++ b/gcc/rust/util/rust-hir-map.cc @@ -1253,13 +1253,11 @@ Mappings::lookup_builtin_marker () DefId Mappings::get_lang_item (LangItem::Kind item_type, location_t locus) { - DefId item = UNKNOWN_DEFID; - bool ok = lookup_lang_item (item_type, &item); - if (!ok) - rust_fatal_error (locus, "failed to find lang item %s", - LangItem::ToString (item_type).c_str ()); + if (auto item = lookup_lang_item (item_type)) + return *item; - return item; + rust_fatal_error (locus, "failed to find lang item %s", + LangItem::ToString (item_type).c_str ()); } tl::optional diff --git a/gcc/rust/util/rust-hir-map.h b/gcc/rust/util/rust-hir-map.h index 753e06f..3ca980e 100644 --- a/gcc/rust/util/rust-hir-map.h +++ b/gcc/rust/util/rust-hir-map.h @@ -267,14 +267,13 @@ public: lang_item_mappings[item_type] = id; } - bool lookup_lang_item (LangItem::Kind item_type, DefId *id) + tl::optional lookup_lang_item (LangItem::Kind item_type) { auto it = lang_item_mappings.find (item_type); if (it == lang_item_mappings.end ()) - return false; + return tl::nullopt; - *id = it->second; - return true; + return it->second; } // This will fatal_error when this lang item does not exist -- cgit v1.1