LCOV - code coverage report
Current view: top level - gcc/rust/checks/errors/privacy - rust-privacy-reporter.cc (source / functions) Coverage Total Hit
Test: gcc.info Lines: 86.4 % 368 318
Test Date: 2025-06-28 16:12:38 Functions: 81.5 % 81 66
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: - 0 0

             Branch data     Line data    Source code
       1                 :             : // Copyright (C) 2020-2025 Free Software Foundation, Inc.
       2                 :             : 
       3                 :             : // This file is part of GCC.
       4                 :             : 
       5                 :             : // GCC is free software; you can redistribute it and/or modify it under
       6                 :             : // the terms of the GNU General Public License as published by the Free
       7                 :             : // Software Foundation; either version 3, or (at your option) any later
       8                 :             : // version.
       9                 :             : 
      10                 :             : // GCC is distributed in the hope that it will be useful, but WITHOUT ANY
      11                 :             : // WARRANTY; without even the implied warranty of MERCHANTABILITY or
      12                 :             : // FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
      13                 :             : // for more details.
      14                 :             : 
      15                 :             : // You should have received a copy of the GNU General Public License
      16                 :             : // along with GCC; see the file COPYING3.  If not see
      17                 :             : // <http://www.gnu.org/licenses/>.
      18                 :             : 
      19                 :             : #include "rust-privacy-reporter.h"
      20                 :             : #include "rust-session-manager.h"
      21                 :             : #include "rust-hir-expr.h"
      22                 :             : #include "rust-hir-stmt.h"
      23                 :             : #include "rust-hir-item.h"
      24                 :             : #include "rust-attribute-values.h"
      25                 :             : #include "rust-immutable-name-resolution-context.h"
      26                 :             : 
      27                 :             : namespace Rust {
      28                 :             : namespace Privacy {
      29                 :             : 
      30                 :        4339 : PrivacyReporter::PrivacyReporter (
      31                 :             :   Analysis::Mappings &mappings, Resolver::Resolver &resolver,
      32                 :        4339 :   const Rust::Resolver::TypeCheckContext &ty_ctx)
      33                 :        4339 :   : mappings (mappings), resolver (resolver), ty_ctx (ty_ctx),
      34                 :        4339 :     current_module (tl::nullopt)
      35                 :        4339 : {}
      36                 :             : 
      37                 :             : // Find a proc_macro, proc_macro_derive or proc_macro_attribute
      38                 :             : // attribute in a vector of attribute
      39                 :             : static tl::optional<std::string>
      40                 :          12 : find_proc_macro_attribute (const AST::AttrVec &outer_attrs)
      41                 :             : {
      42                 :          12 :   for (auto &a : outer_attrs)
      43                 :             :     {
      44                 :           6 :       auto &segments = a.get_path ().get_segments ();
      45                 :           6 :       if (segments.size () != 1)
      46                 :           0 :         continue;
      47                 :           6 :       auto name = segments.at (0).get_segment_name ();
      48                 :           6 :       if (name == Values::Attributes::PROC_MACRO
      49                 :           4 :           || name == Values::Attributes::PROC_MACRO_ATTRIBUTE
      50                 :           8 :           || name == Values::Attributes::PROC_MACRO_DERIVE)
      51                 :           6 :         return name;
      52                 :           6 :     }
      53                 :             : 
      54                 :           6 :   return tl::nullopt;
      55                 :             : }
      56                 :             : 
      57                 :             : // Common check on crate items when dealing with 'proc-macro' crate type.
      58                 :             : static void
      59                 :          12 : proc_macro_privacy_check (std::unique_ptr<HIR::Item> &item)
      60                 :             : {
      61                 :          12 :   if (item->get_hir_kind () == HIR::Node::BaseKind::VIS_ITEM)
      62                 :             :     {
      63                 :          12 :       auto attribute = find_proc_macro_attribute (item->get_outer_attrs ());
      64                 :             : 
      65                 :          12 :       bool pub_item = static_cast<HIR::VisItem *> (item.get ())
      66                 :          12 :                         ->get_visibility ()
      67                 :          12 :                         .is_public ();
      68                 :             : 
      69                 :          12 :       if (pub_item && !attribute.has_value ()) // Public non proc-macro
      70                 :           4 :         rust_error_at (
      71                 :           4 :           item->get_locus (),
      72                 :             :           "%<proc-macro%> crate types currently cannot export any "
      73                 :             :           "items other than functions tagged with %<#[proc_macro]%>, "
      74                 :             :           "%<#[proc_macro_derive]%> or %<#[proc_macro_attribute]%>");
      75                 :           8 :       else if (!pub_item && attribute.has_value ()) // Private proc-macro
      76                 :           6 :         rust_error_at (item->get_locus (),
      77                 :             :                        "functions tagged with %<#[%s]%> must be %<pub%>",
      78                 :           6 :                        attribute.value ().c_str ());
      79                 :          12 :     }
      80                 :          12 : }
      81                 :             : 
      82                 :             : void
      83                 :        4339 : PrivacyReporter::go (HIR::Crate &crate)
      84                 :             : {
      85                 :       20339 :   for (auto &item : crate.get_items ())
      86                 :             :     {
      87                 :       16000 :       if (Session::get_instance ().options.is_proc_macro ())
      88                 :          12 :         proc_macro_privacy_check (item);
      89                 :       16000 :       item->accept_vis (*this);
      90                 :             :     }
      91                 :        4339 : }
      92                 :             : 
      93                 :             : static bool
      94                 :          27 : is_child_module (Analysis::Mappings &mappings, NodeId parent,
      95                 :             :                  NodeId possible_child)
      96                 :             : {
      97                 :          27 :   if (flag_name_resolution_2_0)
      98                 :             :     {
      99                 :          13 :       auto &nr_ctx
     100                 :          13 :         = Resolver2_0::ImmutableNameResolutionContext::get ().resolver ();
     101                 :             : 
     102                 :          13 :       return nr_ctx.values.is_module_descendant (parent, possible_child);
     103                 :             :     }
     104                 :             : 
     105                 :          14 :   auto children = mappings.lookup_module_children (parent);
     106                 :             : 
     107                 :          14 :   if (!children)
     108                 :             :     return false;
     109                 :             : 
     110                 :             :   // Visit all toplevel children
     111                 :           4 :   for (auto &child : *children)
     112                 :           4 :     if (child == possible_child)
     113                 :           2 :       return true;
     114                 :             : 
     115                 :             :   // Now descend recursively in the child module tree
     116                 :           0 :   for (auto &child : *children)
     117                 :           0 :     if (is_child_module (mappings, child, possible_child))
     118                 :           2 :       return true;
     119                 :             : 
     120                 :             :   return false;
     121                 :             : }
     122                 :             : 
     123                 :             : // FIXME: This function needs a lot of refactoring
     124                 :             : void
     125                 :       38647 : PrivacyReporter::check_for_privacy_violation (const NodeId &use_id,
     126                 :             :                                               const location_t locus)
     127                 :             : {
     128                 :       38647 :   NodeId ref_node_id = UNKNOWN_NODEID;
     129                 :             : 
     130                 :       38647 :   if (flag_name_resolution_2_0)
     131                 :             :     {
     132                 :        4420 :       auto &nr_ctx
     133                 :        4420 :         = Resolver2_0::ImmutableNameResolutionContext::get ().resolver ();
     134                 :             : 
     135                 :        4420 :       if (auto id = nr_ctx.lookup (use_id))
     136                 :        4412 :         ref_node_id = *id;
     137                 :             :     }
     138                 :             :   // FIXME: Don't assert here - we might be dealing with a type
     139                 :       34227 :   else if (!resolver.lookup_resolved_name (use_id, &ref_node_id))
     140                 :        3433 :     resolver.lookup_resolved_type (use_id, &ref_node_id);
     141                 :             : 
     142                 :             :   // FIXME: Assert here. For now, we return since this causes issues when
     143                 :             :   // checking inferred types (#1260)
     144                 :             :   // rust_assert (ref_node_id != UNKNOWN_NODEID);
     145                 :       38647 :   if (ref_node_id == UNKNOWN_NODEID)
     146                 :       36929 :     return;
     147                 :             : 
     148                 :       38563 :   auto vis = mappings.lookup_visibility (ref_node_id);
     149                 :             : 
     150                 :             :   // FIXME: Can we really return here if the item has no visibility?
     151                 :       38563 :   if (!vis)
     152                 :             :     return;
     153                 :             : 
     154                 :        6535 :   auto valid = true;
     155                 :             : 
     156                 :        6535 :   switch (vis->get_kind ())
     157                 :             :     {
     158                 :             :     case ModuleVisibility::Public:
     159                 :             :       break;
     160                 :        4860 :       case ModuleVisibility::Restricted: {
     161                 :             :         // If we are in the crate, everything is restricted correctly, but we
     162                 :             :         // can't get a module for it
     163                 :        4860 :         if (!current_module.has_value ())
     164                 :             :           return;
     165                 :             : 
     166                 :          43 :         auto module = mappings.lookup_defid (vis->get_module_id ()).value ();
     167                 :             : 
     168                 :          43 :         auto mod_node_id = module->get_mappings ().get_nodeid ();
     169                 :             : 
     170                 :             :         // We are in the module referenced by the pub(restricted) visibility.
     171                 :             :         // This is valid
     172                 :          43 :         if (mod_node_id == current_module.value ())
     173                 :             :           break;
     174                 :             : 
     175                 :             :         // FIXME: This needs a LOT of TLC: hinting about the definition, a
     176                 :             :         // string to say if it's a module, function, type, etc...
     177                 :          27 :         if (!is_child_module (mappings, mod_node_id, current_module.value ()))
     178                 :          24 :           valid = false;
     179                 :             :       }
     180                 :             :       break;
     181                 :           0 :     case ModuleVisibility::Unknown:
     182                 :           0 :       rust_unreachable ();
     183                 :          24 :       break;
     184                 :             :     }
     185                 :             : 
     186                 :          24 :   if (!valid)
     187                 :             :     {
     188                 :          24 :       rich_location richloc (line_table, locus);
     189                 :          24 :       richloc.add_fixit_replace ("item is private");
     190                 :          24 :       rust_error_at (richloc, ErrorCode::E0603,
     191                 :             :                      "definition is private in this context");
     192                 :          24 :     }
     193                 :             : }
     194                 :             : 
     195                 :             : void
     196                 :        9788 : PrivacyReporter::check_base_type_privacy (Analysis::NodeMapping &node_mappings,
     197                 :             :                                           const TyTy::BaseType *ty,
     198                 :             :                                           const location_t locus)
     199                 :             : {
     200                 :             :   // Avoids repeating commong argument such as `use_id` or `locus` since we're
     201                 :             :   // doing a lot of recursive calls here
     202                 :        9788 :   auto recursive_check
     203                 :        2489 :     = [this, &node_mappings, &locus] (const TyTy::BaseType *ty) {
     204                 :        2489 :         return check_base_type_privacy (node_mappings, ty, locus);
     205                 :        9788 :       };
     206                 :             : 
     207                 :        9788 :   switch (ty->get_kind ())
     208                 :             :     {
     209                 :             :       // These "simple" types are our stop condition
     210                 :        5959 :     case TyTy::BOOL:
     211                 :        5959 :     case TyTy::CHAR:
     212                 :        5959 :     case TyTy::INT:
     213                 :        5959 :     case TyTy::UINT:
     214                 :        5959 :     case TyTy::FLOAT:
     215                 :        5959 :     case TyTy::USIZE:
     216                 :        5959 :     case TyTy::ISIZE:
     217                 :        5959 :     case TyTy::ADT:
     218                 :        5959 :       case TyTy::STR: {
     219                 :        5959 :         auto ref_id = ty->get_ref ();
     220                 :        5959 :         if (auto lookup_id = mappings.lookup_hir_to_node (ref_id))
     221                 :        5959 :           return check_for_privacy_violation (*lookup_id, locus);
     222                 :           0 :         rust_unreachable ();
     223                 :             :       }
     224                 :         985 :     case TyTy::REF:
     225                 :         985 :       return recursive_check (
     226                 :        1970 :         static_cast<const TyTy::ReferenceType *> (ty)->get_base ());
     227                 :         521 :     case TyTy::POINTER:
     228                 :         521 :       return recursive_check (
     229                 :        1042 :         static_cast<const TyTy::PointerType *> (ty)->get_base ());
     230                 :         562 :     case TyTy::ARRAY:
     231                 :         562 :       return recursive_check (
     232                 :        1124 :         static_cast<const TyTy::ArrayType *> (ty)->get_element_type ());
     233                 :         205 :     case TyTy::SLICE:
     234                 :         205 :       return recursive_check (
     235                 :         410 :         static_cast<const TyTy::SliceType *> (ty)->get_element_type ());
     236                 :          38 :     case TyTy::FNPTR:
     237                 :          74 :       for (auto &param : static_cast<const TyTy::FnPtr *> (ty)->get_params ())
     238                 :          36 :         recursive_check (param.get_tyty ());
     239                 :          38 :       return recursive_check (
     240                 :          76 :         static_cast<const TyTy::FnPtr *> (ty)->get_return_type ());
     241                 :          80 :     case TyTy::TUPLE:
     242                 :         182 :       for (auto &param :
     243                 :         182 :            static_cast<const TyTy::TupleType *> (ty)->get_fields ())
     244                 :         102 :         recursive_check (param.get_tyty ());
     245                 :             :       return;
     246                 :           0 :       case TyTy::PLACEHOLDER: {
     247                 :           0 :         const auto p = static_cast<const TyTy::PlaceholderType *> (ty);
     248                 :           0 :         if (!p->can_resolve ())
     249                 :             :           return;
     250                 :           0 :         return recursive_check (p->resolve ());
     251                 :             :       }
     252                 :          40 :     case TyTy::PROJECTION:
     253                 :          40 :       return recursive_check (
     254                 :          40 :         static_cast<const TyTy::ProjectionType *> (ty)->get ());
     255                 :           0 :     case TyTy::CLOSURE:
     256                 :           0 :       rust_sorry_at (locus, "privacy pass for closures is not handled yet");
     257                 :           0 :       break;
     258                 :             : 
     259                 :             :       // If we're dealing with a generic param, there's nothing we should be
     260                 :             :       // doing here
     261                 :             :     case TyTy::PARAM:
     262                 :             :       // We are dealing with a function definition that has been assigned
     263                 :             :       // somewhere else. Nothing to resolve privacy-wise other than the actual
     264                 :             :       // function, which is resolved as an expression
     265                 :             :     case TyTy::FNDEF:
     266                 :             :       // FIXME: Can we really not resolve Dynamic types here? Shouldn't we have
     267                 :             :       // a look at the path and perform proper privacy analysis?
     268                 :             :     case TyTy::DYNAMIC:
     269                 :             :       // The never type is builtin and always available
     270                 :             :     case TyTy::NEVER:
     271                 :             :       // We shouldn't have inference types here, ever
     272                 :             :     case TyTy::INFER:
     273                 :             :       return;
     274                 :             :     case TyTy::OPAQUE:
     275                 :             :       return;
     276                 :             :     case TyTy::ERROR:
     277                 :             :       return;
     278                 :             :     }
     279                 :             : }
     280                 :             : 
     281                 :             : void
     282                 :        7299 : PrivacyReporter::check_type_privacy (const HIR::Type &type)
     283                 :             : {
     284                 :        7299 :   TyTy::BaseType *lookup = nullptr;
     285                 :        7299 :   rust_assert (ty_ctx.lookup_type (type.get_mappings ().get_hirid (), &lookup));
     286                 :             : 
     287                 :        7299 :   auto node_mappings = type.get_mappings ();
     288                 :        7299 :   return check_base_type_privacy (node_mappings, lookup, type.get_locus ());
     289                 :             : }
     290                 :             : 
     291                 :             : void
     292                 :       32566 : PrivacyReporter::visit (HIR::PathInExpression &path)
     293                 :             : {
     294                 :       32566 :   check_for_privacy_violation (path.get_mappings ().get_nodeid (),
     295                 :             :                                path.get_locus ());
     296                 :       32566 : }
     297                 :             : 
     298                 :             : void
     299                 :           0 : PrivacyReporter::visit (HIR::TypePathSegmentFunction &)
     300                 :             : {
     301                 :             :   // FIXME: Do we need to do anything for this?
     302                 :           0 : }
     303                 :             : 
     304                 :             : void
     305                 :          36 : PrivacyReporter::visit (HIR::InlineAsm &)
     306                 :          36 : {}
     307                 :             : 
     308                 :             : void
     309                 :           2 : PrivacyReporter::visit (HIR::LlvmInlineAsm &)
     310                 :           2 : {}
     311                 :             : 
     312                 :             : void
     313                 :           0 : PrivacyReporter::visit (HIR::TypePath &path)
     314                 :             : {
     315                 :           0 :   check_for_privacy_violation (path.get_mappings ().get_nodeid (),
     316                 :           0 :                                path.get_locus ());
     317                 :           0 : }
     318                 :             : 
     319                 :             : void
     320                 :         122 : PrivacyReporter::visit (HIR::QualifiedPathInExpression &path)
     321                 :             : {
     322                 :         122 :   check_for_privacy_violation (path.get_mappings ().get_nodeid (),
     323                 :             :                                path.get_locus ());
     324                 :         122 : }
     325                 :             : 
     326                 :             : void
     327                 :           0 : PrivacyReporter::visit (HIR::QualifiedPathInType &path)
     328                 :             : {
     329                 :           0 :   check_for_privacy_violation (path.get_mappings ().get_nodeid (),
     330                 :           0 :                                path.get_locus ());
     331                 :           0 : }
     332                 :             : 
     333                 :             : void
     334                 :       14538 : PrivacyReporter::visit (HIR::LiteralExpr &)
     335                 :             : {
     336                 :             :   // Literals cannot contain any sort of privacy violation
     337                 :       14538 : }
     338                 :             : 
     339                 :             : void
     340                 :        1253 : PrivacyReporter::visit (HIR::BorrowExpr &expr)
     341                 :             : {
     342                 :        1253 :   expr.get_expr ().accept_vis (*this);
     343                 :        1253 : }
     344                 :             : 
     345                 :             : void
     346                 :        1779 : PrivacyReporter::visit (HIR::DereferenceExpr &expr)
     347                 :             : {
     348                 :        1779 :   expr.get_expr ().accept_vis (*this);
     349                 :        1779 : }
     350                 :             : 
     351                 :             : void
     352                 :           0 : PrivacyReporter::visit (HIR::ErrorPropagationExpr &expr)
     353                 :             : {
     354                 :           0 :   expr.get_expr ().accept_vis (*this);
     355                 :           0 : }
     356                 :             : 
     357                 :             : void
     358                 :         327 : PrivacyReporter::visit (HIR::NegationExpr &expr)
     359                 :             : {
     360                 :         327 :   expr.get_expr ().accept_vis (*this);
     361                 :         327 : }
     362                 :             : 
     363                 :             : void
     364                 :        2913 : PrivacyReporter::visit (HIR::ArithmeticOrLogicalExpr &expr)
     365                 :             : {
     366                 :        2913 :   expr.get_lhs ().accept_vis (*this);
     367                 :        2913 :   expr.get_rhs ().accept_vis (*this);
     368                 :        2913 : }
     369                 :             : 
     370                 :             : void
     371                 :        1068 : PrivacyReporter::visit (HIR::ComparisonExpr &expr)
     372                 :             : {
     373                 :        1068 :   expr.get_lhs ().accept_vis (*this);
     374                 :        1068 :   expr.get_rhs ().accept_vis (*this);
     375                 :        1068 : }
     376                 :             : 
     377                 :             : void
     378                 :         316 : PrivacyReporter::visit (HIR::LazyBooleanExpr &expr)
     379                 :             : {
     380                 :         316 :   expr.get_lhs ().accept_vis (*this);
     381                 :         316 :   expr.get_rhs ().accept_vis (*this);
     382                 :         316 : }
     383                 :             : 
     384                 :             : void
     385                 :        3910 : PrivacyReporter::visit (HIR::TypeCastExpr &expr)
     386                 :             : {
     387                 :        3910 :   expr.get_expr ().accept_vis (*this);
     388                 :        3910 : }
     389                 :             : 
     390                 :             : void
     391                 :        1779 : PrivacyReporter::visit (HIR::AssignmentExpr &expr)
     392                 :             : {
     393                 :        1779 :   expr.get_lhs ().accept_vis (*this);
     394                 :        1779 :   expr.get_rhs ().accept_vis (*this);
     395                 :        1779 : }
     396                 :             : 
     397                 :             : void
     398                 :         216 : PrivacyReporter::visit (HIR::CompoundAssignmentExpr &expr)
     399                 :             : {
     400                 :         216 :   expr.get_lhs ().accept_vis (*this);
     401                 :         216 :   expr.get_rhs ().accept_vis (*this);
     402                 :         216 : }
     403                 :             : 
     404                 :             : void
     405                 :         244 : PrivacyReporter::visit (HIR::GroupedExpr &expr)
     406                 :             : {
     407                 :         244 :   expr.get_expr_in_parens ().accept_vis (*this);
     408                 :         244 : }
     409                 :             : 
     410                 :             : void
     411                 :         380 : PrivacyReporter::visit (HIR::ArrayExpr &expr)
     412                 :             : {
     413                 :         380 :   HIR::ArrayElems &elements = expr.get_internal_elements ();
     414                 :         380 :   switch (elements.get_array_expr_type ())
     415                 :             :     {
     416                 :         257 :       case HIR::ArrayElems::ArrayExprType::VALUES: {
     417                 :         257 :         auto &elems = static_cast<HIR::ArrayElemsValues &> (elements);
     418                 :        1572 :         for (auto &value : elems.get_values ())
     419                 :        1315 :           value->accept_vis (*this);
     420                 :             :       }
     421                 :             :       return;
     422                 :             : 
     423                 :         123 :     case HIR::ArrayElems::ArrayExprType::COPIED:
     424                 :         123 :       auto &elems = static_cast<HIR::ArrayElemsCopied &> (elements);
     425                 :         123 :       elems.get_elem_to_copy ().accept_vis (*this);
     426                 :             :     }
     427                 :             : }
     428                 :             : 
     429                 :             : void
     430                 :         233 : PrivacyReporter::visit (HIR::ArrayIndexExpr &expr)
     431                 :             : {
     432                 :         233 :   expr.get_array_expr ().accept_vis (*this);
     433                 :         233 :   expr.get_index_expr ().accept_vis (*this);
     434                 :         233 : }
     435                 :             : 
     436                 :             : void
     437                 :         459 : PrivacyReporter::visit (HIR::TupleExpr &expr)
     438                 :             : {
     439                 :        1322 :   for (auto &value : expr.get_tuple_elems ())
     440                 :         863 :     value->accept_vis (*this);
     441                 :         459 : }
     442                 :             : 
     443                 :             : void
     444                 :         858 : PrivacyReporter::visit (HIR::TupleIndexExpr &expr)
     445                 :             : {
     446                 :         858 :   expr.get_tuple_expr ().accept_vis (*this);
     447                 :         858 : }
     448                 :             : 
     449                 :             : void
     450                 :          61 : PrivacyReporter::visit (HIR::StructExprStruct &)
     451                 :             : {
     452                 :             :   // FIXME: We need to check the visibility of the type it refers to here
     453                 :          61 : }
     454                 :             : 
     455                 :             : void
     456                 :         234 : PrivacyReporter::visit (HIR::StructExprFieldIdentifier &)
     457                 :         234 : {}
     458                 :             : 
     459                 :             : void
     460                 :        2349 : PrivacyReporter::visit (HIR::StructExprFieldIdentifierValue &field)
     461                 :             : {
     462                 :        2349 :   field.get_value ().accept_vis (*this);
     463                 :        2349 : }
     464                 :             : 
     465                 :             : void
     466                 :          48 : PrivacyReporter::visit (HIR::StructExprFieldIndexValue &field)
     467                 :             : {
     468                 :          48 :   field.get_value ().accept_vis (*this);
     469                 :          48 : }
     470                 :             : 
     471                 :             : void
     472                 :        1065 : PrivacyReporter::visit (HIR::StructExprStructFields &expr)
     473                 :             : {
     474                 :        3696 :   for (auto &field : expr.get_fields ())
     475                 :        2631 :     field->accept_vis (*this);
     476                 :        1065 : }
     477                 :             : 
     478                 :             : void
     479                 :        8975 : PrivacyReporter::visit (HIR::CallExpr &expr)
     480                 :             : {
     481                 :        8975 :   expr.get_fnexpr ().accept_vis (*this);
     482                 :             : 
     483                 :       19956 :   for (auto &param : expr.get_arguments ())
     484                 :       10981 :     param->accept_vis (*this);
     485                 :        8975 : }
     486                 :             : 
     487                 :             : void
     488                 :        1393 : PrivacyReporter::visit (HIR::MethodCallExpr &expr)
     489                 :             : {
     490                 :        1393 :   expr.get_receiver ().accept_vis (*this);
     491                 :             : 
     492                 :        2053 :   for (auto &param : expr.get_arguments ())
     493                 :         660 :     param->accept_vis (*this);
     494                 :        1393 : }
     495                 :             : 
     496                 :             : void
     497                 :        2466 : PrivacyReporter::visit (HIR::FieldAccessExpr &expr)
     498                 :             : {
     499                 :        2466 :   expr.get_receiver_expr ().accept_vis (*this);
     500                 :             : 
     501                 :             :   // FIXME: We should also check if the field is public?
     502                 :        2466 : }
     503                 :             : 
     504                 :             : void
     505                 :          55 : PrivacyReporter::visit (HIR::ClosureExpr &)
     506                 :             : {
     507                 :             :   // Not handled yet
     508                 :          55 : }
     509                 :             : 
     510                 :             : void
     511                 :       17401 : PrivacyReporter::visit (HIR::BlockExpr &expr)
     512                 :             : {
     513                 :       36176 :   for (auto &stmt : expr.get_statements ())
     514                 :       18775 :     stmt->accept_vis (*this);
     515                 :             : 
     516                 :       17401 :   if (expr.has_final_expr ())
     517                 :       12376 :     expr.get_final_expr ().accept_vis (*this);
     518                 :       17401 : }
     519                 :             : 
     520                 :             : void
     521                 :           8 : PrivacyReporter::visit (HIR::ContinueExpr &)
     522                 :           8 : {}
     523                 :             : 
     524                 :             : void
     525                 :          48 : PrivacyReporter::visit (HIR::BreakExpr &expr)
     526                 :             : {
     527                 :          48 :   if (expr.has_break_expr ())
     528                 :          18 :     expr.get_expr ().accept_vis (*this);
     529                 :          48 : }
     530                 :             : 
     531                 :             : void
     532                 :          70 : PrivacyReporter::visit (HIR::RangeFromToExpr &expr)
     533                 :             : {
     534                 :          70 :   expr.get_from_expr ().accept_vis (*this);
     535                 :          70 :   expr.get_to_expr ().accept_vis (*this);
     536                 :          70 : }
     537                 :             : 
     538                 :             : void
     539                 :           8 : PrivacyReporter::visit (HIR::RangeFromExpr &expr)
     540                 :             : {
     541                 :           8 :   expr.get_from_expr ().accept_vis (*this);
     542                 :           8 : }
     543                 :             : 
     544                 :             : void
     545                 :           8 : PrivacyReporter::visit (HIR::RangeToExpr &expr)
     546                 :             : {
     547                 :           8 :   expr.get_to_expr ().accept_vis (*this);
     548                 :           8 : }
     549                 :             : 
     550                 :             : void
     551                 :           0 : PrivacyReporter::visit (HIR::RangeFullExpr &)
     552                 :           0 : {}
     553                 :             : 
     554                 :             : void
     555                 :           8 : PrivacyReporter::visit (HIR::RangeFromToInclExpr &expr)
     556                 :             : {
     557                 :           8 :   expr.get_from_expr ().accept_vis (*this);
     558                 :           8 :   expr.get_to_expr ().accept_vis (*this);
     559                 :           8 : }
     560                 :             : 
     561                 :             : void
     562                 :           0 : PrivacyReporter::visit (HIR::RangeToInclExpr &)
     563                 :             : {
     564                 :             :   // Not handled yet
     565                 :           0 : }
     566                 :             : 
     567                 :             : void
     568                 :         379 : PrivacyReporter::visit (HIR::ReturnExpr &expr)
     569                 :             : {
     570                 :         379 :   if (expr.has_expr ())
     571                 :         353 :     expr.get_expr ().accept_vis (*this);
     572                 :         379 : }
     573                 :             : 
     574                 :             : void
     575                 :        3097 : PrivacyReporter::visit (HIR::UnsafeBlockExpr &expr)
     576                 :             : {
     577                 :        3097 :   expr.get_block_expr ().accept_vis (*this);
     578                 :        3097 : }
     579                 :             : 
     580                 :             : void
     581                 :         106 : PrivacyReporter::visit (HIR::LoopExpr &expr)
     582                 :             : {
     583                 :         106 :   expr.get_loop_block ().accept_vis (*this);
     584                 :         106 : }
     585                 :             : 
     586                 :             : void
     587                 :          66 : PrivacyReporter::visit (HIR::WhileLoopExpr &expr)
     588                 :             : {
     589                 :          66 :   expr.get_predicate_expr ().accept_vis (*this);
     590                 :          66 :   expr.get_loop_block ().accept_vis (*this);
     591                 :          66 : }
     592                 :             : 
     593                 :             : void
     594                 :           0 : PrivacyReporter::visit (HIR::WhileLetLoopExpr &expr)
     595                 :             : {
     596                 :           0 :   expr.get_cond ().accept_vis (*this);
     597                 :           0 :   expr.get_loop_block ().accept_vis (*this);
     598                 :           0 : }
     599                 :             : 
     600                 :             : void
     601                 :         375 : PrivacyReporter::visit (HIR::IfExpr &expr)
     602                 :             : {
     603                 :         375 :   expr.get_if_condition ().accept_vis (*this);
     604                 :         375 :   expr.get_if_block ().accept_vis (*this);
     605                 :         375 : }
     606                 :             : 
     607                 :             : void
     608                 :         567 : PrivacyReporter::visit (HIR::IfExprConseqElse &expr)
     609                 :             : {
     610                 :         567 :   expr.get_if_condition ().accept_vis (*this);
     611                 :         567 :   expr.get_if_block ().accept_vis (*this);
     612                 :         567 :   expr.get_else_block ().accept_vis (*this);
     613                 :         567 : }
     614                 :             : 
     615                 :             : void
     616                 :         431 : PrivacyReporter::visit (HIR::MatchExpr &expr)
     617                 :             : {
     618                 :         431 :   expr.get_scrutinee_expr ().accept_vis (*this);
     619                 :         431 : }
     620                 :             : 
     621                 :             : void
     622                 :           0 : PrivacyReporter::visit (HIR::AwaitExpr &)
     623                 :             : {
     624                 :             :   // Not handled yet
     625                 :           0 : }
     626                 :             : 
     627                 :             : void
     628                 :           0 : PrivacyReporter::visit (HIR::AsyncBlockExpr &)
     629                 :             : {
     630                 :             :   // Not handled yet
     631                 :           0 : }
     632                 :             : 
     633                 :             : void
     634                 :         904 : PrivacyReporter::visit (HIR::Module &module)
     635                 :             : {
     636                 :             :   // FIXME: We also need to think about module privacy
     637                 :             : 
     638                 :         904 :   auto old_module = current_module;
     639                 :         904 :   current_module = module.get_mappings ().get_nodeid ();
     640                 :             : 
     641                 :        3976 :   for (auto &item : module.get_items ())
     642                 :        3072 :     item->accept_vis (*this);
     643                 :             : 
     644                 :         904 :   current_module = old_module;
     645                 :         904 : }
     646                 :             : 
     647                 :             : void
     648                 :           0 : PrivacyReporter::visit (HIR::ExternCrate &)
     649                 :           0 : {}
     650                 :             : 
     651                 :             : void
     652                 :           0 : PrivacyReporter::visit (HIR::UseDeclaration &)
     653                 :             : {
     654                 :             :   // FIXME: Is there anything we need to do here?
     655                 :           0 : }
     656                 :             : 
     657                 :             : void
     658                 :       12060 : PrivacyReporter::visit (HIR::Function &function)
     659                 :             : {
     660                 :       17174 :   for (auto &param : function.get_function_params ())
     661                 :        5114 :     check_type_privacy (param.get_type ());
     662                 :             : 
     663                 :       12060 :   function.get_definition ().accept_vis (*this);
     664                 :       12060 : }
     665                 :             : 
     666                 :             : void
     667                 :        1237 : PrivacyReporter::visit (HIR::TypeAlias &)
     668                 :             : {
     669                 :             :   // TODO: Check the type here
     670                 :        1237 : }
     671                 :             : 
     672                 :             : void
     673                 :        1262 : PrivacyReporter::visit (HIR::StructStruct &)
     674                 :             : {
     675                 :             :   // TODO: Check the type of all fields
     676                 :        1262 : }
     677                 :             : 
     678                 :             : void
     679                 :         935 : PrivacyReporter::visit (HIR::TupleStruct &)
     680                 :             : {
     681                 :             :   // TODO: Check the type of all fields
     682                 :         935 : }
     683                 :             : 
     684                 :             : void
     685                 :           0 : PrivacyReporter::visit (HIR::EnumItem &)
     686                 :             : {
     687                 :             :   // TODO: Check the type of all variants
     688                 :           0 : }
     689                 :             : 
     690                 :             : void
     691                 :           0 : PrivacyReporter::visit (HIR::EnumItemTuple &)
     692                 :             : {
     693                 :             :   // TODO: Check the type
     694                 :           0 : }
     695                 :             : 
     696                 :             : void
     697                 :           0 : PrivacyReporter::visit (HIR::EnumItemStruct &)
     698                 :             : {
     699                 :             :   // TODO: Check the type
     700                 :           0 : }
     701                 :             : 
     702                 :             : void
     703                 :           0 : PrivacyReporter::visit (HIR::EnumItemDiscriminant &)
     704                 :           0 : {}
     705                 :             : 
     706                 :             : void
     707                 :         329 : PrivacyReporter::visit (HIR::Enum &)
     708                 :         329 : {}
     709                 :             : 
     710                 :             : void
     711                 :         100 : PrivacyReporter::visit (HIR::Union &)
     712                 :             : {
     713                 :             :   // TODO: Check the type
     714                 :         100 : }
     715                 :             : 
     716                 :             : void
     717                 :         547 : PrivacyReporter::visit (HIR::ConstantItem &const_item)
     718                 :             : {
     719                 :             :   // TODO: We need to visit the type
     720                 :         547 :   const_item.get_expr ().accept_vis (*this);
     721                 :         547 : }
     722                 :             : 
     723                 :             : void
     724                 :          59 : PrivacyReporter::visit (HIR::StaticItem &static_item)
     725                 :             : {
     726                 :             :   // TODO: We need to visit the type
     727                 :          59 :   static_item.get_expr ().accept_vis (*this);
     728                 :          59 : }
     729                 :             : 
     730                 :             : void
     731                 :        2933 : PrivacyReporter::visit (HIR::Trait &)
     732                 :             : {
     733                 :             :   // FIXME: We need to be an ItemVisitor as well
     734                 :             :   // for (auto &item : trait.get_trait_items ())
     735                 :             :   //   item->accept_vis (*this);
     736                 :        2933 : }
     737                 :             : 
     738                 :             : void
     739                 :        4842 : PrivacyReporter::visit (HIR::ImplBlock &impl)
     740                 :             : {
     741                 :       11853 :   for (auto &item : impl.get_impl_items ())
     742                 :        7011 :     item->accept_vis (*this);
     743                 :        4842 : }
     744                 :             : 
     745                 :             : void
     746                 :        1248 : PrivacyReporter::visit (HIR::ExternBlock &)
     747                 :             : {
     748                 :             :   // FIXME: We need to be an ItemVisitor as well
     749                 :             :   // for (auto &block: block.get_extern_items ())
     750                 :             :   //   item->accept_vis (*this);
     751                 :        1248 : }
     752                 :             : 
     753                 :             : void
     754                 :          52 : PrivacyReporter::visit (HIR::EmptyStmt &)
     755                 :          52 : {}
     756                 :             : 
     757                 :             : void
     758                 :       11430 : PrivacyReporter::visit (HIR::LetStmt &stmt)
     759                 :             : {
     760                 :       11430 :   if (stmt.has_type ())
     761                 :        2185 :     check_type_privacy (stmt.get_type ());
     762                 :             : 
     763                 :       11430 :   if (stmt.has_init_expr ())
     764                 :       10270 :     stmt.get_init_expr ().accept_vis (*this);
     765                 :       11430 : }
     766                 :             : 
     767                 :             : void
     768                 :        6920 : PrivacyReporter::visit (HIR::ExprStmt &stmt)
     769                 :             : {
     770                 :        6920 :   stmt.get_expr ().accept_vis (*this);
     771                 :        6920 : }
     772                 :             : 
     773                 :             : } // namespace Privacy
     774                 :             : } // namespace Rust
        

Generated by: LCOV version 2.1-beta

LCOV profile is generated on x86_64 machine using following configure options: configure --disable-bootstrap --enable-coverage=opt --enable-languages=c,c++,fortran,go,jit,lto,rust,m2 --enable-host-shared. GCC test suite is run with the built compiler.