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

gcc/rust/ChangeLog:

* util/rust-hir-map.cc (Mappings::insert_hir_pattern): Change call site
in order to accomodate new return type.
(Mappings::lookup_hir_pattern): 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 d1f55a372ac12e1f273a322093d72bfaf1a526eb..2ac614141a242df0e5e2660c65412cdde11b9ae7 100644 (file)
@@ -692,18 +692,18 @@ void
 Mappings::insert_hir_pattern (HIR::Pattern *pattern)
 {
   auto id = pattern->get_mappings ().get_hirid ();
-  rust_assert (lookup_hir_pattern (id) == nullptr);
+  rust_assert (!lookup_hir_pattern (id));
 
   hirPatternMappings[id] = pattern;
   insert_node_to_hir (pattern->get_mappings ().get_nodeid (), id);
 }
 
-HIR::Pattern *
+tl::optional<HIR::Pattern *>
 Mappings::lookup_hir_pattern (HirId id)
 {
   auto it = hirPatternMappings.find (id);
   if (it == hirPatternMappings.end ())
-    return nullptr;
+    return tl::nullopt;
 
   return it->second;
 }
index 740a8e6d4998331a185861bd4647a9b89383a0fe..c556d766b3595589e3849470294bbe4cc8f9d05f 100644 (file)
@@ -170,7 +170,7 @@ public:
   tl::optional<HIR::StructExprField *> lookup_hir_struct_field (HirId id);
 
   void insert_hir_pattern (HIR::Pattern *pattern);
-  HIR::Pattern *lookup_hir_pattern (HirId id);
+  tl::optional<HIR::Pattern *> lookup_hir_pattern (HirId id);
 
   void walk_local_defids_for_crate (CrateNum crateNum,
                                    std::function<bool (HIR::Item *)> cb);