[gccrs COMMIT 17/19] privacy-reporter: Check for resolved nodes in more namespaces

gerris.rs@gmail.com gerris.rs@gmail.com
Thu Jun 4 13:13:50 GMT 2026


From: Arthur Cohen <arthur.cohen@embecosm.com>

And improve code factoring to reduce the complexity of the check_for_privacy_violation function.

gcc/rust/ChangeLog:

	* checks/errors/privacy/rust-privacy-reporter.cc
	(PrivacyReporter::check_for_privacy_violation): Add new overload for two namespaces.
	(PrivacyReporter::visit): Call it.
	(PrivacyReporter::check_violation_inner): New function.
	* checks/errors/privacy/rust-privacy-reporter.h: Declare it.
---
This change was merged into the gccrs repository and is posted here for
upstream visibility and potential drive-by review, as requested by GCC
release managers.
Each commit email contains a link to its details on github from where you can
find the Pull-Request and associated discussions.


Commit on github: https://github.com/Rust-GCC/gccrs/commit/3c36a62710bbb3629bf7fa4f5db23cd126260c94

The commit has NOT been mentioned in any issue.

The commit has been mentioned in the following pull-request(s):
 - https://github.com/Rust-GCC/gccrs/pull/4551

 .../errors/privacy/rust-privacy-reporter.cc   | 57 +++++++++++++------
 .../errors/privacy/rust-privacy-reporter.h    |  7 +++
 2 files changed, 48 insertions(+), 16 deletions(-)

diff --git a/gcc/rust/checks/errors/privacy/rust-privacy-reporter.cc b/gcc/rust/checks/errors/privacy/rust-privacy-reporter.cc
index 5d3c50ae3..9e2238f79 100644
--- a/gcc/rust/checks/errors/privacy/rust-privacy-reporter.cc
+++ b/gcc/rust/checks/errors/privacy/rust-privacy-reporter.cc
@@ -17,6 +17,7 @@
 // <http://www.gnu.org/licenses/>.
 
 #include "rust-privacy-reporter.h"
+#include "rust-hir-map.h"
 #include "rust-rib.h"
 #include "rust-session-manager.h"
 #include "rust-hir-expr.h"
@@ -92,21 +93,10 @@ PrivacyReporter::go (HIR::Crate &crate)
     }
 }
 
-// FIXME: This function needs a lot of refactoring
 void
-PrivacyReporter::check_for_privacy_violation (const NodeId &use_id,
-					      const location_t locus,
-					      Resolver2_0::Namespace ns)
+PrivacyReporter::check_violation_inner (NodeId ref_node_id,
+					const location_t locus)
 {
-  NodeId ref_node_id;
-
-  // FIXME: Assert here. For now, we return since this causes issues when
-  // checking inferred types (#1260)
-  if (auto id = resolver.lookup (use_id, ns))
-    ref_node_id = *id;
-  else
-    return;
-
   auto vis = mappings.lookup_visibility (ref_node_id);
 
   // FIXME: Can we really return here if the item has no visibility?
@@ -157,6 +147,41 @@ PrivacyReporter::check_for_privacy_violation (const NodeId &use_id,
     }
 }
 
+void
+PrivacyReporter::check_for_privacy_violation (const NodeId &use_id,
+					      const location_t locus,
+					      Resolver2_0::Namespace ns)
+{
+  NodeId ref_node_id;
+
+  // FIXME: Assert here. For now, we return since this causes issues when
+  // checking inferred types (#1260)
+  if (auto id = resolver.lookup (use_id, ns))
+    ref_node_id = *id;
+  else
+    return;
+
+  check_violation_inner (ref_node_id, locus);
+}
+
+void
+PrivacyReporter::check_for_privacy_violation (const NodeId &use_id,
+					      const location_t locus,
+					      Resolver2_0::Namespace ns1,
+					      Resolver2_0::Namespace ns2)
+{
+  NodeId ref_node_id;
+
+  // FIXME: Assert here. For now, we return since this causes issues when
+  // checking inferred types (#1260)
+  if (auto resolved = resolver.lookup (use_id, ns1, ns2))
+    ref_node_id = resolved->id;
+  else
+    return;
+
+  check_violation_inner (ref_node_id, locus);
+}
+
 void
 PrivacyReporter::check_base_type_privacy (Analysis::NodeMapping &node_mappings,
 					  const TyTy::BaseType *ty,
@@ -298,9 +323,9 @@ PrivacyReporter::visit (HIR::TypePath &path)
 void
 PrivacyReporter::visit (HIR::QualifiedPathInExpression &path)
 {
-  check_for_privacy_violation (
-    path.get_mappings ().get_nodeid (), path.get_locus (),
-    Resolver2_0::Namespace::Types /* FIXME: Is that correct? */);
+  check_for_privacy_violation (path.get_mappings ().get_nodeid (),
+			       path.get_locus (),
+			       Resolver2_0::Namespace::Values);
 }
 
 void
diff --git a/gcc/rust/checks/errors/privacy/rust-privacy-reporter.h b/gcc/rust/checks/errors/privacy/rust-privacy-reporter.h
index c735aa44a..07627b1d6 100644
--- a/gcc/rust/checks/errors/privacy/rust-privacy-reporter.h
+++ b/gcc/rust/checks/errors/privacy/rust-privacy-reporter.h
@@ -57,10 +57,17 @@ private:
    * @param use_id NodeId of the expression/statement referencing an item with
    * 		a visibility
    * @param locus Location of said expression/statement
+   * @param ns1, ns2 Namespaces in which to check for visibility
    */
   void check_for_privacy_violation (const NodeId &use_id,
 				    const location_t locus,
 				    Resolver2_0::Namespace ns);
+  void check_for_privacy_violation (const NodeId &use_id,
+				    const location_t locus,
+				    Resolver2_0::Namespace ns1,
+				    Resolver2_0::Namespace ns2);
+
+  void check_violation_inner (NodeId ref_node_id, const location_t inner);
 
   /**
    * Internal function used by `check_type_privacy` when dealing with complex
-- 
2.54.0



More information about the Gcc-rust mailing list