]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Change lookup_hir_self_param return type
authorPierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Fri, 3 May 2024 18:42:06 +0000 (20:42 +0200)
committerP-E-P <32375388+P-E-P@users.noreply.github.com>
Fri, 17 May 2024 15:28:30 +0000 (15:28 +0000)
Wrap the function's return type within an optional in order to
differentiate null pointers from missing value.

gcc/rust/ChangeLog:

* util/rust-hir-map.cc (Mappings::insert_hir_self_param): Adapt call
site to new return type.
(Mappings::lookup_hir_self_param): Change the function's return type.
* util/rust-hir-map.h: Update the function's prototype.

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

index 3fb64960373930062c799c0f94177acafbb7edcb..c2c75abeb80116dd16132019ed13ca4676801d6f 100644 (file)
@@ -652,18 +652,18 @@ void
 Mappings::insert_hir_self_param (HIR::SelfParam *param)
 {
   auto id = param->get_mappings ().get_hirid ();
-  rust_assert (lookup_hir_self_param (id) == nullptr);
+  rust_assert (!lookup_hir_self_param (id));
 
   hirSelfParamMappings[id] = param;
   insert_node_to_hir (param->get_mappings ().get_nodeid (), id);
 }
 
-HIR::SelfParam *
+tl::optional<HIR::SelfParam *>
 Mappings::lookup_hir_self_param (HirId id)
 {
   auto it = hirSelfParamMappings.find (id);
   if (it == hirSelfParamMappings.end ())
-    return nullptr;
+    return tl::nullopt;
 
   return it->second;
 }
index f8c3cb1809c4c65b18dd323f5fd5f5ac4fb31a80..7e1f644b11ecfc3ce95f4d9cdb07d7804afbd654 100644 (file)
@@ -164,7 +164,7 @@ public:
   tl::optional<HIR::FunctionParam *> lookup_hir_param (HirId id);
 
   void insert_hir_self_param (HIR::SelfParam *type);
-  HIR::SelfParam *lookup_hir_self_param (HirId id);
+  tl::optional<HIR::SelfParam *> lookup_hir_self_param (HirId id);
 
   void insert_hir_struct_field (HIR::StructExprField *type);
   HIR::StructExprField *lookup_hir_struct_field (HirId id);