public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc/devel/rust/master] privacy: PrivacyReporter: Add visitors for all expressions
@ 2022-06-08 12:47 Thomas Schwinge
  0 siblings, 0 replies; only message in thread
From: Thomas Schwinge @ 2022-06-08 12:47 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:dba78989e557246a0b4b53c020eb05b1130e6d42

commit dba78989e557246a0b4b53c020eb05b1130e6d42
Author: Arthur Cohen <arthur.cohen@embecosm.com>
Date:   Tue May 17 14:52:45 2022 +0200

    privacy: PrivacyReporter: Add visitors for all expressions

Diff:
---
 gcc/rust/privacy/rust-privacy-reporter.cc | 546 +++++++++++++++---------------
 gcc/rust/privacy/rust-privacy-reporter.h  |  90 ++---
 gcc/testsuite/rust/compile/privacy3.rs    |  28 ++
 gcc/testsuite/rust/compile/privacy4.rs    |  19 ++
 4 files changed, 340 insertions(+), 343 deletions(-)

diff --git a/gcc/rust/privacy/rust-privacy-reporter.cc b/gcc/rust/privacy/rust-privacy-reporter.cc
index 4c18adb8615..81200ebbac6 100644
--- a/gcc/rust/privacy/rust-privacy-reporter.cc
+++ b/gcc/rust/privacy/rust-privacy-reporter.cc
@@ -39,10 +39,13 @@ void
 PrivacyReporter::check_for_privacy_violation (const NodeId &use_id,
 					      const Location &locus)
 {
-  NodeId ref_node_id;
+  NodeId ref_node_id = UNKNOWN_NODEID;
 
   // FIXME: Don't assert here - we might be dealing with a type
-  rust_assert (resolver.lookup_resolved_name (use_id, &ref_node_id));
+  if (!resolver.lookup_resolved_name (use_id, &ref_node_id))
+    resolver.lookup_resolved_type (use_id, &ref_node_id);
+
+  rust_assert (ref_node_id != UNKNOWN_NODEID);
 
   ModuleVisibility vis;
 
@@ -93,14 +96,6 @@ void
 PrivacyReporter::visit (HIR::IdentifierExpr &ident_expr)
 {}
 
-void
-PrivacyReporter::visit (HIR::Lifetime &lifetime)
-{}
-
-void
-PrivacyReporter::visit (HIR::LifetimeParam &lifetime_param)
-{}
-
 void
 PrivacyReporter::visit (HIR::PathInExpression &path)
 {
@@ -108,105 +103,156 @@ PrivacyReporter::visit (HIR::PathInExpression &path)
 			       path.get_locus ());
 }
 
-void
-PrivacyReporter::visit (HIR::TypePathSegment &segment)
-{}
-
-void
-PrivacyReporter::visit (HIR::TypePathSegmentGeneric &segment)
-{}
-
 void
 PrivacyReporter::visit (HIR::TypePathSegmentFunction &segment)
-{}
+{
+  // FIXME: Do we need to do anything for this?
+}
 
 void
 PrivacyReporter::visit (HIR::TypePath &path)
-{}
+{
+  check_for_privacy_violation (path.get_mappings ().get_nodeid (),
+			       path.get_locus ());
+}
 
 void
 PrivacyReporter::visit (HIR::QualifiedPathInExpression &path)
-{}
+{
+  check_for_privacy_violation (path.get_mappings ().get_nodeid (),
+			       path.get_locus ());
+}
 
 void
 PrivacyReporter::visit (HIR::QualifiedPathInType &path)
-{}
+{
+  check_for_privacy_violation (path.get_mappings ().get_nodeid (),
+			       path.get_locus ());
+}
 
 void
 PrivacyReporter::visit (HIR::LiteralExpr &expr)
-{}
+{
+  // Literals cannot contain any sort of privacy violation
+}
 
 void
 PrivacyReporter::visit (HIR::BorrowExpr &expr)
-{}
+{
+  expr.get_expr ()->accept_vis (*this);
+}
 
 void
 PrivacyReporter::visit (HIR::DereferenceExpr &expr)
-{}
+{
+  expr.get_expr ()->accept_vis (*this);
+}
 
 void
 PrivacyReporter::visit (HIR::ErrorPropagationExpr &expr)
-{}
+{
+  expr.get_expr ()->accept_vis (*this);
+}
 
 void
 PrivacyReporter::visit (HIR::NegationExpr &expr)
