aboutsummaryrefslogtreecommitdiff
path: root/gcc/rust/util
diff options
context:
space:
mode:
authorPierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>2024-05-03 14:54:06 +0200
committerArthur Cohen <arthur.cohen@embecosm.com>2025-03-17 16:35:25 +0100
commitf7031e6a2cefc31f38604189ff3d98af2321aebb (patch)
treec9c34f4d078a1b540da684efbf2f6e9a74b2990b /gcc/rust/util
parentd75c82ef1750a60c6cbdd41f01ed814a07faaeec (diff)
downloadgcc-f7031e6a2cefc31f38604189ff3d98af2321aebb.zip
gcc-f7031e6a2cefc31f38604189ff3d98af2321aebb.tar.gz
gcc-f7031e6a2cefc31f38604189ff3d98af2321aebb.tar.bz2
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 <pierre-emmanuel.patry@embecosm.com>
Diffstat (limited to 'gcc/rust/util')
-rw-r--r--gcc/rust/util/rust-hir-map.cc10
-rw-r--r--gcc/rust/util/rust-hir-map.h7
2 files changed, 7 insertions, 10 deletions
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<HIR::TraitItem *>
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<DefId &> 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