]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Change return type of lookup_hir_extern_block
authorPierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Thu, 25 Apr 2024 13:14:36 +0000 (15:14 +0200)
committerP-E-P <32375388+P-E-P@users.noreply.github.com>
Fri, 17 May 2024 15:28:30 +0000 (15:28 +0000)
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>
gcc/rust/checks/errors/rust-unsafe-checker.cc
gcc/rust/typecheck/rust-type-util.cc
gcc/rust/util/rust-hir-map.cc
gcc/rust/util/rust-hir-map.h

index 6b3b4a2ac113b8bc6ab069e82ab3dff50d744bb8..4a2bb0fc87e48812e56a3c8bb689c53566e4db2c 100644 (file)
@@ -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);
 }
 
index e96f5ed9359bf87f7279686fba50c8a96449249f..1840a92ef96a6626e1f0a94287422023e898c23d 100644 (file)
@@ -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;
     }
index 1cc0dd7fb73b6b192029256de54bde042ff5b2f6..52de6d1d867621255226bb93474e370eec8e4219 100644 (file)
@@ -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;
 }
index db404674b4a76a6d512539bea651b280c80de88d..9415ac122c57c755346dace2004f729c0d88e934 100644 (file)
@@ -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);