-{}
+{
+  expr.get_expr ()->accept_vis (*this);
+}
 
 void
 PrivacyReporter::visit (HIR::ArithmeticOrLogicalExpr &expr)
-{}
+{
+  expr.get_lhs ()->accept_vis (*this);
+  expr.get_rhs ()->accept_vis (*this);
+}
 
 void
 PrivacyReporter::visit (HIR::ComparisonExpr &expr)
-{}
+{
+  expr.get_lhs ()->accept_vis (*this);
+  expr.get_rhs ()->accept_vis (*this);
+}
 
 void
 PrivacyReporter::visit (HIR::LazyBooleanExpr &expr)
-{}
+{
+  expr.get_lhs ()->accept_vis (*this);
+  expr.get_rhs ()->accept_vis (*this);
+}
 
 void
 PrivacyReporter::visit (HIR::TypeCastExpr &expr)
-{}
+{
+  expr.get_expr ()->accept_vis (*this);
+}
 
 void
 PrivacyReporter::visit (HIR::AssignmentExpr &expr)
-{}
+{
+  expr.get_lhs ()->accept_vis (*this);
+  expr.get_rhs ()->accept_vis (*this);
+}
 
 void
 PrivacyReporter::visit (HIR::CompoundAssignmentExpr &expr)
-{}
+{
+  expr.get_left_expr ()->accept_vis (*this);
+  expr.get_right_expr ()->accept_vis (*this);
+}
 
 void
 PrivacyReporter::visit (HIR::GroupedExpr &expr)
-{}
-
-void
-PrivacyReporter::visit (HIR::ArrayElemsValues &elems)
-{}
-
-void
-PrivacyReporter::visit (HIR::ArrayElemsCopied &elems)
-{}
+{
+  expr.get_expr_in_parens ()->accept_vis (*this);
+}
 
 void
 PrivacyReporter::visit (HIR::ArrayExpr &expr)
-{}
+{
+  HIR::ArrayElems &elements = *expr.get_internal_elements ();
+  switch (elements.get_array_expr_type ())
+    {
+      case HIR::ArrayElems::ArrayExprType::VALUES: {
+	HIR::ArrayElemsValues &elems
+	  = static_cast<HIR::ArrayElemsValues &> (elements);
+	for (auto &value : elems.get_values ())
+	  value->accept_vis (*this);
+      }
+      return;
+
+    case HIR::ArrayElems::ArrayExprType::COPIED:
+      HIR::ArrayElemsCopied &elems
+	= static_cast<HIR::ArrayElemsCopied &> (elements);
+      elems.get_elem_to_copy ()->accept_vis (*this);
+    }
+}
 
 void
 PrivacyReporter::visit (HIR::ArrayIndexExpr &expr)
-{}
+{
+  expr.get_array_expr ()->accept_vis (*this);
+  expr.get_index_expr ()->accept_vis (*this);
+}
 
 void
 PrivacyReporter::visit (HIR::TupleExpr &expr)
-{}
+{
+  for (auto &value : expr.get_tuple_elems ())
+    value->accept_vis (*this);
+}
 
 void
 PrivacyReporter::visit (HIR::TupleIndexExpr &expr)
-{}
+{
+  expr.get_tuple_expr ()->accept_vis (*this);
+}
 
 void
 PrivacyReporter::visit (HIR::StructExprStruct &expr)
-{}
+{
+  // FIXME: We need to check the visibility of the type it refers to here
+}
 
 void
 PrivacyReporter::visit (HIR::StructExprFieldIdentifier &field)
@@ -214,40 +260,54 @@ PrivacyReporter::visit (HIR::StructExprFieldIdentifier &field)
 
 void
 PrivacyReporter::visit (HIR::StructExprFieldIdentifierValue &field)
-{}
+{
+  field.get_value ()->accept_vis (*this);
+}
 
 void
 PrivacyReporter::visit (HIR::StructExprFieldIndexValue &field)
-{}
+{
+  field.get_value ()->accept_vis (*this);
+}
 
 void
 PrivacyReporter::visit (HIR::StructExprStructFields &expr)
