]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
gccrs: Change lookup_hir_struct_field return type
authorPierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Fri, 3 May 2024 18:48:10 +0000 (20:48 +0200)
committerArthur Cohen <arthur.cohen@embecosm.com>
Mon, 17 Mar 2025 15:35:25 +0000 (16:35 +0100)
Wrap the function's return type within an optional to differentiate
between a null pointer and a missing value.

gcc/rust/ChangeLog:

* util/rust-hir-map.cc (Mappings::insert_hir_struct_field): Change
call site to accomodate new return type.
(Mappings::lookup_hir_struct_field): 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 f124be8b9985766446f1974dca6de00ecb06cc49..d1f55a372ac12e1f273a322093d72bfaf1a526eb 100644 (file)
@@ -672,18 +672,18 @@ void
 Mappings::insert_hir_struct_field (HIR::StructExprField *field)
 {
   auto id = field->get_mappings ().get_hirid ();
-  rust_assert (lookup_hir_struct_field (id) == nullptr);
+  rust_assert (!lookup_hir_struct_field (id));
 
   hirStructFieldMappings[id] = field;
   insert_node_to_hir (field->get_mappings ().get_nodeid (), id);
 }
 
-HIR::StructExprField *
+tl::optional<HIR::StructExprField *>
 Mappings::lookup_hir_struct_field (HirId id)
 {
   auto it = hirStructFieldMappings.find (id);
   if (it == hirStructFieldMappings.end ())
-    return nullptr;
+    return tl::nullopt;
 
   return it->second;
 }
index 720dd976af47fb7b67a265f62393118d6726e81f..740a8e6d4998331a185861bd4647a9b89383a0fe 100644 (file)
@@ -167,7 +167,7 @@ public:
   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);
+  tl::optional<HIR::StructExprField *> lookup_hir_struct_field (HirId id);
 
   void insert_hir_pattern (HIR::Pattern *pattern);
   HIR::Pattern *lookup_hir_pattern (HirId id);