aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>2024-05-03 19:40:18 +0200
committerP-E-P <32375388+P-E-P@users.noreply.github.com>2024-05-17 15:28:30 +0000
commit478c227c864f108a49ffa9bc695c0413e159c15c (patch)
treeb0907cd8f9ad70bfe4c1ea46076788a5a5aa4035
parent1fcb7198e46212a1689e190aca0e4803d9762e68 (diff)
downloadgcc-478c227c864f108a49ffa9bc695c0413e159c15c.zip
gcc-478c227c864f108a49ffa9bc695c0413e159c15c.tar.gz
gcc-478c227c864f108a49ffa9bc695c0413e159c15c.tar.bz2
Change lookup_hir_expr return type to optional
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>
-rw-r--r--gcc/rust/backend/rust-mangle-v0.cc6
-rw-r--r--gcc/rust/util/rust-hir-map.cc4
-rw-r--r--gcc/rust/util/rust-hir-map.h2
3 files changed, 5 insertions, 7 deletions
diff --git a/gcc/rust/backend/rust-mangle-v0.cc b/gcc/rust/backend/rust-mangle-v0.cc
index 6d9a59a..685236b 100644
--- a/gcc/rust/backend/rust-mangle-v0.cc
+++ b/gcc/rust/backend/rust-mangle-v0.cc
@@ -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);
diff --git a/gcc/rust/util/rust-hir-map.cc b/gcc/rust/util/rust-hir-map.cc
index 597c574..cfd2a58 100644
--- a/gcc/rust/util/rust-hir-map.cc
+++ b/gcc/rust/util/rust-hir-map.cc
@@ -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;
}
diff --git a/gcc/rust/util/rust-hir-map.h b/gcc/rust/util/rust-hir-map.h
index ec29976..6544935 100644
--- a/gcc/rust/util/rust-hir-map.h
+++ b/gcc/rust/util/rust-hir-map.h
@@ -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);