-{}
-
-void
-PrivacyReporter::visit (HIR::StructExprStructBase &expr)
-{}
+{
+  for (auto &field : expr.get_fields ())
+    field->accept_vis (*this);
+}
 
 void
 PrivacyReporter::visit (HIR::CallExpr &expr)
 {
   expr.get_fnexpr ()->accept_vis (*this);
 
-  // rust_assert (mappings.lookup_visibility (definition_id, def_vis));
-  // check_for_privacy_violation (def_vis, expr.get_locus ());
+  for (auto &param : expr.get_arguments ())
+    param->accept_vis (*this);
 }
 
 void
 PrivacyReporter::visit (HIR::MethodCallExpr &expr)
-{}
+{
+  expr.get_receiver ()->accept_vis (*this);
+
+  for (auto &param : expr.get_arguments ())
+    param->accept_vis (*this);
+}
 
 void
 PrivacyReporter::visit (HIR::FieldAccessExpr &expr)
-{}
+{
+  expr.get_receiver_expr ()->accept_vis (*this);
+
+  // FIXME: We should also check if the field is public?
+}
 
 void
 PrivacyReporter::visit (HIR::ClosureExprInner &expr)
-{}
+{
+  // Not handled yet
+}
 
 void
 PrivacyReporter::visit (HIR::BlockExpr &expr)
@@ -262,7 +322,9 @@ PrivacyReporter::visit (HIR::BlockExpr &expr)
 
 void
 PrivacyReporter::visit (HIR::ClosureExprInnerTyped &expr)
-{}
+{
+  // Not handled yet
+}
 
 void
 PrivacyReporter::visit (HIR::ContinueExpr &expr)
@@ -270,19 +332,30 @@ PrivacyReporter::visit (HIR::ContinueExpr &expr)
 
 void
 PrivacyReporter::visit (HIR::BreakExpr &expr)
-{}
+{
+  auto &break_expr = expr.get_expr ();
+  if (break_expr)
+    break_expr->accept_vis (*this);
+}
 
 void
 PrivacyReporter::visit (HIR::RangeFromToExpr &expr)
-{}
+{
+  expr.get_from_expr ()->accept_vis (*this);
+  expr.get_to_expr ()->accept_vis (*this);
+}
 
 void
 PrivacyReporter::visit (HIR::RangeFromExpr &expr)
-{}
+{
+  expr.get_from_expr ()->accept_vis (*this);
+}
 
 void
 PrivacyReporter::visit (HIR::RangeToExpr &expr)
-{}
+{
+  expr.get_to_expr ()->accept_vis (*this);
+}
 
 void
 PrivacyReporter::visit (HIR::RangeFullExpr &expr)
@@ -290,95 +363,144 @@ PrivacyReporter::visit (HIR::RangeFullExpr &expr)
 
 void
 PrivacyReporter::visit (HIR::RangeFromToInclExpr &expr)
-{}
+{
+  expr.get_from_expr ()->accept_vis (*this);
+  expr.get_to_expr ()->accept_vis (*this);
+}
 
 void
 PrivacyReporter::visit (HIR::RangeToInclExpr &expr)
-{}
+{
+  // Not handled yet
+}
 
 void
 PrivacyReporter::visit (HIR::ReturnExpr &expr)
-{}
+{
+  auto return_expr = expr.get_expr ();
+  if (return_expr)
+    return_expr->accept_vis (*this);
+}
 
 void
 PrivacyReporter::visit (HIR::UnsafeBlockExpr &expr)
-{}
+{
+  expr.get_block_expr ()->accept_vis (*this);
+}
 
 void
 PrivacyReporter::visit (HIR::LoopExpr &expr)
-{}
+{
+  expr.get_loop_block ()->accept_vis (*this);
+}
 
 void
 PrivacyReporter::visit (HIR::WhileLoopExpr &expr)
-{}
+{
+  expr.get_predicate_expr ()->accept_vis (*this);
+  expr.get_loop_block ()->accept_vis (*this);
+}
 
 void
 PrivacyReporter::visit (HIR::WhileLetLoopExpr &expr)
-{}
+{
+  expr.get_cond ()->accept_vis (*this);
+  expr.get_loop_block ()->accept_vis (*this);
+}
 
 void
 PrivacyReporter::visit (HIR::ForLoopExpr &expr)
-{}
+{
+  expr.get_iterator_expr ()->accept_vis (*this);
+  expr.get_loop_block ()->accept_vis (*this);
+}
 
 void
 PrivacyReporter::visit (HIR::IfExpr &expr)
-{}
+{
+  expr.get_if_condition ()->accept_vis (*this);
+  expr.get_if_block ()->accept_vis (*this);
+}
 
 void
 PrivacyReporter::visit (HIR::IfExprConseqElse &expr)
