aboutsummaryrefslogtreecommitdiff
path: root/gcc/rust/util
diff options
context:
space:
mode:
authorPierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>2024-04-25 10:48:47 +0200
committerArthur Cohen <arthur.cohen@embecosm.com>2025-03-17 16:35:23 +0100
commit2d9d7036f3bc831f34972cf243f8012d45da0ff0 (patch)
treef8bb517bc3d2c48067e1a5953d7e179443c6cdf2 /gcc/rust/util
parent97f03ba35810fcbb3a4e05128d323ba655d74acf (diff)
downloadgcc-2d9d7036f3bc831f34972cf243f8012d45da0ff0.zip
gcc-2d9d7036f3bc831f34972cf243f8012d45da0ff0.tar.gz
gcc-2d9d7036f3bc831f34972cf243f8012d45da0ff0.tar.bz2
gccrs: Change return type for lookup_hir_item to optional
gcc/rust/ChangeLog: * backend/rust-compile-resolve-path.cc (HIRCompileBase::query_compile): Adapt function call to new return type. * backend/rust-mangle-v0.cc (v0_path): Likewise. * checks/errors/rust-const-checker.cc (ConstChecker::check_function_call): Likewise. * checks/errors/rust-unsafe-checker.cc (UnsafeChecker::check_use_of_static): Likewise. (UnsafeChecker::check_function_call): Likewise. (UnsafeChecker::check_function_attr): Likewise. * checks/lints/rust-lint-marklive.cc (MarkLive::go): Likewise. (MarkLive::visit): Likewise. * typecheck/rust-hir-trait-resolve.cc (TraitResolver::resolve_path_to_trait): Likewise. * typecheck/rust-type-util.cc (query_type): Likewise. * util/rust-hir-map.cc (Mappings::insert_hir_item): Likewise. (Mappings::lookup_hir_item): Change function return type to use optional. * util/rust-hir-map.h: Update function 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.cc7
-rw-r--r--gcc/rust/util/rust-hir-map.h2
2 files changed, 4 insertions, 5 deletions
diff --git a/gcc/rust/util/rust-hir-map.cc b/gcc/rust/util/rust-hir-map.cc
index 57a7667..535353b 100644
--- a/gcc/rust/util/rust-hir-map.cc
+++ b/gcc/rust/util/rust-hir-map.cc
@@ -366,19 +366,18 @@ void
Mappings::insert_hir_item (HIR::Item *item)
{
auto id = item->get_mappings ().get_hirid ();
- rust_assert (lookup_hir_item (id) == nullptr);
+ rust_assert (!lookup_hir_item (id).has_value ());
hirItemMappings[id] = item;
insert_node_to_hir (item->get_mappings ().get_nodeid (), id);
}
-HIR::Item *
+tl::optional<HIR::Item *>
Mappings::lookup_hir_item (HirId id)
{
auto it = hirItemMappings.find (id);
if (it == hirItemMappings.end ())
- return nullptr;
-
+ return tl::nullopt;
return it->second;
}
diff --git a/gcc/rust/util/rust-hir-map.h b/gcc/rust/util/rust-hir-map.h
index 6ed3bee..e6df05b 100644
--- a/gcc/rust/util/rust-hir-map.h
+++ b/gcc/rust/util/rust-hir-map.h
@@ -115,7 +115,7 @@ public:
HIR::Item *lookup_local_defid (CrateNum crateNum, LocalDefId id);
void insert_hir_item (HIR::Item *item);
- HIR::Item *lookup_hir_item (HirId id);
+ tl::optional<HIR::Item *> lookup_hir_item (HirId id);
void insert_hir_enumitem (HIR::Enum *parent, HIR::EnumItem *item);
std::pair<HIR::Enum *, HIR::EnumItem *> lookup_hir_enumitem (HirId id);