]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
gccrs: Change lookup_hir_path_expr_seg return type
authorPierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Fri, 3 May 2024 17:49:44 +0000 (19:49 +0200)
committerArthur Cohen <arthur.cohen@embecosm.com>
Mon, 17 Mar 2025 15:35:25 +0000 (16:35 +0100)
Make the function's return type optional in order to differentiate
between null pointers and missing value.

gcc/rust/ChangeLog:

* util/rust-hir-map.cc (Mappings::insert_hir_path_expr_seg): Change
call site to accomodate the new return type.
(Mappings::lookup_hir_path_expr_seg): Wrap the function's return type
with an optional.
* 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 80786490f82b04b072d340f89d5141161d3f18f4..c96743a54f881c5b1de179fdda342817c8b46d79 100644 (file)
@@ -550,19 +550,19 @@ void
 Mappings::insert_hir_path_expr_seg (HIR::PathExprSegment *expr)
 {
   auto id = expr->get_mappings ().get_hirid ();
-  rust_assert (lookup_hir_path_expr_seg (id) == nullptr);
+  rust_assert (!lookup_hir_path_expr_seg (id));
 
   hirPathSegMappings[id] = expr;
   insert_node_to_hir (expr->get_mappings ().get_nodeid (), id);
   insert_location (id, expr->get_locus ());
 }
 
-HIR::PathExprSegment *
+tl::optional<HIR::PathExprSegment *>
 Mappings::lookup_hir_path_expr_seg (HirId id)
 {
   auto it = hirPathSegMappings.find (id);
   if (it == hirPathSegMappings.end ())
-    return nullptr;
+    return tl::nullopt;
 
   return it->second;
 }
index 8d0f652a3d3c78cccfb6596f305bfeb6202b6701..c7d0838d4008ab95daa4ca588c09cac4a4b2db2c 100644 (file)
@@ -149,7 +149,7 @@ public:
   tl::optional<HIR::Expr *> lookup_hir_expr (HirId id);
 
   void insert_hir_path_expr_seg (HIR::PathExprSegment *expr);
-  HIR::PathExprSegment *lookup_hir_path_expr_seg (HirId id);
+  tl::optional<HIR::PathExprSegment *> lookup_hir_path_expr_seg (HirId id);
 
   void insert_hir_generic_param (HIR::GenericParam *expr);
   HIR::GenericParam *lookup_hir_generic_param (HirId id);