-{}
+{
+  expr.get_if_condition ()->accept_vis (*this);
+  expr.get_if_block ()->accept_vis (*this);
+  expr.get_else_block ()->accept_vis (*this);
+}
 
 void
 PrivacyReporter::visit (HIR::IfExprConseqIf &expr)
-{}
+{
+  expr.get_if_condition ()->accept_vis (*this);
+  expr.get_if_block ()->accept_vis (*this);
+  expr.get_conseq_if_expr ()->accept_vis (*this);
+}
 
 void
 PrivacyReporter::visit (HIR::IfExprConseqIfLet &expr)
-{}
+{
+  expr.get_if_condition ()->accept_vis (*this);
+  expr.get_if_block ()->accept_vis (*this);
+
+  // TODO: We need to visit the if_let_expr as well
+}
 
 void
 PrivacyReporter::visit (HIR::IfLetExpr &expr)
-{}
+{
+  // TODO: We need to visit the if_let_expr
+  // TODO: We need to visit the block as well
+}
 
 void
 PrivacyReporter::visit (HIR::IfLetExprConseqElse &expr)
-{}
+{
+  // TODO: We need to visit the if_let_expr
+  // TODO: We need to visit the if_block as well
+  // TODO: We need to visit the else_block as well
+}
 
 void
 PrivacyReporter::visit (HIR::IfLetExprConseqIf &expr)
-{}
+{
+  // TODO: We need to visit the if_let_expr
+  // TODO: We need to visit the if_block as well
+  // TODO: We need to visit the else_block as well
+}
 
 void
 PrivacyReporter::visit (HIR::IfLetExprConseqIfLet &expr)
-{}
+{
+  // TODO: We need to visit the if_let_expr
+  // TODO: We need to visit the if_block as well
+  // TODO: We need to visit the else_block as well
+}
 
 void
 PrivacyReporter::visit (HIR::MatchExpr &expr)
-{}
+{
+  expr.get_scrutinee_expr ()->accept_vis (*this);
+}
 
 void
 PrivacyReporter::visit (HIR::AwaitExpr &expr)
-{}
+{
+  // Not handled yet
+}
 
 void
 PrivacyReporter::visit (HIR::AsyncBlockExpr &expr)
