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.2 % 363 313
Test Date: 2024-04-20 14:03:02 Functions: 80.2 % 81 65
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: - 0 0

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