aboutsummaryrefslogtreecommitdiff
path: root/gcc/rust/util/rust-hir-map.cc
diff options
context:
space:
mode:
authorPierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>2024-04-25 14:54:23 +0200
committerArthur Cohen <arthur.cohen@embecosm.com>2025-03-17 16:35:23 +0100
commit7b90f5e5212b056dfac763b6a4e79b533dbe4f2b (patch)
tree267765ba0255c7a051b0ea27516b0d7d09f8dc83 /gcc/rust/util/rust-hir-map.cc
parent2d9d7036f3bc831f34972cf243f8012d45da0ff0 (diff)
downloadgcc-7b90f5e5212b056dfac763b6a4e79b533dbe4f2b.zip
gcc-7b90f5e5212b056dfac763b6a4e79b533dbe4f2b.tar.gz
gcc-7b90f5e5212b056dfac763b6a4e79b533dbe4f2b.tar.bz2
gccrs: Change return type of lookup_hir_trait_item
Change the return type to an optional instead of returning a null pointer. This allows easier tracking of rogue null pointers in the map. This commit also fixes a bug in trait associated function mangling, the function was using an already invalidated pointer. gcc/rust/ChangeLog: * backend/rust-compile-resolve-path.cc (HIRCompileBase::query_compile): Adapt return type to new optional. * backend/rust-mangle-v0.cc (v0_function_path): Change prototype to use the generic arguments vector instead of the whole HIR function. (v0_path): Fix a bug with a null pointer being used to create the trait function mangling. * util/rust-hir-map.cc (Mappings::insert_hir_trait_item): Adapt code to new return type. (Mappings::lookup_hir_trait_item): Change the return type of the function to an optional. * 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/rust-hir-map.cc')
-rw-r--r--gcc/rust/util/rust-hir-map.cc6
1 files changed, 3 insertions, 3 deletions
diff --git a/gcc/rust/util/rust-hir-map.cc b/gcc/rust/util/rust-hir-map.cc
index 535353b..0d134bf 100644
--- a/gcc/rust/util/rust-hir-map.cc
+++ b/gcc/rust/util/rust-hir-map.cc
@@ -406,18 +406,18 @@ void
Mappings::insert_hir_trait_item (HIR::TraitItem *item)
{
auto id = item->get_mappings ().get_hirid ();
- rust_assert (lookup_hir_trait_item (id) == nullptr);
+ rust_assert (!lookup_hir_trait_item (id).has_value ());
hirTraitItemMappings[id] = item;
insert_node_to_hir (item->get_mappings ().get_nodeid (), id);
}
-HIR::TraitItem *
+tl::optional<HIR::TraitItem *>
Mappings::lookup_hir_trait_item (HirId id)
{
auto it = hirTraitItemMappings.find (id);
if (it == hirTraitItemMappings.end ())
- return nullptr;
+ return tl::nullopt;
return it->second;
}