-{}
-
-void
-PrivacyReporter::visit (HIR::TypeParam &param)
-{}
-
-void
-PrivacyReporter::visit (HIR::LifetimeWhereClauseItem &item)
-{}
-
-void
-PrivacyReporter::visit (HIR::TypeBoundWhereClauseItem &item)
-{}
+{
+  // Not handled yet
+}
 
 void
 PrivacyReporter::visit (HIR::Module &module)
 {
+  // FIXME: We also need to think about module privacy
+
   auto old_module = current_module;
   current_module
     = Optional<NodeId>::some (module.get_mappings ().get_nodeid ());
@@ -393,21 +515,11 @@ void
 PrivacyReporter::visit (HIR::ExternCrate &crate)
 {}
 
-void
-PrivacyReporter::visit (HIR::UseTreeGlob &use_tree)
-{}
-
-void
-PrivacyReporter::visit (HIR::UseTreeList &use_tree)
-{}
-
-void
-PrivacyReporter::visit (HIR::UseTreeRebind &use_tree)
-{}
-
 void
 PrivacyReporter::visit (HIR::UseDeclaration &use_decl)
-{}
+{
+  // FIXME: Is there anything we need to do here?
+}
 
 void
 PrivacyReporter::visit (HIR::Function &function)
@@ -417,27 +529,39 @@ PrivacyReporter::visit (HIR::Function &function)
 
 void
 PrivacyReporter::visit (HIR::TypeAlias &type_alias)
-{}
+{
+  // TODO: Check the type here
+}
 
 void
 PrivacyReporter::visit (HIR::StructStruct &struct_item)
-{}
+{
+  // TODO: Check the type of all fields
+}
 
 void
 PrivacyReporter::visit (HIR::TupleStruct &tuple_struct)
-{}
+{
+  // TODO: Check the type of all fields
+}
 
 void
 PrivacyReporter::visit (HIR::EnumItem &item)
-{}
+{
+  // TODO: Check the type of all variants
+}
 
 void
 PrivacyReporter::visit (HIR::EnumItemTuple &item)
-{}
+{
+  // TODO: Check the type
+}
 
 void
 PrivacyReporter::visit (HIR::EnumItemStruct &item)
-{}
+{
+  // TODO: Check the type
+}
 
 void
 PrivacyReporter::visit (HIR::EnumItemDiscriminant &item)
@@ -449,127 +573,46 @@ PrivacyReporter::visit (HIR::Enum &enum_item)
 
 void
 PrivacyReporter::visit (HIR::Union &union_item)
-{}
+{
+  // TODO: Check the type
+}
 
 void
 PrivacyReporter::visit (HIR::ConstantItem &const_item)
-{}
+{
+  // TODO: We need to visit the type
+  const_item.get_expr ()->accept_vis (*this);
+}
 
 void
 PrivacyReporter::visit (HIR::StaticItem &static_item)
-{}
-
-void
-PrivacyReporter::visit (HIR::TraitItemFunc &item)
-{}
-
-void
-PrivacyReporter::visit (HIR::TraitItemConst &item)
-{}
-
-void
-PrivacyReporter::visit (HIR::TraitItemType &item)
-{}
+{
+  // TODO: We need to visit the type
+  static_item.get_expr ()->accept_vis (*this);
+}
 
 void
 PrivacyReporter::visit (HIR::Trait &trait)
-{}
+{
+  // FIXME: We need to be an ItemVisitor as well
+  // for (auto &item : trait.get_trait_items ())
+  //   item->accept_vis (*this);
+}
 
 void
 PrivacyReporter::visit (HIR::ImplBlock &impl)
-{}
-
-void
-PrivacyReporter::visit (HIR::ExternalStaticItem &item)
-{}
-
-void
-PrivacyReporter::visit (HIR::ExternalFunctionItem &item)
-{}
+{
+  for (auto &item : impl.get_impl_items ())
+    item->accept_vis (*this);
+}
 
 void
 PrivacyReporter::visit (HIR::ExternBlock &block)
-{}
-
-void
-PrivacyReporter::visit (HIR::LiteralPattern &pattern)
-{}
-
-void
-PrivacyReporter::visit (HIR::IdentifierPattern &pattern)
-{}
-
-void
-PrivacyReporter::visit (HIR::WildcardPattern &pattern)
-{}
-
-void
-PrivacyReporter::visit (HIR::RangePatternBoundLiteral &bound)
-{}
-
-void
-PrivacyReporter::visit (HIR::RangePatternBoundPath &bound)
-{}
-
-void
-PrivacyReporter::visit (HIR::RangePatternBoundQualPath &bound)
-{}
-
-void
-PrivacyReporter::visit (HIR::RangePattern &pattern)
-{}
-
-void
-PrivacyReporter::visit (HIR::ReferencePattern &pattern)
-{}
-
-void
-PrivacyReporter::visit (HIR::StructPatternFieldTuplePat &field)
-{}
-
-void
-PrivacyReporter::visit (HIR::StructPatternFieldIdentPat &field)
-{}
-
-void
-PrivacyReporter::visit (HIR::StructPatternFieldIdent &field)
-{}
-
-void
-PrivacyReporter::visit (HIR::StructPattern &pattern)
-{}
-
-void
-PrivacyReporter::visit (HIR::TupleStructItemsNoRange &tuple_items)
-{}
-
-void
-PrivacyReporter::visit (HIR::TupleStructItemsRange &tuple_items)
-{}
-
-void
-PrivacyReporter::visit (HIR::TupleStructPattern &pattern)
-{}
-
-void
-PrivacyReporter::visit (HIR::TuplePatternItemsMultiple &tuple_items)
-{}
-
-void
-PrivacyReporter::visit (HIR::TuplePatternItemsRanged &tuple_items)
-{}
-
-void
-PrivacyReporter::visit (HIR::TuplePattern &pattern)
-{}
-
-void
-PrivacyReporter::visit (HIR::GroupedPattern &pattern)
-{}
-
-void
-PrivacyReporter::visit (HIR::SlicePattern &pattern)
-{}
+{
+  // FIXME: We need to be an ItemVisitor as well
+  // for (auto &item : block.get_extern_items ())
+  //   item->accept_vis (*this);
+}
 
 void
 PrivacyReporter::visit (HIR::EmptyStmt &stmt)
@@ -577,7 +620,12 @@ PrivacyReporter::visit (HIR::EmptyStmt &stmt)
 
 void
 PrivacyReporter::visit (HIR::LetStmt &stmt)
-{}
+{
+  // FIXME: We probably have to check the type as well
+  auto init_expr = stmt.get_init_expr ();
+  if (init_expr)
+    init_expr->accept_vis (*this);
+}
 
 void
 PrivacyReporter::visit (HIR::ExprStmtWithoutBlock &stmt)
@@ -587,59 +635,9 @@ PrivacyReporter::visit (HIR::ExprStmtWithoutBlock &stmt)
 
 void
 PrivacyReporter::visit (HIR::ExprStmtWithBlock &stmt)
-{}
-
-void
-PrivacyReporter::visit (HIR::TraitBound &bound)
-{}
-
-void
-PrivacyReporter::visit (HIR::ImplTraitType &type)
-{}
-
-void
-PrivacyReporter::visit (HIR::TraitObjectType &type)
-{}
-
-void
-PrivacyReporter::visit (HIR::ParenthesisedType &type)
-{}
-
-void
-PrivacyReporter::visit (HIR::ImplTraitTypeOneBound &type)
-{}
-
-void
-PrivacyReporter::visit (HIR::TupleType &type)
-{}
-
-void
-PrivacyReporter::visit (HIR::NeverType &type)
-{}
-
-void
-PrivacyReporter::visit (HIR::RawPointerType &type)
-{}
-
-void
-PrivacyReporter::visit (HIR::ReferenceType &type)
-{}
-
-void
-PrivacyReporter::visit (HIR::ArrayType &type)
-{}
-
-void
-PrivacyReporter::visit (HIR::SliceType &type)
-{}
-
-void
-PrivacyReporter::visit (HIR::InferredType &type)
-{}
-
-void
-PrivacyReporter::visit (HIR::BareFunctionType &type)
-{}
+{
+  stmt.get_expr ()->accept_vis (*this);
+}
 
 } // namespace Privacy
 } // namespace Rust
