From: Pierre-Emmanuel Patry <[email protected]>
Make the API more convenient by changing the function's return type. We
can now differentiate between a stored null pointer and a missing value.
gcc/rust/ChangeLog:
* util/rust-hir-map.cc (Mappings::insert_defid_mapping): Adapt call
to new return type.
(Mappings::insert_local_defid_mapping): Likewise.
(Mappings::lookup_local_defid): Change return type to wrap it with an
optional.
* util/rust-hir-map.h: Update the function's prototype.
Signed-off-by: Pierre-Emmanuel Patry <[email protected]>
---
gcc/rust/util/rust-hir-map.cc | 12 ++++++------
gcc/rust/util/rust-hir-map.h | 3 ++-
2 files changed, 8 insertions(+), 7 deletions(-)
diff --git a/gcc/rust/util/rust-hir-map.cc b/gcc/rust/util/rust-hir-map.cc
index 899f71be49d..dcedea97e09 100644
--- a/gcc/rust/util/rust-hir-map.cc
+++ b/gcc/rust/util/rust-hir-map.cc
@@ -313,7 +313,7 @@ Mappings::insert_defid_mapping (DefId id, HIR::Item *item)
LocalDefId local_def_id = id.localDefId;
rust_assert (!lookup_defid (id));
- rust_assert (lookup_local_defid (crate_num, local_def_id) == nullptr);
+ rust_assert (!lookup_local_defid (crate_num, local_def_id));
rust_assert (lookup_trait_item_defid (id) == nullptr);
defIdMappings[id] = item;
@@ -337,7 +337,7 @@ Mappings::insert_defid_mapping (DefId id, HIR::TraitItem
*item)
LocalDefId local_def_id = id.localDefId;
rust_assert (!lookup_defid (id));
- rust_assert (lookup_local_defid (crate_num, local_def_id) == nullptr);
+ rust_assert (!lookup_local_defid (crate_num, local_def_id));
rust_assert (lookup_trait_item_defid (id) == nullptr);
defIdTraitItemMappings[id] = item;
@@ -718,20 +718,20 @@ void
Mappings::insert_local_defid_mapping (CrateNum crateNum, LocalDefId id,
HIR::Item *item)
{
- rust_assert (lookup_local_defid (crateNum, id) == nullptr);
+ rust_assert (!lookup_local_defid (crateNum, id));
localDefIdMappings[crateNum][id] = item;
}
-HIR::Item *
+tl::optional<HIR::Item *>
Mappings::lookup_local_defid (CrateNum crateNum, LocalDefId id)
{
auto it = localDefIdMappings.find (crateNum);
if (it == localDefIdMappings.end ())
- return nullptr;
+ return tl::nullopt;
auto iy = it->second.find (id);
if (iy == it->second.end ())
- return nullptr;
+ return tl::nullopt;
return iy->second;
}
diff --git a/gcc/rust/util/rust-hir-map.h b/gcc/rust/util/rust-hir-map.h
index 8a927c9ad4f..b4c39a94e82 100644
--- a/gcc/rust/util/rust-hir-map.h
+++ b/gcc/rust/util/rust-hir-map.h
@@ -112,7 +112,8 @@ public:
void insert_local_defid_mapping (CrateNum crateNum, LocalDefId id,
HIR::Item *item);
- HIR::Item *lookup_local_defid (CrateNum crateNum, LocalDefId id);
+ tl::optional<HIR::Item *> lookup_local_defid (CrateNum crateNum,
+ LocalDefId id);
void insert_hir_item (HIR::Item *item);
tl::optional<HIR::Item *> lookup_hir_item (HirId id);
--
2.45.2