]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
gccrs: Change lookup_module function return type
authorPierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Fri, 3 May 2024 11:25:20 +0000 (13:25 +0200)
committerArthur Cohen <arthur.cohen@embecosm.com>
Mon, 17 Mar 2025 15:35:24 +0000 (16:35 +0100)
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 <pierre-emmanuel.patry@embecosm.com>
gcc/rust/checks/errors/privacy/rust-visibility-resolver.cc
gcc/rust/typecheck/rust-hir-type-check-path.cc
gcc/rust/typecheck/rust-hir-type-check-type.cc
gcc/rust/util/rust-hir-map.cc
gcc/rust/util/rust-hir-map.h

index 3066fee422bad69bd814a2b00bc8e95dfa239c4d..464ce86e1778229edfb22b968713af585c498b56 100644 (file)
@@ -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
index 0cc9f0e1203a890518501c29da3520a1c5c300f1..c6552099bed0c5be99bfd526d6a0ed1a64117e57 100644 (file)
@@ -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)
        {
index eb4abbbed3fe8b72885666f06831061da96ab203..2a3e35cd7b06ad36b190c89db57d5ff9c4be76ed 100644 (file)
@@ -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)
        {
index 7c4fd1ba0bd4e6d58c6c08ae30f45478bb4ee218..c77ffea354ef589d3b4cc898bbc94e1ee0487686 100644 (file)
@@ -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;
 }
index da3aa9f538932dabe1acdfe30cbdd4054aafc71b..753e06f796663fb3981f6dfd2bc7ace85a07dab0 100644 (file)
@@ -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);