diff --git a/gcc/rust/privacy/rust-privacy-reporter.h b/gcc/rust/privacy/rust-privacy-reporter.h
index fafcec1edac..868428a7c98 100644
--- a/gcc/rust/privacy/rust-privacy-reporter.h
+++ b/gcc/rust/privacy/rust-privacy-reporter.h
@@ -32,7 +32,8 @@ namespace Privacy {
  * violations. It should be started after using the `VisibilityResolver` visitor
  * which resolves the visibilities of all items of a crate.
  */
-class PrivacyReporter : public HIR::HIRFullVisitor
+class PrivacyReporter : public HIR::HIRExpressionVisitor,
+			public HIR::HIRStmtVisitor
 {
 public:
   PrivacyReporter (Analysis::Mappings &mappings,
@@ -56,16 +57,17 @@ private:
   void check_for_privacy_violation (const NodeId &use_id,
 				    const Location &locus);
 
+  virtual void visit (HIR::StructExprFieldIdentifier &field);
+  virtual void visit (HIR::StructExprFieldIdentifierValue &field);
+  virtual void visit (HIR::StructExprFieldIndexValue &field);
+
+  virtual void visit (HIR::QualifiedPathInExpression &expr);
+  virtual void visit (HIR::PathInExpression &expr);
+  virtual void visit (HIR::ClosureExprInnerTyped &);
+  virtual void visit (HIR::ClosureExprInner &expr);
+  virtual void visit (HIR::StructExprStructFields &);
+  virtual void visit (HIR::StructExprStruct &);
   virtual void visit (HIR::IdentifierExpr &ident_expr);
-  virtual void visit (HIR::Lifetime &lifetime);
-  virtual void visit (HIR::LifetimeParam &lifetime_param);
-  virtual void visit (HIR::PathInExpression &path);
-  virtual void visit (HIR::TypePathSegment &segment);
-  virtual void visit (HIR::TypePathSegmentGeneric &segment);
-  virtual void visit (HIR::TypePathSegmentFunction &segment);
-  virtual void visit (HIR::TypePath &path);
-  virtual void visit (HIR::QualifiedPathInExpression &path);
-  virtual void visit (HIR::QualifiedPathInType &path);
   virtual void visit (HIR::LiteralExpr &expr);
   virtual void visit (HIR::BorrowExpr &expr);
   virtual void visit (HIR::DereferenceExpr &expr);
@@ -78,24 +80,14 @@ private:
   virtual void visit (HIR::AssignmentExpr &expr);
   virtual void visit (HIR::CompoundAssignmentExpr &expr);
   virtual void visit (HIR::GroupedExpr &expr);
-  virtual void visit (HIR::ArrayElemsValues &elems);
-  virtual void visit (HIR::ArrayElemsCopied &elems);
   virtual void visit (HIR::ArrayExpr &expr);
   virtual void visit (HIR::ArrayIndexExpr &expr);
   virtual void visit (HIR::TupleExpr &expr);
   virtual void visit (HIR::TupleIndexExpr &expr);
-  virtual void visit (HIR::StructExprStruct &expr);
-  virtual void visit (HIR::StructExprFieldIdentifier &field);
-  virtual void visit (HIR::StructExprFieldIdentifierValue &field);
-  virtual void visit (HIR::StructExprFieldIndexValue &field);
-  virtual void visit (HIR::StructExprStructFields &expr);
-  virtual void visit (HIR::StructExprStructBase &expr);
   virtual void visit (HIR::CallExpr &expr);
   virtual void visit (HIR::MethodCallExpr &expr);
   virtual void visit (HIR::FieldAccessExpr &expr);
-  virtual void visit (HIR::ClosureExprInner &expr);
   virtual void visit (HIR::BlockExpr &expr);
-  virtual void visit (HIR::ClosureExprInnerTyped &expr);
   virtual void visit (HIR::ContinueExpr &expr);
   virtual void visit (HIR::BreakExpr &expr);
   virtual void visit (HIR::RangeFromToExpr &expr);
@@ -121,72 +113,32 @@ private:
   virtual void visit (HIR::MatchExpr &expr);
   virtual void visit (HIR::AwaitExpr &expr);
   virtual void visit (HIR::AsyncBlockExpr &expr);
-  virtual void visit (HIR::TypeParam &param);
-  virtual void visit (HIR::LifetimeWhereClauseItem &item);
-  virtual void visit (HIR::TypeBoundWhereClauseItem &item);
+
+  virtual void visit (HIR::EnumItemTuple &);
+  virtual void visit (HIR::EnumItemStruct &);
+  virtual void visit (HIR::EnumItem &item);
+  virtual void visit (HIR::TupleStruct &tuple_struct);
+  virtual void visit (HIR::EnumItemDiscriminant &);
+  virtual void visit (HIR::TypePathSegmentFunction &segment);
+  virtual void visit (HIR::TypePath &path);
+  virtual void visit (HIR::QualifiedPathInType &path);
   virtual void visit (HIR::Module &module);
   virtual void visit (HIR::ExternCrate &crate);
-  virtual void visit (HIR::UseTreeGlob &use_tree);
-  virtual void visit (HIR::UseTreeList &use_tree);
-  virtual void visit (HIR::UseTreeRebind &use_tree);
   virtual void visit (HIR::UseDeclaration &use_decl);
   virtual void visit (HIR::Function &function);
   virtual void visit (HIR::TypeAlias &type_alias);
   virtual void visit (HIR::StructStruct &struct_item);
-  virtual void visit (HIR::TupleStruct &tuple_struct);
-  virtual void visit (HIR::EnumItem &item);
-  virtual void visit (HIR::EnumItemTuple &item);
-  virtual void visit (HIR::EnumItemStruct &item);
-  virtual void visit (HIR::EnumItemDiscriminant &item);
   virtual void visit (HIR::Enum &enum_item);
   virtual void visit (HIR::Union &union_item);
   virtual void visit (HIR::ConstantItem &const_item);
   virtual void visit (HIR::StaticItem &static_item);
-  virtual void visit (HIR::TraitItemFunc &item);
-  virtual void visit (HIR::TraitItemConst &item);
-  virtual void visit (HIR::TraitItemType &item);
   virtual void visit (HIR::Trait &trait);
   virtual void visit (HIR::ImplBlock &impl);
-  virtual void visit (HIR::ExternalStaticItem &item);
-  virtual void visit (HIR::ExternalFunctionItem &item);
   virtual void visit (HIR::ExternBlock &block);
-  virtual void visit (HIR::LiteralPattern &pattern);
-  virtual void visit (HIR::IdentifierPattern &pattern);
-  virtual void visit (HIR::WildcardPattern &pattern);
-  virtual void visit (HIR::RangePatternBoundLiteral &bound);
-  virtual void visit (HIR::RangePatternBoundPath &bound);
-  virtual void visit (HIR::RangePatternBoundQualPath &bound);
-  virtual void visit (HIR::RangePattern &pattern);
-  virtual void visit (HIR::ReferencePattern &pattern);
-  virtual void visit (HIR::StructPatternFieldTuplePat &field);
-  virtual void visit (HIR::StructPatternFieldIdentPat &field);
-  virtual void visit (HIR::StructPatternFieldIdent &field);
-  virtual void visit (HIR::StructPattern &pattern);
-  virtual void visit (HIR::TupleStructItemsNoRange &tuple_items);
-  virtual void visit (HIR::TupleStructItemsRange &tuple_items);
-  virtual void visit (HIR::TupleStructPattern &pattern);
-  virtual void visit (HIR::TuplePatternItemsMultiple &tuple_items);
-  virtual void visit (HIR::TuplePatternItemsRanged &tuple_items);
-  virtual void visit (HIR::TuplePattern &pattern);
-  virtual void visit (HIR::GroupedPattern &pattern);
-  virtual void visit (HIR::SlicePattern &pattern);
   virtual void visit (HIR::EmptyStmt &stmt);
   virtual void visit (HIR::LetStmt &stmt);
   virtual void visit (HIR::ExprStmtWithoutBlock &stmt);
   virtual void visit (HIR::ExprStmtWithBlock &stmt);
-  virtual void visit (HIR::TraitBound &bound);
-  virtual void visit (HIR::ImplTraitType &type);
-  virtual void visit (HIR::TraitObjectType &type);
-  virtual void visit (HIR::ParenthesisedType &type);
-  virtual void visit (HIR::ImplTraitTypeOneBound &type);
-  virtual void visit (HIR::TupleType &type);
-  virtual void visit (HIR::NeverType &type);
-  virtual void visit (HIR::RawPointerType &type);
-  virtual void visit (HIR::ReferenceType &type);
-  virtual void visit (HIR::ArrayType &type);
-  virtual void visit (HIR::SliceType &type);
-  virtual void visit (HIR::InferredType &type);
-  virtual void visit (HIR::BareFunctionType &type);
 
   Analysis::Mappings &mappings;
   Rust::Resolver::Resolver &resolver;
diff --git a/gcc/testsuite/rust/compile/privacy3.rs b/gcc/testsuite/rust/compile/privacy3.rs
new file mode 100644
index 00000000000..d48acea4786
--- /dev/null
+++ b/gcc/testsuite/rust/compile/privacy3.rs
@@ -0,0 +1,28 @@
+mod orange {
+    mod green {
+        fn sain_void() {}
+        fn sain() -> bool {
+            false
+        }
+        pub fn doux() {}
+    }
+
+    fn brown() {
+        if green::sain() {
+            // { dg-error "definition is private in this context" "" { target *-*-* } .-1 }
+            green::doux();
+        }
+
+        {
+            green::sain();
+            // { dg-error "definition is private in this context" "" { target *-*-* } .-1 }
+            green::sain();
+            // { dg-error "definition is private in this context" "" { target *-*-* } .-1 }
+            green::sain_void()
+            // { dg-error "definition is private in this context" "" { target *-*-* } .-1 }
+        }
+
+        let a = green::sain();
+        // { dg-error "definition is private in this context" "" { target *-*-* } .-1 }
+    }
+}
diff --git a/gcc/testsuite/rust/compile/privacy4.rs b/gcc/testsuite/rust/compile/privacy4.rs
new file mode 100644
index 00000000000..d1ce0afd654
--- /dev/null
+++ b/gcc/testsuite/rust/compile/privacy4.rs
@@ -0,0 +1,19 @@
+mod orange {
+    mod green {
+        fn bean<T>(value: T) -> T {
+            value
+        }
+    }
+
+    fn brown() {
+        green::bean::<bool>(false);
+        // { dg-error "definition is private in this context" "" { target *-*-* } .-1 }
+        let a = green::bean::<i32>(15);
+        // { dg-error "definition is private in this context" "" { target *-*-* } .-1 }
+
+        struct S;
+
+        let s = green::bean(S);
+        // { dg-error "definition is private in this context" "" { target *-*-* } .-1 }
+    }
+}


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-06-08 12:47 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-08 12:47 [gcc/devel/rust/master] privacy: PrivacyReporter: Add visitors for all expressions Thomas Schwinge

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).