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 4339 : PrivacyReporter::PrivacyReporter (
33 : Analysis::Mappings &mappings,
34 : const Resolver2_0::FinalizedNameResolutionContext &resolver,
35 4339 : const Rust::Resolver::TypeCheckContext &ty_ctx)
36 4339 : : mappings (mappings), resolver (resolver), ty_ctx (ty_ctx),
37 4339 : current_module (tl::nullopt)
38 4339 : {}
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 4339 : PrivacyReporter::go (HIR::Crate &crate)
87 : {
88 22168 : for (auto &item : crate.get_items ())
89 : {
90 17829 : if (Session::get_instance ().options.is_proc_macro ())
91 6 : proc_macro_privacy_check (item);
92 17829 : item->accept_vis (*this);
93 : }
94 4339 : }
95 :
96 : void
97 44774 : PrivacyReporter::check_violation_inner (NodeId ref_node_id,
98 : const location_t locus)
99 : {
100 44774 : auto vis = mappings.lookup_visibility (ref_node_id);
101 :
102 : // FIXME: Can we really return here if the item has no visibility?
103 44774 : if (!vis)
104 42077 : return;
105 :
106 7828 : auto valid = true;
107 :
108 7828 : switch (vis->get_kind ())
109 : {
110 : case ModuleVisibility::Public:
111 : break;
112 5158 : case ModuleVisibility::Restricted:
113 5158 : {
114 : // If we are in the crate, everything is restricted correctly, but we
115 : // can't get a module for it
116 5158 : 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 48480 : PrivacyReporter::check_for_privacy_violation (const NodeId &use_id,
152 : const location_t locus,
153 : Resolver2_0::Namespace ns)
154 : {
155 48480 : NodeId ref_node_id;
156 :
157 : // FIXME: Assert here. For now, we return since this causes issues when
158 : // checking inferred types (#1260)
159 48480 : if (auto id = resolver.lookup (use_id, ns))
160 44774 : ref_node_id = *id;
161 : else
162 3706 : return;
163 :
164 44774 : 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 11973 : 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 11973 : auto recursive_check
193 3646 : = [this, &node_mappings, &locus] (const TyTy::BaseType *ty) {
194 3646 : return check_base_type_privacy (node_mappings, ty, locus);
195 11973 : };
196 :
197 11973 : switch (ty->get_kind ())
198 : {
199 : // These "simple" types are our stop condition
200 6977 : case TyTy::BOOL:
201 6977 : case TyTy::CHAR:
202 6977 : case TyTy::INT:
203 6977 : case TyTy::UINT:
204 6977 : case TyTy::FLOAT:
205 6977 : case TyTy::USIZE:
206 6977 : case TyTy::ISIZE:
207 6977 : case TyTy::ADT:
208 6977 : case TyTy::STR:
209 6977 : {
210 6977 : auto ref_id = ty->get_ref ();
211 6977 : if (auto lookup_id = mappings.lookup_hir_to_node (ref_id))
212 6977 : return check_for_privacy_violation (*lookup_id, locus,
213 6977 : Resolver2_0::Namespace::Types);
214 : }
215 0 : break;
216 :
217 2242 : case TyTy::REF:
218 2242 : return recursive_check (
219 4484 : static_cast<const TyTy::ReferenceType *> (ty)->get_base ());
220 467 : case TyTy::POINTER:
221 467 : return recursive_check (
222 934 : static_cast<const TyTy::PointerType *> (ty)->get_base ());
223 542 : case TyTy::ARRAY:
224 542 : return recursive_check (
225 1084 : static_cast<const TyTy::ArrayType *> (ty)->get_element_type ());
226 239 : case TyTy::SLICE:
227 239 : return recursive_check (
228 478 : static_cast<const TyTy::SliceType *> (ty)->get_element_type ());
229 35 : case TyTy::FNPTR:
230 64 : for (auto ¶m : 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 72 : case TyTy::TUPLE:
235 164 : for (auto ¶m :
236 164 : static_cast<const TyTy::TupleType *> (ty)->get_fields ())
237 92 : 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 8327 : PrivacyReporter::check_type_privacy (const HIR::Type &type)
284 : {
285 8327 : TyTy::BaseType *lookup = nullptr;
286 8327 : rust_assert (ty_ctx.lookup_type (type.get_mappings ().get_hirid (), &lookup));
287 :
288 8327 : auto node_mappings = type.get_mappings ();
289 8327 : return check_base_type_privacy (node_mappings, lookup, type.get_locus ());
290 : }
291 :
292 : void
293 41397 : PrivacyReporter::visit (HIR::PathInExpression &path)
294 : {
295 41397 : check_for_privacy_violation (path.get_mappings ().get_nodeid (),
296 : path.get_locus (),
297 : Resolver2_0::Namespace::Values);
298 41397 : }
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 17727 : PrivacyReporter::visit (HIR::LiteralExpr &)
346 : {
347 : // Literals cannot contain any sort of privacy violation
348 17727 : }
349 :
350 : void
351 1609 : PrivacyReporter::visit (HIR::BorrowExpr &expr)
352 : {
353 1609 : expr.get_expr ().accept_vis (*this);
354 1609 : }
355 :
356 : void
357 3848 : PrivacyReporter::visit (HIR::DereferenceExpr &expr)
358 : {
359 3848 : expr.get_expr ().accept_vis (*this);
360 3848 : }
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 3151 : PrivacyReporter::visit (HIR::ArithmeticOrLogicalExpr &expr)
376 : {
377 3151 : expr.get_lhs ().accept_vis (*this);
378 3151 : expr.get_rhs ().accept_vis (*this);
379 3151 : }
380 :
381 : void
382 3293 : PrivacyReporter::visit (HIR::ComparisonExpr &expr)
383 : {
384 3293 : expr.get_lhs ().accept_vis (*this);
385 3293 : expr.get_rhs ().accept_vis (*this);
386 3293 : }
387 :
388 : void
389 357 : PrivacyReporter::visit (HIR::LazyBooleanExpr &expr)
390 : {
391 357 : expr.get_lhs ().accept_vis (*this);
392 357 : expr.get_rhs ().accept_vis (*this);
393 357 : }
394 :
395 : void
396 4293 : PrivacyReporter::visit (HIR::TypeCastExpr &expr)
397 : {
398 4293 : expr.get_expr ().accept_vis (*this);
399 4293 : }
400 :
401 : void
402 2358 : PrivacyReporter::visit (HIR::AssignmentExpr &expr)
403 : {
404 2358 : expr.get_lhs ().accept_vis (*this);
405 2358 : expr.get_rhs ().accept_vis (*this);
406 2358 : }
407 :
408 : void
409 591 : PrivacyReporter::visit (HIR::CompoundAssignmentExpr &expr)
410 : {
411 591 : expr.get_lhs ().accept_vis (*this);
412 591 : expr.get_rhs ().accept_vis (*this);
413 591 : }
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 466 : PrivacyReporter::visit (HIR::TupleExpr &expr)
450 : {
451 1389 : for (auto &value : expr.get_tuple_elems ())
452 923 : value->accept_vis (*this);
453 466 : }
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 215 : PrivacyReporter::visit (HIR::StructExprFieldIdentifier &)
469 215 : {}
470 :
471 : void
472 2645 : PrivacyReporter::visit (HIR::StructExprFieldIdentifierValue &field)
473 : {
474 2645 : field.get_value ().accept_vis (*this);
475 2645 : }
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 1333 : PrivacyReporter::visit (HIR::StructExprStructFields &expr)
485 : {
486 4235 : for (auto &field : expr.get_fields ())
487 2902 : field->accept_vis (*this);
488 1333 : }
489 :
490 : void
491 11089 : PrivacyReporter::visit (HIR::CallExpr &expr)
492 : {
493 11089 : expr.get_fnexpr ().accept_vis (*this);
494 :
495 23570 : for (auto ¶m : expr.get_arguments ())
496 12481 : param->accept_vis (*this);
497 11089 : }
498 :
499 : void
500 2490 : PrivacyReporter::visit (HIR::MethodCallExpr &expr)
501 : {
502 2490 : expr.get_receiver ().accept_vis (*this);
503 :
504 4082 : for (auto ¶m : expr.get_arguments ())
505 1592 : param->accept_vis (*this);
506 2490 : }
507 :
508 : void
509 5455 : PrivacyReporter::visit (HIR::FieldAccessExpr &expr)
510 : {
511 5455 : expr.get_receiver_expr ().accept_vis (*this);
512 :
513 : // FIXME: We should also check if the field is public?
514 5455 : }
515 :
516 : void
517 60 : PrivacyReporter::visit (HIR::ClosureExpr &)
518 : {
519 : // Not handled yet
520 60 : }
521 :
522 : void
523 20561 : PrivacyReporter::visit (HIR::BlockExpr &expr)
524 : {
525 42825 : for (auto &stmt : expr.get_statements ())
526 22264 : stmt->accept_vis (*this);
527 :
528 20561 : if (expr.has_final_expr ())
529 14779 : expr.get_final_expr ().accept_vis (*this);
530 20561 : }
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 13 : PrivacyReporter::visit (HIR::ContinueExpr &)
546 13 : {}
547 :
548 : void
549 49 : PrivacyReporter::visit (HIR::BreakExpr &expr)
550 : {
551 49 : if (expr.has_break_expr ())
552 19 : expr.get_expr ().accept_vis (*this);
553 49 : }
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 7 : PrivacyReporter::visit (HIR::RangeFromToInclExpr &expr)
580 : {
581 7 : expr.get_from_expr ().accept_vis (*this);
582 7 : expr.get_to_expr ().accept_vis (*this);
583 7 : }
584 :
585 : void
586 0 : PrivacyReporter::visit (HIR::RangeToInclExpr &)
587 : {
588 : // Not handled yet
589 0 : }
590 :
591 : void
592 1 : PrivacyReporter::visit (HIR::BoxExpr &expr)
593 : {
594 1 : expr.get_expr ().accept_vis (*this);
595 1 : }
596 :
597 : void
598 374 : PrivacyReporter::visit (HIR::ReturnExpr &expr)
599 : {
600 374 : if (expr.has_expr ())
601 343 : expr.get_expr ().accept_vis (*this);
602 374 : }
603 :
604 : void
605 3201 : PrivacyReporter::visit (HIR::UnsafeBlockExpr &expr)
606 : {
607 3201 : expr.get_block_expr ().accept_vis (*this);
608 3201 : }
609 :
610 : void
611 110 : PrivacyReporter::visit (HIR::LoopExpr &expr)
612 : {
613 110 : expr.get_loop_block ().accept_vis (*this);
614 110 : }
615 :
616 : void
617 72 : PrivacyReporter::visit (HIR::WhileLoopExpr &expr)
618 : {
619 72 : expr.get_predicate_expr ().accept_vis (*this);
620 72 : expr.get_loop_block ().accept_vis (*this);
621 72 : }
622 :
623 : void
624 0 : PrivacyReporter::visit (HIR::WhileLetLoopExpr &expr)
625 : {
626 0 : expr.get_cond ().accept_vis (*this);
627 0 : expr.get_loop_block ().accept_vis (*this);
628 0 : }
629 :
630 : void
631 1210 : PrivacyReporter::visit (HIR::IfExpr &expr)
632 : {
633 1210 : expr.get_if_condition ().accept_vis (*this);
634 1210 : expr.get_if_block ().accept_vis (*this);
635 1210 : }
636 :
637 : void
638 1142 : PrivacyReporter::visit (HIR::IfExprConseqElse &expr)
639 : {
640 1142 : expr.get_if_condition ().accept_vis (*this);
641 1142 : expr.get_if_block ().accept_vis (*this);
642 1142 : expr.get_else_block ().accept_vis (*this);
643 1142 : }
644 :
645 : void
646 709 : PrivacyReporter::visit (HIR::MatchExpr &expr)
647 : {
648 709 : expr.get_scrutinee_expr ().accept_vis (*this);
649 709 : }
650 :
651 : void
652 0 : PrivacyReporter::visit (HIR::AwaitExpr &)
653 : {
654 : // Not handled yet
655 0 : }
656 :
657 : void
658 0 : PrivacyReporter::visit (HIR::AsyncBlockExpr &)
659 : {
660 : // Not handled yet
661 0 : }
662 :
663 : void
664 1200 : PrivacyReporter::visit (HIR::Module &module)
665 : {
666 : // FIXME: We also need to think about module privacy
667 :
668 1200 : auto old_module = current_module;
669 1200 : current_module = module.get_mappings ().get_nodeid ();
670 :
671 5130 : for (auto &item : module.get_items ())
672 3930 : item->accept_vis (*this);
673 :
674 1200 : current_module = old_module;
675 1200 : }
676 :
677 : void
678 0 : PrivacyReporter::visit (HIR::ExternCrate &)
679 0 : {}
680 :
681 : void
682 0 : PrivacyReporter::visit (HIR::UseDeclaration &)
683 : {
684 : // FIXME: Is there anything we need to do here?
685 0 : }
686 :
687 : void
688 13224 : PrivacyReporter::visit (HIR::Function &function)
689 : {
690 19461 : for (auto ¶m : function.get_function_params ())
691 6237 : check_type_privacy (param.get_type ());
692 :
693 13224 : function.get_definition ().accept_vis (*this);
694 13224 : }
695 :
696 : void
697 1235 : PrivacyReporter::visit (HIR::TypeAlias &)
698 : {
699 : // TODO: Check the type here
700 1235 : }
701 :
702 : void
703 1498 : PrivacyReporter::visit (HIR::StructStruct &)
704 : {
705 : // TODO: Check the type of all fields
706 1498 : }
707 :
708 : void
709 934 : PrivacyReporter::visit (HIR::TupleStruct &)
710 : {
711 : // TODO: Check the type of all fields
712 934 : }
713 :
714 : void
715 0 : PrivacyReporter::visit (HIR::EnumItem &)
716 : {
717 : // TODO: Check the type of all variants
718 0 : }
719 :
720 : void
721 0 : PrivacyReporter::visit (HIR::EnumItemTuple &)
722 : {
723 : // TODO: Check the type
724 0 : }
725 :
726 : void
727 0 : PrivacyReporter::visit (HIR::EnumItemStruct &)
728 : {
729 : // TODO: Check the type
730 0 : }
731 :
732 : void
733 0 : PrivacyReporter::visit (HIR::EnumItemDiscriminant &)
734 0 : {}
735 :
736 : void
737 490 : PrivacyReporter::visit (HIR::Enum &)
738 490 : {}
739 :
740 : void
741 101 : PrivacyReporter::visit (HIR::Union &)
742 : {
743 : // TODO: Check the type
744 101 : }
745 :
746 : void
747 515 : PrivacyReporter::visit (HIR::ConstantItem &const_item)
748 : {
749 : // TODO: We need to visit the type
750 515 : const_item.get_expr ().accept_vis (*this);
751 515 : }
752 :
753 : void
754 52 : PrivacyReporter::visit (HIR::StaticItem &static_item)
755 : {
756 : // TODO: We need to visit the type
757 52 : static_item.get_expr ().accept_vis (*this);
758 52 : }
759 :
760 : void
761 3760 : PrivacyReporter::visit (HIR::Trait &)
762 : {
763 : // FIXME: We need to be an ItemVisitor as well
764 : // for (auto &item : trait.get_trait_items ())
765 : // item->accept_vis (*this);
766 3760 : }
767 :
768 : void
769 5631 : PrivacyReporter::visit (HIR::ImplBlock &impl)
770 : {
771 13762 : for (auto &item : impl.get_impl_items ())
772 8131 : item->accept_vis (*this);
773 5631 : }
774 :
775 : void
776 1633 : PrivacyReporter::visit (HIR::ExternBlock &)
777 : {
778 : // FIXME: We need to be an ItemVisitor as well
779 : // for (auto &block: block.get_extern_items ())
780 : // item->accept_vis (*this);
781 1633 : }
782 :
783 : void
784 45 : PrivacyReporter::visit (HIR::EmptyStmt &)
785 45 : {}
786 :
787 : void
788 11727 : PrivacyReporter::visit (HIR::LetStmt &stmt)
789 : {
790 11727 : if (stmt.has_type ())
791 2090 : check_type_privacy (stmt.get_type ());
792 :
793 11727 : if (stmt.has_init_expr ())
794 10626 : stmt.get_init_expr ().accept_vis (*this);
795 11727 : }
796 :
797 : void
798 10109 : PrivacyReporter::visit (HIR::ExprStmt &stmt)
799 : {
800 10109 : stmt.get_expr ().accept_vis (*this);
801 10109 : }
802 :
803 : } // namespace Privacy
804 : } // namespace Rust
|