diff options
author | Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com> | 2024-05-04 03:44:35 +0200 |
---|---|---|
committer | Arthur Cohen <arthur.cohen@embecosm.com> | 2025-03-17 16:35:27 +0100 |
commit | 3c1653b7b01cfad21fc1768dbfb6972e108bac30 (patch) | |
tree | b4cf85d1adb403d8f63cfe2579f7485908bd7a5f /gcc | |
parent | 1d7d56aab77fa53e3cba8a885208a07772d91a76 (diff) | |
download | gcc-3c1653b7b01cfad21fc1768dbfb6972e108bac30.zip gcc-3c1653b7b01cfad21fc1768dbfb6972e108bac30.tar.gz gcc-3c1653b7b01cfad21fc1768dbfb6972e108bac30.tar.bz2 |
gccrs: Change lookup_visibility's return type
Wrap the return type within an optional.
gcc/rust/ChangeLog:
* checks/errors/privacy/rust-privacy-reporter.cc: Change call site
to accomodate new return type.
* checks/errors/privacy/rust-pub-restricted-visitor.cc: Likewise.
* util/rust-hir-map.cc (Mappings::lookup_visibility): 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>
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/rust/checks/errors/privacy/rust-privacy-reporter.cc | 8 | ||||
-rw-r--r-- | gcc/rust/checks/errors/privacy/rust-pub-restricted-visitor.cc | 6 | ||||
-rw-r--r-- | gcc/rust/util/rust-hir-map.cc | 9 | ||||
-rw-r--r-- | gcc/rust/util/rust-hir-map.h | 2 |
4 files changed, 12 insertions, 13 deletions
diff --git a/gcc/rust/checks/errors/privacy/rust-privacy-reporter.cc b/gcc/rust/checks/errors/privacy/rust-privacy-reporter.cc index f8df9f7..d16d6ed 100644 --- a/gcc/rust/checks/errors/privacy/rust-privacy-reporter.cc +++ b/gcc/rust/checks/errors/privacy/rust-privacy-reporter.cc @@ -128,15 +128,15 @@ PrivacyReporter::check_for_privacy_violation (const NodeId &use_id, if (ref_node_id == UNKNOWN_NODEID) return; - ModuleVisibility vis; + auto vis = mappings.lookup_visibility (ref_node_id); // FIXME: Can we really return here if the item has no visibility? - if (!mappings.lookup_visibility (ref_node_id, vis)) + if (!vis) return; auto valid = true; - switch (vis.get_kind ()) + switch (vis->get_kind ()) { case ModuleVisibility::Public: break; @@ -146,7 +146,7 @@ PrivacyReporter::check_for_privacy_violation (const NodeId &use_id, if (!current_module.has_value ()) return; - auto module = mappings.lookup_defid (vis.get_module_id ()).value (); + auto module = mappings.lookup_defid (vis->get_module_id ()).value (); auto mod_node_id = module->get_mappings ().get_nodeid (); diff --git a/gcc/rust/checks/errors/privacy/rust-pub-restricted-visitor.cc b/gcc/rust/checks/errors/privacy/rust-pub-restricted-visitor.cc index bd11f50..7e6be1a 100644 --- a/gcc/rust/checks/errors/privacy/rust-pub-restricted-visitor.cc +++ b/gcc/rust/checks/errors/privacy/rust-pub-restricted-visitor.cc @@ -27,16 +27,16 @@ bool PubRestrictedVisitor::is_restriction_valid (NodeId item_id, const location_t locus) { - ModuleVisibility visibility; + auto visibility = mappings.lookup_visibility (item_id); // If there is no visibility in the mappings, then the item is private and // does not contain any restriction // FIXME: Is that correct? - if (!mappings.lookup_visibility (item_id, visibility)) + if (!visibility) return true; for (auto mod = module_stack.rbegin (); mod != module_stack.rend (); mod++) - if (*mod == visibility.get_module_id ()) + if (*mod == visibility->get_module_id ()) return true; rust_error_at (locus, "restricted path is not an ancestor of the " diff --git a/gcc/rust/util/rust-hir-map.cc b/gcc/rust/util/rust-hir-map.cc index 3b72119..7418fa4 100644 --- a/gcc/rust/util/rust-hir-map.cc +++ b/gcc/rust/util/rust-hir-map.cc @@ -1102,15 +1102,14 @@ Mappings::insert_visibility (NodeId id, Privacy::ModuleVisibility visibility) visibility_map.insert ({id, visibility}); } -bool -Mappings::lookup_visibility (NodeId id, Privacy::ModuleVisibility &def) +tl::optional<Privacy::ModuleVisibility &> +Mappings::lookup_visibility (NodeId id) { auto it = visibility_map.find (id); if (it == visibility_map.end ()) - return false; + return tl::nullopt; - def = it->second; - return true; + return it->second; } void diff --git a/gcc/rust/util/rust-hir-map.h b/gcc/rust/util/rust-hir-map.h index d80a15e..c70af5b 100644 --- a/gcc/rust/util/rust-hir-map.h +++ b/gcc/rust/util/rust-hir-map.h @@ -326,7 +326,7 @@ public: AttributeProcMacro def); void insert_visibility (NodeId id, Privacy::ModuleVisibility visibility); - bool lookup_visibility (NodeId id, Privacy::ModuleVisibility &def); + tl::optional<Privacy::ModuleVisibility &> lookup_visibility (NodeId id); void insert_ast_module (AST::Module *); tl::optional<AST::Module *> lookup_ast_module (NodeId id); |