aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorPierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>2024-04-25 15:14:36 +0200
committerP-E-P <32375388+P-E-P@users.noreply.github.com>2024-05-17 15:28:30 +0000
commit6dbaa5dbfbaac28c96f0ecdc62a8d8479fcf6891 (patch)
tree3ec46fb721e4343ebd602c200860e078cec88823 /gcc
parentdcd38375635ff023a11e695fb2d88bdfb9665feb (diff)
downloadgcc-6dbaa5dbfbaac28c96f0ecdc62a8d8479fcf6891.zip
gcc-6dbaa5dbfbaac28c96f0ecdc62a8d8479fcf6891.tar.gz
gcc-6dbaa5dbfbaac28c96f0ecdc62a8d8479fcf6891.tar.bz2
Change return type of lookup_hir_extern_block
Change the return type to an optional in order to easily differentiate between a null pointer and an missing value. gcc/rust/ChangeLog: * checks/errors/rust-unsafe-checker.cc (UnsafeChecker::check_function_call): Adapt function call to new return type. * typecheck/rust-type-util.cc (query_type): Likewise. * util/rust-hir-map.cc (Mappings::insert_hir_extern_block): Likewise. (Mappings::lookup_hir_extern_block): Change 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>
Diffstat (limited to 'gcc')
-rw-r--r--gcc/rust/checks/errors/rust-unsafe-checker.cc2
-rw-r--r--gcc/rust/typecheck/rust-type-util.cc8
-rw-r--r--gcc/rust/util/rust-hir-map.cc6
-rw-r--r--gcc/rust/util/rust-hir-map.h2
4 files changed, 9 insertions, 9 deletions
diff --git a/gcc/rust/checks/errors/rust-unsafe-checker.cc b/gcc/rust/checks/errors/rust-unsafe-checker.cc
index 6b3b4a2..4a2bb0f 100644
--- a/gcc/rust/checks/errors/rust-unsafe-checker.cc
+++ b/gcc/rust/checks/errors/rust-unsafe-checker.cc
@@ -177,7 +177,7 @@ UnsafeChecker::check_function_call (HirId node_id, location_t locus)
if (maybe_extern)
check_extern_call (static_cast<ExternalItem *> (maybe_extern),
- mappings.lookup_hir_extern_block (parent_extern_block),
+ *mappings.lookup_hir_extern_block (parent_extern_block),
locus);
}
diff --git a/gcc/rust/typecheck/rust-type-util.cc b/gcc/rust/typecheck/rust-type-util.cc
index e96f5ed..1840a92 100644
--- a/gcc/rust/typecheck/rust-type-util.cc
+++ b/gcc/rust/typecheck/rust-type-util.cc
@@ -105,11 +105,11 @@ query_type (HirId reference, TyTy::BaseType **result)
= mappings.lookup_hir_extern_item (reference, &parent_extern_block_id);
if (extern_item != nullptr)
{
- HIR::ExternBlock *block
- = mappings.lookup_hir_extern_block (parent_extern_block_id);
- rust_assert (block != nullptr);
+ auto block = mappings.lookup_hir_extern_block (parent_extern_block_id);
+ rust_assert (block.has_value ());
- *result = TypeCheckTopLevelExternItem::Resolve (extern_item, *block);
+ *result
+ = TypeCheckTopLevelExternItem::Resolve (extern_item, *block.value ());
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 1cc0dd7..52de6d1 100644
--- a/gcc/rust/util/rust-hir-map.cc
+++ b/gcc/rust/util/rust-hir-map.cc
@@ -426,18 +426,18 @@ void
Mappings::insert_hir_extern_block (HIR::ExternBlock *block)
{
auto id = block->get_mappings ().get_hirid ();
- rust_assert (lookup_hir_extern_block (id) == nullptr);
+ rust_assert (!lookup_hir_extern_block (id).has_value ());
hirExternBlockMappings[id] = block;
insert_node_to_hir (block->get_mappings ().get_nodeid (), id);
}
-HIR::ExternBlock *
+tl::optional<HIR::ExternBlock *>
Mappings::lookup_hir_extern_block (HirId id)
{
auto it = hirExternBlockMappings.find (id);
if (it == hirExternBlockMappings.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 db40467..9415ac1 100644
--- a/gcc/rust/util/rust-hir-map.h
+++ b/gcc/rust/util/rust-hir-map.h
@@ -124,7 +124,7 @@ public:
tl::optional<HIR::TraitItem *> lookup_hir_trait_item (HirId id);
void insert_hir_extern_block (HIR::ExternBlock *block);
- HIR::ExternBlock *lookup_hir_extern_block (HirId id);
+ tl::optional<HIR::ExternBlock *> lookup_hir_extern_block (HirId id);
void insert_hir_extern_item (HIR::ExternalItem *item, HirId parent_block);
HIR::ExternalItem *lookup_hir_extern_item (HirId id, HirId *parent_block);