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

gcc/rust/ChangeLog:

* backend/rust-mangle-v0.cc (v0_path): Adapt call site to new returned
type.
* util/rust-hir-map.cc (Mappings::lookup_hir_expr): 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/backend/rust-mangle-v0.cc
gcc/rust/util/rust-hir-map.cc
gcc/rust/util/rust-hir-map.h

index 261e84405d5b210870e767b0c83f62839111267e..d604dcf725cd7797d6c0b8295a1ede2120dee67c 100644 (file)
@@ -384,8 +384,6 @@ v0_path (Rust::Compile::Context *ctx, const TyTy::BaseType *ty,
 
     auto hir_id = hid.value ();
 
-    HIR::Expr *expr = mappings.lookup_hir_expr (hir_id);
-
     if (auto impl_item = mappings.lookup_hir_implitem (hir_id))
       {
        switch (impl_item->first->get_impl_item_type ())
@@ -467,9 +465,9 @@ v0_path (Rust::Compile::Context *ctx, const TyTy::BaseType *ty,
                                  cpath.get ().c_str ());
          break;
        }
-    else if (expr != nullptr)
+    else if (auto expr = mappings.lookup_hir_expr (hir_id))
       {
-       rust_assert (expr->get_expression_type ()
+       rust_assert (expr.value ()->get_expression_type ()
                     == HIR::Expr::ExprType::Closure);
        // Use HIR ID as disambiguator.
        v0path = v0_closure (v0path, hir_id);
index 89c990d965fbd0a169c554eb08c93d8da9dcf5d0..80786490f82b04b072d340f89d5141161d3f18f4 100644 (file)
@@ -536,12 +536,12 @@ Mappings::insert_hir_expr (HIR::Expr *expr)
   insert_location (id, expr->get_locus ());
 }
 
-HIR::Expr *
+tl::optional<HIR::Expr *>
 Mappings::lookup_hir_expr (HirId id)
 {
   auto it = hirExprMappings.find (id);
   if (it == hirExprMappings.end ())
-    return nullptr;
+    return tl::nullopt;
 
   return it->second;
 }
index a587ccca7539c48109093495c3418003de14d324..8d0f652a3d3c78cccfb6596f305bfeb6202b6701 100644 (file)
@@ -146,7 +146,7 @@ public:
   lookup_hir_implitem (HirId id);
 
   void insert_hir_expr (HIR::Expr *expr);
-  HIR::Expr *lookup_hir_expr (HirId id);
+  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);