Branch data Line data Source code
1 : : // Copyright (C) 2020-2025 Free Software Foundation, Inc.
2 : :
3 : : // This file is part of GCC.
4 : :
5 : : // GCC is free software; you can redistribute it and/or modify it under
6 : : // the terms of the GNU General Public License as published by the Free
7 : : // Software Foundation; either version 3, or (at your option) any later
8 : : // version.
9 : :
10 : : // GCC is distributed in the hope that it will be useful, but WITHOUT ANY
11 : : // WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 : : // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 : : // for more details.
14 : :
15 : : // You should have received a copy of the GNU General Public License
16 : : // along with GCC; see the file COPYING3. If not see
17 : : // <http://www.gnu.org/licenses/>.
18 : :
19 : : #include "rust-privacy-reporter.h"
20 : : #include "rust-session-manager.h"
21 : : #include "rust-hir-expr.h"
22 : : #include "rust-hir-stmt.h"
23 : : #include "rust-hir-item.h"
24 : : #include "rust-attribute-values.h"
25 : : #include "rust-immutable-name-resolution-context.h"
26 : :
27 : : namespace Rust {
28 : : namespace Privacy {
29 : :
30 : 4081 : PrivacyReporter::PrivacyReporter (
31 : : Analysis::Mappings &mappings,
32 : : const Resolver2_0::NameResolutionContext &resolver,
33 : 4081 : const Rust::Resolver::TypeCheckContext &ty_ctx)
34 : 4081 : : mappings (mappings), resolver (resolver), ty_ctx (ty_ctx),
35 : 4081 : current_module (tl::nullopt)
36 : 4081 : {}
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 : 4081 : PrivacyReporter::go (HIR::Crate &crate)
85 : : {
86 : 20986 : for (auto &item : crate.get_items ())
87 : : {
88 : 16905 : if (Session::get_instance ().options.is_proc_macro ())
89 : 6 : proc_macro_privacy_check (item);
90 : 16905 : item->accept_vis (*this);
91 : : }
92 : 4081 : }
93 : :
94 : : // FIXME: This function needs a lot of refactoring
95 : : void
96 : 46412 : PrivacyReporter::check_for_privacy_violation (const NodeId &use_id,
97 : : const location_t locus)
98 : : {
99 : 46412 : NodeId ref_node_id;
100 : :
101 : : // FIXME: Assert here. For now, we return since this causes issues when
102 : : // checking inferred types (#1260)
103 : 46412 : if (auto id = resolver.lookup (use_id))
104 : 46371 : ref_node_id = *id;
105 : : else
106 : 41 : return;
107 : :
108 : 46371 : auto vis = mappings.lookup_visibility (ref_node_id);
109 : :
110 : : // FIXME: Can we really return here if the item has no visibility?
111 : 46371 : if (!vis)
112 : : return;
113 : :
114 : 7752 : auto valid = true;
115 : :
116 : 7752 : switch (vis->get_kind ())
117 : : {
118 : : case ModuleVisibility::Public:
119 : : break;
120 : 5103 : case ModuleVisibility::Restricted:
121 : 5103 : {
122 : : // If we are in the crate, everything is restricted correctly, but we
123 : : // can't get a module for it
124 : 5103 : 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 : 11842 : 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 : 11842 : auto recursive_check
166 : 3633 : = [this, &node_mappings, &locus] (const TyTy::BaseType *ty) {
167 : 3633 : return check_base_type_privacy (node_mappings, ty, locus);
168 : 11842 : };
169 : :
170 : 11842 : switch (ty->get_kind ())
171 : : {
172 : : // These "simple" types are our stop condition
173 : 6907 : case TyTy::BOOL:
174 : 6907 : case TyTy::CHAR:
175 : 6907 : case TyTy::INT:
176 : 6907 : case TyTy::UINT:
177 : 6907 : case TyTy::FLOAT:
178 : 6907 : case TyTy::USIZE:
179 : 6907 : case TyTy::ISIZE:
180 : 6907 : case TyTy::ADT:
181 : 6907 : case TyTy::STR:
182 : 6907 : {
183 : 6907 : auto ref_id = ty->get_ref ();
184 : 6907 : if (auto lookup_id = mappings.lookup_hir_to_node (ref_id))
185 : 6907 : return check_for_privacy_violation (*lookup_id, locus);
186 : : }
187 : 0 : break;
188 : :
189 : 2199 : case TyTy::REF:
190 : 2199 : return recursive_check (
191 : 4398 : 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 : 35 : case TyTy::PROJECTION:
219 : 35 : return recursive_check (
220 : 35 : 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 : 8209 : PrivacyReporter::check_type_privacy (const HIR::Type &type)
251 : : {
252 : 8209 : TyTy::BaseType *lookup = nullptr;
253 : 8209 : rust_assert (ty_ctx.lookup_type (type.get_mappings ().get_hirid (), &lookup));
254 : :
255 : 8209 : auto node_mappings = type.get_mappings ();
256 : 8209 : return check_base_type_privacy (node_mappings, lookup, type.get_locus ());
257 : : }
258 : :
259 : : void
260 : 39399 : PrivacyReporter::visit (HIR::PathInExpression &path)
261 : : {
262 : 39399 : check_for_privacy_violation (path.get_mappings ().get_nodeid (),
263 : : path.get_locus ());
264 : 39399 : }
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 : 15597 : PrivacyReporter::visit (HIR::LiteralExpr &)
309 : : {
310 : : // Literals cannot contain any sort of privacy violation
311 : 15597 : }
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 : 303 : PrivacyReporter::visit (HIR::NegationExpr &expr)
333 : : {
334 : 303 : expr.get_expr ().accept_vis (*this);
335 : 303 : }
336 : :
337 : : void
338 : 3114 : PrivacyReporter::visit (HIR::ArithmeticOrLogicalExpr &expr)
339 : : {
340 : 3114 : expr.get_lhs ().accept_vis (*this);
341 : 3114 : expr.get_rhs ().accept_vis (*this);
342 : 3114 : }
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 : 4178 : PrivacyReporter::visit (HIR::TypeCastExpr &expr)
360 : : {
361 : 4178 : expr.get_expr ().accept_vis (*this);
362 : 4178 : }
363 : :
364 : : void
365 : 2347 : PrivacyReporter::visit (HIR::AssignmentExpr &expr)
366 : : {
367 : 2347 : expr.get_lhs ().accept_vis (*this);
368 : 2347 : expr.get_rhs ().accept_vis (*this);
369 : 2347 : }
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 : 294 : PrivacyReporter::visit (HIR::GroupedExpr &expr)
380 : : {
381 : 294 : expr.get_expr_in_parens ().accept_vis (*this);
382 : 294 : }
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 : 462 : PrivacyReporter::visit (HIR::TupleExpr &expr)
413 : : {
414 : 1376 : for (auto &value : expr.get_tuple_elems ())
415 : 914 : value->accept_vis (*this);
416 : 462 : }
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 : 76 : PrivacyReporter::visit (HIR::StructExprStruct &)
426 : : {
427 : : // FIXME: We need to check the visibility of the type it refers to here
428 : 76 : }
429 : :
430 : : void
431 : 215 : PrivacyReporter::visit (HIR::StructExprFieldIdentifier &)
432 : 215 : {}
433 : :
434 : : void
435 : 2591 : PrivacyReporter::visit (HIR::StructExprFieldIdentifierValue &field)
436 : : {
437 : 2591 : field.get_value ().accept_vis (*this);
438 : 2591 : }
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 : 1286 : PrivacyReporter::visit (HIR::StructExprStructFields &expr)
448 : : {
449 : 4134 : for (auto &field : expr.get_fields ())
450 : 2848 : field->accept_vis (*this);
451 : 1286 : }
452 : :
453 : : void
454 : 9530 : PrivacyReporter::visit (HIR::CallExpr &expr)
455 : : {
456 : 9530 : expr.get_fnexpr ().accept_vis (*this);
457 : :
458 : 21198 : for (auto ¶m : expr.get_arguments ())
459 : 11668 : param->accept_vis (*this);
460 : 9530 : }
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 : 19166 : PrivacyReporter::visit (HIR::BlockExpr &expr)
487 : : {
488 : 39552 : for (auto &stmt : expr.get_statements ())
489 : 20386 : stmt->accept_vis (*this);
490 : :
491 : 19166 : if (expr.has_final_expr ())
492 : 14238 : expr.get_final_expr ().accept_vis (*this);
493 : 19166 : }
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 : 8 : PrivacyReporter::visit (HIR::ContinueExpr &)
509 : 8 : {}
510 : :
511 : : void
512 : 39 : PrivacyReporter::visit (HIR::BreakExpr &expr)
513 : : {
514 : 39 : if (expr.has_break_expr ())
515 : 15 : expr.get_expr ().accept_vis (*this);
516 : 39 : }
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 : 366 : PrivacyReporter::visit (HIR::ReturnExpr &expr)
556 : : {
557 : 366 : if (expr.has_expr ())
558 : 336 : expr.get_expr ().accept_vis (*this);
559 : 366 : }
560 : :
561 : : void
562 : 3061 : PrivacyReporter::visit (HIR::UnsafeBlockExpr &expr)
563 : : {
564 : 3061 : expr.get_block_expr ().accept_vis (*this);
565 : 3061 : }
566 : :
567 : : void
568 : 95 : PrivacyReporter::visit (HIR::LoopExpr &expr)
569 : : {
570 : 95 : expr.get_loop_block ().accept_vis (*this);
571 : 95 : }
572 : :
573 : : void
574 : 64 : PrivacyReporter::visit (HIR::WhileLoopExpr &expr)
575 : : {
576 : 64 : expr.get_predicate_expr ().accept_vis (*this);
577 : 64 : expr.get_loop_block ().accept_vis (*this);
578 : 64 : }
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 : 450 : PrivacyReporter::visit (HIR::IfExpr &expr)
589 : : {
590 : 450 : expr.get_if_condition ().accept_vis (*this);
591 : 450 : expr.get_if_block ().accept_vis (*this);
592 : 450 : }
593 : :
594 : : void
595 : 1085 : PrivacyReporter::visit (HIR::IfExprConseqElse &expr)
596 : : {
597 : 1085 : expr.get_if_condition ().accept_vis (*this);
598 : 1085 : expr.get_if_block ().accept_vis (*this);
599 : 1085 : expr.get_else_block ().accept_vis (*this);
600 : 1085 : }
601 : :
602 : : void
603 : 685 : PrivacyReporter::visit (HIR::MatchExpr &expr)
604 : : {
605 : 685 : expr.get_scrutinee_expr ().accept_vis (*this);
606 : 685 : }
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 : 1186 : PrivacyReporter::visit (HIR::Module &module)
622 : : {
623 : : // FIXME: We also need to think about module privacy
624 : :
625 : 1186 : auto old_module = current_module;
626 : 1186 : current_module = module.get_mappings ().get_nodeid ();
627 : :
628 : 5095 : for (auto &item : module.get_items ())
629 : 3909 : item->accept_vis (*this);
630 : :
631 : 1186 : current_module = old_module;
632 : 1186 : }
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 : 12839 : PrivacyReporter::visit (HIR::Function &function)
646 : : {
647 : 19030 : for (auto ¶m : function.get_function_params ())
648 : 6191 : check_type_privacy (param.get_type ());
649 : :
650 : 12839 : function.get_definition ().accept_vis (*this);
651 : 12839 : }
652 : :
653 : : void
654 : 1198 : PrivacyReporter::visit (HIR::TypeAlias &)
655 : : {
656 : : // TODO: Check the type here
657 : 1198 : }
658 : :
659 : : void
660 : 1434 : PrivacyReporter::visit (HIR::StructStruct &)
661 : : {
662 : : // TODO: Check the type of all fields
663 : 1434 : }
664 : :
665 : : void
666 : 921 : PrivacyReporter::visit (HIR::TupleStruct &)
667 : : {
668 : : // TODO: Check the type of all fields
669 : 921 : }
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 : 479 : PrivacyReporter::visit (HIR::Enum &)
695 : 479 : {}
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 : 50 : PrivacyReporter::visit (HIR::StaticItem &static_item)
712 : : {
713 : : // TODO: We need to visit the type
714 : 50 : static_item.get_expr ().accept_vis (*this);
715 : 50 : }
716 : :
717 : : void
718 : 3520 : 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 : 3520 : }
724 : :
725 : : void
726 : 5534 : PrivacyReporter::visit (HIR::ImplBlock &impl)
727 : : {
728 : 13558 : for (auto &item : impl.get_impl_items ())
729 : 8024 : item->accept_vis (*this);
730 : 5534 : }
731 : :
732 : : void
733 : 1454 : 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 : 1454 : }
739 : :
740 : : void
741 : 44 : PrivacyReporter::visit (HIR::EmptyStmt &)
742 : 44 : {}
743 : :
744 : : void
745 : 11453 : PrivacyReporter::visit (HIR::LetStmt &stmt)
746 : : {
747 : 11453 : if (stmt.has_type ())
748 : 2018 : check_type_privacy (stmt.get_type ());
749 : :
750 : 11453 : if (stmt.has_init_expr ())
751 : 10352 : stmt.get_init_expr ().accept_vis (*this);
752 : 11453 : }
753 : :
754 : : void
755 : 8510 : PrivacyReporter::visit (HIR::ExprStmt &stmt)
756 : : {
757 : 8510 : stmt.get_expr ().accept_vis (*this);
758 : 8510 : }
759 : :
760 : : } // namespace Privacy
761 : : } // namespace Rust
|