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