]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Change lookup_hir_type return type with an optional
authorPierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Fri, 3 May 2024 18:08:14 +0000 (20:08 +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 with an optional in order to tell
appart a null pointer from a missing value.

gcc/rust/ChangeLog:

* util/rust-hir-map.cc (Mappings::insert_hir_type): Change call site
to accomodate the new return type.
(Mappings::lookup_hir_type): 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 457e8af8ef0190ff44fff3b783101a86b881b38b..de6cb4d28b9150cc12bb3e50181f81690ca92522 100644 (file)
@@ -592,18 +592,18 @@ void
 Mappings::insert_hir_type (HIR::Type *type)
 {
   auto id = type->get_mappings ().get_hirid ();
-  rust_assert (lookup_hir_type (id) == nullptr);
+  rust_assert (!lookup_hir_type (id));
 
   hirTypeMappings[id] = type;
   insert_node_to_hir (type->get_mappings ().get_nodeid (), id);
 }
 
-HIR::Type *
+tl::optional<HIR::Type *>
 Mappings::lookup_hir_type (HirId id)
 {
   auto it = hirTypeMappings.find (id);
   if (it == hirTypeMappings.end ())
-    return nullptr;
+    return tl::nullopt;
 
   return it->second;
 }
index 2c15097e0ce4d6758429610fcabd738ad9783df3..583f63029b8327b34cc9b37298a6adc033062b35 100644 (file)
@@ -155,7 +155,7 @@ public:
   tl::optional<HIR::GenericParam *> lookup_hir_generic_param (HirId id);
 
   void insert_hir_type (HIR::Type *type);
-  HIR::Type *lookup_hir_type (HirId id);
+  tl::optional<HIR::Type *> lookup_hir_type (HirId id);
 
   void insert_hir_stmt (HIR::Stmt *stmt);
   HIR::Stmt *lookup_hir_stmt (HirId id);