From: Pierre-Emmanuel Patry <[email protected]>
Wrap the return type into an optional.
gcc/rust/ChangeLog:
* checks/errors/privacy/rust-visibility-resolver.cc: Update function
call to match the new return type.
* typecheck/rust-hir-type-check-path.cc
(TypeCheckExpr::resolve_root_path):
Likewise.
* typecheck/rust-hir-type-check-type.cc
(TypeCheckType::resolve_root_path):
Likewise.
* util/rust-hir-map.cc (Mappings::insert_module): Likewise.
(Mappings::lookup_module): Change the function's return type.
* util/rust-hir-map.h: Update the function's prototype.
Signed-off-by: Pierre-Emmanuel Patry <[email protected]>
---
.../errors/privacy/rust-visibility-resolver.cc | 16 +++++++---------
gcc/rust/typecheck/rust-hir-type-check-path.cc | 2 +-
gcc/rust/typecheck/rust-hir-type-check-type.cc | 2 +-
gcc/rust/util/rust-hir-map.cc | 6 +++---
gcc/rust/util/rust-hir-map.h | 2 +-
5 files changed, 13 insertions(+), 15 deletions(-)
diff --git a/gcc/rust/checks/errors/privacy/rust-visibility-resolver.cc
b/gcc/rust/checks/errors/privacy/rust-visibility-resolver.cc
index 3066fee422b..464ce86e177 100644
--- a/gcc/rust/checks/errors/privacy/rust-visibility-resolver.cc
+++ b/gcc/rust/checks/errors/privacy/rust-visibility-resolver.cc
@@ -85,17 +85,15 @@ VisibilityResolver::resolve_module_path (const
HIR::SimplePath &restriction,
// these items as private?
return true;
- auto module = mappings.lookup_module (ref);
- if (!module)
+ if (auto module = mappings.lookup_module (ref))
{
- invalid_path.emit ();
- return false;
- }
+ // Fill in the resolved `DefId`
+ id = module.value ()->get_mappings ().get_defid ();
- // Fill in the resolved `DefId`
- id = module->get_mappings ().get_defid ();
-
- return true;
+ return true;
+ }
+ invalid_path.emit ();
+ return false;
}
bool
diff --git a/gcc/rust/typecheck/rust-hir-type-check-path.cc
b/gcc/rust/typecheck/rust-hir-type-check-path.cc
index 0cc9f0e1203..c6552099bed 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-path.cc
+++ b/gcc/rust/typecheck/rust-hir-type-check-path.cc
@@ -243,7 +243,7 @@ TypeCheckExpr::resolve_root_path (HIR::PathInExpression
&expr, size_t *offset,
}
auto ref = hid.value ();
- auto seg_is_module = (nullptr != mappings.lookup_module (ref));
+ auto seg_is_module = mappings.lookup_module (ref).has_value ();
auto seg_is_crate = mappings.is_local_hirid_crate (ref);
if (seg_is_module || seg_is_crate)
{
diff --git a/gcc/rust/typecheck/rust-hir-type-check-type.cc
b/gcc/rust/typecheck/rust-hir-type-check-type.cc
index eb4abbbed3f..2a3e35cd7b0 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-type.cc
+++ b/gcc/rust/typecheck/rust-hir-type-check-type.cc
@@ -391,7 +391,7 @@ TypeCheckType::resolve_root_path (HIR::TypePath &path,
size_t *offset,
}
auto ref = hid.value ();
- auto seg_is_module = (nullptr != mappings.lookup_module (ref));
+ auto seg_is_module = mappings.lookup_module (ref).has_value ();
auto seg_is_crate = mappings.is_local_hirid_crate (ref);
if (seg_is_module || seg_is_crate)
{
diff --git a/gcc/rust/util/rust-hir-map.cc b/gcc/rust/util/rust-hir-map.cc
index 7c4fd1ba0bd..c77ffea354e 100644
--- a/gcc/rust/util/rust-hir-map.cc
+++ b/gcc/rust/util/rust-hir-map.cc
@@ -489,18 +489,18 @@ void
Mappings::insert_module (HIR::Module *module)
{
auto id = module->get_mappings ().get_hirid ();
- rust_assert (lookup_module (id) == nullptr);
+ rust_assert (!lookup_module (id));
hirModuleMappings[id] = module;
insert_node_to_hir (module->get_mappings ().get_nodeid (), id);
}
-HIR::Module *
+tl::optional<HIR::Module *>
Mappings::lookup_module (HirId id)
{
auto it = hirModuleMappings.find (id);
if (it == hirModuleMappings.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 da3aa9f5389..753e06f7966 100644
--- a/gcc/rust/util/rust-hir-map.h
+++ b/gcc/rust/util/rust-hir-map.h
@@ -138,7 +138,7 @@ public:
tl::optional<HIR::ImplBlock *> lookup_impl_block_type (HirId id);
void insert_module (HIR::Module *module);
- HIR::Module *lookup_module (HirId id);
+ tl::optional<HIR::Module *> lookup_module (HirId id);
void insert_hir_implitem (HirId parent_impl_id, HIR::ImplItem *item);
HIR::ImplItem *lookup_hir_implitem (HirId id, HirId *parent_impl_id);
--
2.45.2