diff options
author | Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com> | 2024-04-25 15:28:32 +0200 |
---|---|---|
committer | P-E-P <32375388+P-E-P@users.noreply.github.com> | 2024-05-17 15:28:30 +0000 |
commit | 9af30ca752f66063ce199d94e374bb9c7db4e65c (patch) | |
tree | bd1d17a5d89c35cf9577f67c4d10796cc7390435 | |
parent | 6dbaa5dbfbaac28c96f0ecdc62a8d8479fcf6891 (diff) | |
download | gcc-9af30ca752f66063ce199d94e374bb9c7db4e65c.zip gcc-9af30ca752f66063ce199d94e374bb9c7db4e65c.tar.gz gcc-9af30ca752f66063ce199d94e374bb9c7db4e65c.tar.bz2 |
Change return type for lookup_hir_impl_block
Change the return type to an optiona. This allows to differentiate
between missing hir impl block and null pointers.
gcc/rust/ChangeLog:
* typecheck/rust-type-util.cc (query_type): Change call to the function
in order to accomodate the new return type.
* util/rust-hir-map.cc (Mappings::lookup_hir_impl_block): Change the
function's return type to an optional.
* util/rust-hir-map.h: Update the function's prototype.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
-rw-r--r-- | gcc/rust/typecheck/rust-type-util.cc | 8 | ||||
-rw-r--r-- | gcc/rust/util/rust-hir-map.cc | 6 | ||||
-rw-r--r-- | gcc/rust/util/rust-hir-map.h | 2 |
3 files changed, 8 insertions, 8 deletions
diff --git a/gcc/rust/typecheck/rust-type-util.cc b/gcc/rust/typecheck/rust-type-util.cc index 1840a92..7602d26 100644 --- a/gcc/rust/typecheck/rust-type-util.cc +++ b/gcc/rust/typecheck/rust-type-util.cc @@ -75,15 +75,15 @@ query_type (HirId reference, TyTy::BaseType **result) = mappings.lookup_hir_implitem (reference, &parent_impl_id); if (impl_item != nullptr) { - HIR::ImplBlock *impl_block - = mappings.lookup_hir_impl_block (parent_impl_id); - rust_assert (impl_block != nullptr); + auto impl_block = mappings.lookup_hir_impl_block (parent_impl_id); + rust_assert (impl_block); // found an impl item rust_debug_loc (impl_item->get_locus (), "resolved impl-item {%u} to", reference); - *result = TypeCheckItem::ResolveImplItem (*impl_block, *impl_item); + *result + = TypeCheckItem::ResolveImplItem (*impl_block.value (), *impl_item); context->query_completed (reference); return true; } diff --git a/gcc/rust/util/rust-hir-map.cc b/gcc/rust/util/rust-hir-map.cc index 52de6d1..7ddceb7 100644 --- a/gcc/rust/util/rust-hir-map.cc +++ b/gcc/rust/util/rust-hir-map.cc @@ -468,7 +468,7 @@ void Mappings::insert_hir_impl_block (HIR::ImplBlock *item) { auto id = item->get_mappings ().get_hirid (); - rust_assert (lookup_hir_impl_block (id) == nullptr); + rust_assert (!lookup_hir_impl_block (id)); HirId impl_type_id = item->get_type ()->get_mappings ().get_hirid (); hirImplBlockMappings[id] = item; @@ -476,12 +476,12 @@ Mappings::insert_hir_impl_block (HIR::ImplBlock *item) insert_node_to_hir (item->get_mappings ().get_nodeid (), id); } -HIR::ImplBlock * +tl::optional<HIR::ImplBlock *> Mappings::lookup_hir_impl_block (HirId id) { auto it = hirImplBlockMappings.find (id); if (it == hirImplBlockMappings.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 9415ac1..17ee0fd 100644 --- a/gcc/rust/util/rust-hir-map.h +++ b/gcc/rust/util/rust-hir-map.h @@ -130,7 +130,7 @@ public: HIR::ExternalItem *lookup_hir_extern_item (HirId id, HirId *parent_block); void insert_hir_impl_block (HIR::ImplBlock *item); - HIR::ImplBlock *lookup_hir_impl_block (HirId id); + tl::optional<HIR::ImplBlock *> lookup_hir_impl_block (HirId id); bool lookup_impl_block_type (HirId id, HIR::ImplBlock **impl_block); void insert_module (HIR::Module *module); |