]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
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)
committerP-E-P <32375388+P-E-P@users.noreply.github.com>
Fri, 17 May 2024 15:28:30 +0000 (15:28 +0000)
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 5854b46562d3d631298b8cb816ef6211db5e087d..7110883750f5561bf8b5e1f42bcd21cf27b06be0 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 9e284f247fc319d82229a3b614b7ed667312cf36..d2962e6c2f1981f23a59fc64f915206d5666fe91 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 c7bfee5209765d3c28514d451370fd949674ce0c..36f64a770e90950d5d21a5cc5401a45ebc0d6c52 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 aee3ef87baecfae8dc18eb87fac808bcc3fb3185..97d7abfe290c2fccf2bcc1b6a818645bc4f38381 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 1171945ef5574e2fefd7a0f413a445a7781fecf6..b18c60c0e52658b6d012fd370c6736827759e238 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);