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 % 372 315
Test Date: 2026-08-22 16:33:35 Functions: 81.2 % 85 69
Legend: Lines:     hit not hit

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

Generated by: LCOV version 2.4-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.