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