]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
gccrs: 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)
committerArthur Cohen <arthur.cohen@embecosm.com>
Mon, 17 Mar 2025 15:35:23 +0000 (16:35 +0100)
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 18e79e3ce6594a673bf0aacb48a6ea19571a4011..fc83283a795caddf501e71b99c1b79379a10b15d 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 f6f8c8e9e148334857f2bf41028097ec51ba536f..9a777863c2c2a4db8e86be10696ee8caecf0a17b 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 0d134bf4ab9fb31b204f8c368b77a74ccb186875..184ab13494dbb4ba1416189920cd1612141d8853 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 5565ef93f1c804d46e0d586e9ce0b33549b3036b..ef4d65639a07110c2bcfc17cac27196ab5de165a 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);