]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Change return type of lookup_impl_block_type
authorPierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Thu, 25 Apr 2024 13:39:33 +0000 (15:39 +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.

gcc/rust/ChangeLog:

* typecheck/rust-type-util.cc (query_type): Adapt code to accomodate
the new return type.
* util/rust-hir-map.cc (Mappings::lookup_impl_block_type): Change
the function's return type and remove the out pointer argument.
* util/rust-hir-map.h: Update the function's prototype.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
gcc/rust/typecheck/rust-type-util.cc
gcc/rust/util/rust-hir-map.cc
gcc/rust/util/rust-hir-map.h

index 7602d26eca2e5be6b211f747b1edb1fe97edd624..a278228e94f04ace3d38ea6960154cfa9e3151c9 100644 (file)
@@ -89,12 +89,10 @@ query_type (HirId reference, TyTy::BaseType **result)
     }
 
   // is it an impl_type?
-  HIR::ImplBlock *impl_block_by_type = nullptr;
-  bool found_impl_block_type
-    = mappings.lookup_impl_block_type (reference, &impl_block_by_type);
-  if (found_impl_block_type)
+  if (auto impl_block_by_type = mappings.lookup_impl_block_type (reference))
     {
-      *result = TypeCheckItem::ResolveImplBlockSelf (*impl_block_by_type);
+      *result
+       = TypeCheckItem::ResolveImplBlockSelf (*impl_block_by_type.value ());
       context->query_completed (reference);
       return true;
     }
index 7ddceb763accfd00b0235bffd5f41079ab9ac675..f8a0cb436cfa5bcc536c5ecb7a633ebe89526797 100644 (file)
@@ -486,15 +486,14 @@ Mappings::lookup_hir_impl_block (HirId id)
   return it->second;
 }
 
-bool
-Mappings::lookup_impl_block_type (HirId id, HIR::ImplBlock **impl_block)
+tl::optional<HIR::ImplBlock *>
+Mappings::lookup_impl_block_type (HirId id)
 {
   auto it = hirImplBlockTypeMappings.find (id);
   if (it == hirImplBlockTypeMappings.end ())
-    return false;
+    return tl::nullopt;
 
-  *impl_block = it->second;
-  return true;
+  return it->second;
 }
 
 void
index 17ee0fd4c82be39b34e7e09101d77afb79befe97..6d3763cd6b75a0c4094ea86610b41a1b35a993ef 100644 (file)
@@ -131,7 +131,7 @@ public:
 
   void insert_hir_impl_block (HIR::ImplBlock *item);
   tl::optional<HIR::ImplBlock *> lookup_hir_impl_block (HirId id);
-  bool lookup_impl_block_type (HirId id, HIR::ImplBlock **impl_block);
+  tl::optional<HIR::ImplBlock *> lookup_impl_block_type (HirId id);
 
   void insert_module (HIR::Module *module);
   HIR::Module *lookup_module (HirId id);