https://gcc.gnu.org/g:e956f3a7bbf0d1e31d15bc46bd3451172a9b8869
commit e956f3a7bbf0d1e31d15bc46bd3451172a9b8869 Author: Pierre-Emmanuel Patry <[email protected]> Date: Fri May 3 20:48:10 2024 +0200 Change lookup_hir_struct_field return type 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 <[email protected]> Diff: --- gcc/rust/util/rust-hir-map.cc | 6 +++--- gcc/rust/util/rust-hir-map.h | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/gcc/rust/util/rust-hir-map.cc b/gcc/rust/util/rust-hir-map.cc index c2c75abeb801..1e5d3221f2eb 100644 --- a/gcc/rust/util/rust-hir-map.cc +++ b/gcc/rust/util/rust-hir-map.cc @@ -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; } diff --git a/gcc/rust/util/rust-hir-map.h b/gcc/rust/util/rust-hir-map.h index 7e1f644b11ec..d613d7f5c59a 100644 --- a/gcc/rust/util/rust-hir-map.h +++ b/gcc/rust/util/rust-hir-map.h @@ -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);
