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-const-checker.h"
20 : #include "rust-hir.h"
21 : #include "rust-hir-expr.h"
22 : #include "rust-hir-stmt.h"
23 : #include "rust-hir-item.h"
24 : #include "rust-rib.h"
25 : #include "rust-system.h"
26 : #include "rust-finalized-name-resolution-context.h"
27 :
28 : namespace Rust {
29 : namespace HIR {
30 :
31 4532 : ConstChecker::ConstChecker ()
32 4532 : : resolver (Resolver2_0::FinalizedNameResolutionContext::get ()),
33 4532 : mappings (Analysis::Mappings::get ())
34 4532 : {}
35 :
36 : void
37 4532 : ConstChecker::go (HIR::Crate &crate)
38 : {
39 23939 : for (auto &item : crate.get_items ())
40 19407 : item->accept_vis (*this);
41 4532 : }
42 :
43 : bool
44 678 : ConstChecker::is_const_extern_fn (HIR::ExternalFunctionItem &fn)
45 : {
46 : // FIXME: Is it really how we want to handle `rustc_const_stable`
47 : // and `rustc_const_unstable`?
48 : // TODO: Add these attributes to the attribute check and handle
49 : // `stable` and `unstable` as well
50 1356 : return std::any_of (
51 678 : fn.get_outer_attrs ().begin (), fn.get_outer_attrs ().end (),
52 666 : [] (const AST::Attribute &attr) {
53 : // `starts_with` in C++11...
54 666 : return attr.get_path ().as_string ().rfind ("rustc_const_", 0) == 0;
55 678 : });
56 : }
57 :
58 : const char *
59 0 : ConstChecker::ctx_to_str (ConstGenericCtx ctx)
60 : {
61 0 : switch (ctx)
62 : {
63 : case ConstGenericCtx::Function:
64 : return "function";
65 0 : case ConstGenericCtx::TypeAlias:
66 0 : return "type alias";
67 0 : case ConstGenericCtx::Struct:
68 0 : return "struct";
69 0 : case ConstGenericCtx::Enum:
70 0 : return "enum";
71 0 : case ConstGenericCtx::Union:
72 0 : return "union";
73 0 : case ConstGenericCtx::Trait:
74 0 : return "trait";
75 0 : case ConstGenericCtx::Impl:
76 0 : return "impl";
77 0 : default:
78 0 : rust_unreachable ();
79 : }
80 : }
81 :
82 : bool
83 29766 : ConstChecker::ctx_allows_default (ConstGenericCtx ctx)
84 : {
85 29766 : switch (ctx)
86 : {
87 : case ConstGenericCtx::TypeAlias:
88 : case ConstGenericCtx::Struct:
89 : case ConstGenericCtx::Enum:
90 : case ConstGenericCtx::Trait:
91 : return true;
92 21071 : default:
93 21071 : return false;
94 : }
95 : }
96 :
97 : void
98 29766 : ConstChecker::check_default_const_generics (
99 : std::vector<std::unique_ptr<GenericParam>> ¶ms, ConstGenericCtx context)
100 : {
101 29766 : if (ctx_allows_default (context))
102 : return;
103 :
104 23193 : for (auto ¶m : params)
105 : {
106 2122 : if (param->get_kind () == GenericParam::GenericKind::CONST)
107 : {
108 34 : auto const_param = static_cast<ConstGenericParam *> (param.get ());
109 34 : if (const_param->has_default_expression ())
110 0 : rust_error_at (
111 0 : param->get_locus (),
112 : "default values for const generic parameters are not "
113 : "allowed in %qs items",
114 : ctx_to_str (context));
115 : }
116 : }
117 : }
118 :
119 : void
120 0 : ConstChecker::visit (Lifetime &)
121 0 : {}
122 :
123 : void
124 0 : ConstChecker::visit (LifetimeParam &)
125 0 : {}
126 :
127 : void
128 37435 : ConstChecker::visit (PathInExpression &)
129 37435 : {}
130 :
131 : void
132 0 : ConstChecker::visit (TypePathSegment &)
133 0 : {}
134 :
135 : void
136 0 : ConstChecker::visit (TypePathSegmentGeneric &)
137 0 : {}
138 :
139 : void
140 0 : ConstChecker::visit (TypePathSegmentFunction &)
141 0 : {}
142 :
143 : void
144 4302 : ConstChecker::visit (TypePath &)
145 4302 : {}
146 :
147 : void
148 15 : ConstChecker::visit (QualifiedPathInExpression &)
149 15 : {}
150 :
151 : void
152 0 : ConstChecker::visit (QualifiedPathInType &)
153 0 : {}
154 :
155 : void
156 21172 : ConstChecker::visit (LiteralExpr &)
157 21172 : {}
158 :
159 : void
160 2137 : ConstChecker::visit (BorrowExpr &expr)
161 : {
162 2137 : expr.get_expr ().accept_vis (*this);
163 2137 : }
164 :
165 : void
166 4276 : ConstChecker::visit (DereferenceExpr &expr)
167 : {
168 4276 : expr.get_expr ().accept_vis (*this);
169 4276 : }
170 :
171 : void
172 0 : ConstChecker::visit (ErrorPropagationExpr &expr)
173 : {
174 0 : expr.get_expr ().accept_vis (*this);
175 0 : }
176 :
177 : void
178 701 : ConstChecker::visit (NegationExpr &expr)
179 : {
180 701 : expr.get_expr ().accept_vis (*this);
181 701 : }
182 :
183 : void
184 3729 : ConstChecker::visit (ArithmeticOrLogicalExpr &expr)
185 : {
186 3729 : expr.get_lhs ().accept_vis (*this);
187 3729 : expr.get_rhs ().accept_vis (*this);
188 3729 : }
189 :
190 : void
191 3894 : ConstChecker::visit (ComparisonExpr &expr)
192 : {
193 3894 : expr.get_lhs ().accept_vis (*this);
194 3894 : expr.get_rhs ().accept_vis (*this);
195 3894 : }
196 :
197 : void
198 480 : ConstChecker::visit (LazyBooleanExpr &expr)
199 : {
200 480 : expr.get_lhs ().accept_vis (*this);
201 480 : expr.get_rhs ().accept_vis (*this);
202 480 : }
203 :
204 : void
205 5673 : ConstChecker::visit (TypeCastExpr &expr)
206 : {
207 5673 : expr.get_expr ().accept_vis (*this);
208 5673 : }
209 :
210 : void
211 2552 : ConstChecker::visit (AssignmentExpr &expr)
212 : {
213 2552 : expr.get_lhs ().accept_vis (*this);
214 2552 : expr.get_rhs ().accept_vis (*this);
215 2552 : }
216 :
217 : void
218 719 : ConstChecker::visit (CompoundAssignmentExpr &expr)
219 : {
220 719 : expr.get_lhs ().accept_vis (*this);
221 719 : expr.get_rhs ().accept_vis (*this);
222 719 : }
223 :
224 : void
225 340 : ConstChecker::visit (GroupedExpr &expr)
226 : {
227 340 : expr.get_expr_in_parens ().accept_vis (*this);
228 340 : }
229 :
230 : void
231 298 : ConstChecker::visit (ArrayElemsValues &elems)
232 : {
233 1793 : for (auto &elem : elems.get_values ())
234 1495 : elem->accept_vis (*this);
235 298 : }
236 :
237 : void
238 116 : ConstChecker::visit (ArrayElemsCopied &elems)
239 : {
240 116 : elems.get_elem_to_copy ().accept_vis (*this);
241 :
242 116 : const_context.enter (elems.get_mappings ().get_hirid ());
243 :
244 116 : elems.get_num_copies_expr ().accept_vis (*this);
245 :
246 116 : const_context.exit ();
247 116 : }
248 :
249 : void
250 414 : ConstChecker::visit (ArrayExpr &expr)
251 : {
252 414 : expr.get_internal_elements ().accept_vis (*this);
253 414 : }
254 :
255 : void
256 293 : ConstChecker::visit (ArrayIndexExpr &expr)
257 : {
258 293 : expr.get_array_expr ().accept_vis (*this);
259 293 : expr.get_index_expr ().accept_vis (*this);
260 293 : }
261 :
262 : void
263 620 : ConstChecker::visit (TupleExpr &expr)
264 : {
265 1715 : for (auto &elem : expr.get_tuple_elems ())
266 1095 : elem->accept_vis (*this);
267 620 : }
268 :
269 : void
270 912 : ConstChecker::visit (TupleIndexExpr &expr)
271 : {
272 912 : expr.get_tuple_expr ().accept_vis (*this);
273 912 : }
274 :
275 : void
276 79 : ConstChecker::visit (StructExprStruct &)
277 79 : {}
278 :
279 : void
280 235 : ConstChecker::visit (StructExprFieldIdentifier &)
281 235 : {}
282 :
283 : void
284 2738 : ConstChecker::visit (StructExprFieldIdentifierValue &field)
285 : {
286 2738 : field.get_value ().accept_vis (*this);
287 2738 : }
288 :
289 : void
290 42 : ConstChecker::visit (StructExprFieldIndexValue &field)
291 : {
292 42 : field.get_value ().accept_vis (*this);
293 42 : }
294 :
295 : void
296 1412 : ConstChecker::visit (StructExprStructFields &expr)
297 : {
298 4427 : for (auto &field : expr.get_fields ())
299 3015 : field->accept_vis (*this);
300 1412 : }
301 :
302 : void
303 0 : ConstChecker::visit (StructExprStructBase &)
304 0 : {}
305 :
306 : void
307 13607 : ConstChecker::check_function_call (HirId fn_id, location_t locus)
308 : {
309 13607 : if (!const_context.is_in_context ())
310 12503 : return;
311 :
312 1114 : auto maybe_fn = mappings.hir.items.lookup (fn_id);
313 1114 : if (maybe_fn
314 1114 : && maybe_fn.value ()->get_item_kind () != Item::ItemKind::Function)
315 : return;
316 :
317 : // There are const extern functions (intrinsics)
318 : // TODO: Should we check the ABI is only "rust intrinsics"? Is that handled
319 : // elsewhere?
320 1104 : auto maybe_extern_item = mappings.lookup_hir_extern_item (fn_id);
321 1104 : if (maybe_extern_item
322 1104 : && maybe_extern_item->first->get_extern_kind ()
323 : != ExternalItem::ExternKind::Function)
324 : return;
325 :
326 1104 : auto is_error = false;
327 1104 : if (maybe_fn)
328 : {
329 32 : auto fn = static_cast<Function *> (*maybe_fn);
330 32 : if (!fn->get_qualifiers ().is_const ())
331 1104 : is_error = true;
332 : }
333 :
334 1104 : if (maybe_extern_item)
335 : {
336 678 : {
337 678 : auto fn
338 678 : = static_cast<ExternalFunctionItem *> (maybe_extern_item->first);
339 678 : if (!is_const_extern_fn (*fn))
340 : is_error = true;
341 : }
342 : }
343 :
344 1092 : if (is_error)
345 15 : rust_error_at (locus, ErrorCode::E0015,
346 : "only functions marked as %<const%> are allowed to be "
347 : "called from constant contexts");
348 : }
349 :
350 : void
351 13677 : ConstChecker::visit (CallExpr &expr)
352 : {
353 13677 : if (!expr.has_fnexpr ())
354 : return;
355 :
356 13677 : NodeId ast_node_id = expr.get_fnexpr ().get_mappings ().get_nodeid ();
357 13677 : NodeId ref_node_id;
358 :
359 13677 : if (auto id = resolver.lookup (ast_node_id, Resolver2_0::Namespace::Values))
360 13607 : ref_node_id = *id;
361 : else
362 70 : return;
363 :
364 13607 : if (auto definition_id = mappings.lookup_node_to_hir (ref_node_id))
365 : {
366 13607 : check_function_call (*definition_id, expr.get_locus ());
367 :
368 28803 : for (auto &arg : expr.get_arguments ())
369 15196 : arg->accept_vis (*this);
370 : }
371 : else
372 : {
373 0 : rust_unreachable ();
374 : }
375 : }
376 :
377 : void
378 3149 : ConstChecker::visit (MethodCallExpr &expr)
379 : {
380 3149 : expr.get_receiver ().accept_vis (*this);
381 :
382 5309 : for (auto &arg : expr.get_arguments ())
383 2160 : arg->accept_vis (*this);
384 3149 : }
385 :
386 : void
387 5716 : ConstChecker::visit (FieldAccessExpr &expr)
388 : {
389 5716 : expr.get_receiver_expr ().accept_vis (*this);
390 5716 : }
391 :
392 : void
393 53 : ConstChecker::visit (ClosureExpr &expr)
394 : {
395 53 : expr.get_expr ().accept_vis (*this);
396 53 : }
397 :
398 : void
399 25051 : ConstChecker::visit (BlockExpr &expr)
400 : {
401 50243 : for (auto &stmt : expr.get_statements ())
402 25192 : stmt->accept_vis (*this);
403 :
404 25051 : if (expr.has_expr ())
405 18121 : expr.get_final_expr ().accept_vis (*this);
406 25051 : }
407 :
408 : void
409 460 : ConstChecker::visit (AnonConst &expr)
410 : {
411 460 : const_context.enter (expr.get_mappings ().get_hirid ());
412 :
413 460 : expr.get_inner_expr ().accept_vis (*this);
414 :
415 460 : const_context.exit ();
416 460 : }
417 :
418 : void
419 15 : ConstChecker::visit (ConstBlock &expr)
420 : {
421 15 : const_context.enter (expr.get_mappings ().get_hirid ());
422 :
423 15 : expr.get_const_expr ().accept_vis (*this);
424 :
425 15 : const_context.exit ();
426 15 : }
427 :
428 : void
429 25 : ConstChecker::visit (ContinueExpr &)
430 25 : {}
431 :
432 : void
433 114 : ConstChecker::visit (BreakExpr &expr)
434 : {
435 114 : if (expr.has_break_expr ())
436 21 : expr.get_expr ().accept_vis (*this);
437 114 : }
438 :
439 : void
440 74 : ConstChecker::visit (RangeFromToExpr &expr)
441 : {
442 74 : expr.get_from_expr ().accept_vis (*this);
443 74 : expr.get_to_expr ().accept_vis (*this);
444 74 : }
445 :
446 : void
447 7 : ConstChecker::visit (RangeFromExpr &expr)
448 : {
449 7 : expr.get_from_expr ().accept_vis (*this);
450 7 : }
451 :
452 : void
453 7 : ConstChecker::visit (RangeToExpr &expr)
454 : {
455 7 : expr.get_to_expr ().accept_vis (*this);
456 7 : }
457 :
458 : void
459 0 : ConstChecker::visit (RangeFullExpr &)
460 0 : {}
461 :
462 : void
463 0 : ConstChecker::visit (RangeToInclExpr &)
464 : {
465 : // FIXME: Visit to_expr
466 0 : }
467 :
468 : void
469 4 : ConstChecker::visit (BoxExpr &expr)
470 : {
471 4 : expr.get_expr ().accept_vis (*this);
472 4 : }
473 :
474 : void
475 630 : ConstChecker::visit (ReturnExpr &expr)
476 : {
477 630 : if (expr.has_return_expr ())
478 594 : expr.get_expr ().accept_vis (*this);
479 630 : }
480 :
481 : void
482 4034 : ConstChecker::visit (UnsafeBlockExpr &expr)
483 : {
484 4034 : expr.get_block_expr ().accept_vis (*this);
485 4034 : }
486 :
487 : void
488 151 : ConstChecker::visit (LoopExpr &expr)
489 : {
490 151 : expr.get_loop_block ().accept_vis (*this);
491 151 : }
492 :
493 : void
494 90 : ConstChecker::visit (WhileLoopExpr &expr)
495 : {
496 90 : expr.get_predicate_expr ().accept_vis (*this);
497 90 : expr.get_loop_block ().accept_vis (*this);
498 90 : }
499 :
500 : void
501 0 : ConstChecker::visit (WhileLetLoopExpr &expr)
502 : {
503 0 : expr.get_cond ().accept_vis (*this);
504 0 : expr.get_loop_block ().accept_vis (*this);
505 0 : }
506 :
507 : void
508 1342 : ConstChecker::visit (IfExpr &expr)
509 : {
510 1342 : expr.get_if_condition ().accept_vis (*this);
511 1342 : expr.get_if_block ().accept_vis (*this);
512 1342 : }
513 :
514 : void
515 1335 : ConstChecker::visit (IfExprConseqElse &expr)
516 : {
517 1335 : expr.get_if_condition ().accept_vis (*this);
518 1335 : expr.get_if_block ().accept_vis (*this);
519 1335 : expr.get_else_block ().accept_vis (*this);
520 1335 : }
521 :
522 : void
523 1150 : ConstChecker::visit (MatchExpr &expr)
524 : {
525 1150 : expr.get_scrutinee_expr ().accept_vis (*this);
526 :
527 3818 : for (auto &match_arm : expr.get_match_cases ())
528 : {
529 2668 : if (match_arm.get_arm ().has_match_arm_guard ())
530 60 : match_arm.get_arm ().get_guard_expr ().accept_vis (*this);
531 2668 : match_arm.get_expr ().accept_vis (*this);
532 : }
533 1150 : }
534 :
535 : void
536 0 : ConstChecker::visit (AwaitExpr &)
537 : {
538 : // TODO: Visit expression
539 0 : }
540 :
541 : void
542 0 : ConstChecker::visit (AsyncBlockExpr &)
543 : {
544 : // TODO: Visit block expression
545 0 : }
546 :
547 : void
548 27 : ConstChecker::visit (InlineAsm &)
549 27 : {}
550 :
551 : void
552 2 : ConstChecker::visit (LlvmInlineAsm &)
553 2 : {}
554 :
555 : void
556 15 : ConstChecker::visit (OffsetOf &)
557 15 : {}
558 :
559 : void
560 0 : ConstChecker::visit (TypeParam &)
561 0 : {}
562 :
563 : void
564 0 : ConstChecker::visit (ConstGenericParam &)
565 0 : {}
566 :
567 : void
568 0 : ConstChecker::visit (LifetimeWhereClauseItem &)
569 0 : {}
570 :
571 : void
572 0 : ConstChecker::visit (TypeBoundWhereClauseItem &)
573 0 : {}
574 :
575 : void
576 1232 : ConstChecker::visit (Module &module)
577 : {
578 5379 : for (auto &item : module.get_items ())
579 4147 : item->accept_vis (*this);
580 1232 : }
581 :
582 : void
583 0 : ConstChecker::visit (ExternCrate &)
584 0 : {}
585 :
586 : void
587 0 : ConstChecker::visit (UseTreeGlob &)
588 0 : {}
589 :
590 : void
591 0 : ConstChecker::visit (UseTreeList &)
592 0 : {}
593 :
594 : void
595 0 : ConstChecker::visit (UseTreeRebind &)
596 0 : {}
597 :
598 : void
599 0 : ConstChecker::visit (UseDeclaration &)
600 0 : {}
601 :
602 : void
603 14619 : ConstChecker::visit (Function &function)
604 : {
605 14619 : auto const_fn = function.get_qualifiers ().is_const ();
606 14619 : if (const_fn)
607 1032 : const_context.enter (function.get_mappings ().get_hirid ());
608 :
609 14619 : check_default_const_generics (function.get_generic_params (),
610 : ConstGenericCtx::Function);
611 :
612 21895 : for (auto ¶m : function.get_function_params ())
613 7276 : param.get_type ().accept_vis (*this);
614 :
615 14619 : function.get_definition ().accept_vis (*this);
616 :
617 14619 : if (const_fn)
618 1032 : const_context.exit ();
619 14619 : }
620 :
621 : void
622 1483 : ConstChecker::visit (TypeAlias &type_alias)
623 : {
624 1483 : check_default_const_generics (type_alias.get_generic_params (),
625 : ConstGenericCtx::TypeAlias);
626 1483 : }
627 :
628 : void
629 1629 : ConstChecker::visit (StructStruct &struct_item)
630 : {
631 1629 : check_default_const_generics (struct_item.get_generic_params (),
632 : ConstGenericCtx::Struct);
633 1629 : }
634 :
635 : void
636 987 : ConstChecker::visit (TupleStruct &tuple_struct)
637 : {
638 987 : check_default_const_generics (tuple_struct.get_generic_params (),
639 : ConstGenericCtx::Struct);
640 987 : }
641 :
642 : void
643 450 : ConstChecker::visit (EnumItem &)
644 450 : {}
645 :
646 : void
647 437 : ConstChecker::visit (EnumItemTuple &)
648 437 : {}
649 :
650 : void
651 79 : ConstChecker::visit (EnumItemStruct &)
652 79 : {}
653 :
654 : void
655 280 : ConstChecker::visit (EnumItemDiscriminant &item)
656 : {
657 280 : const_context.enter (item.get_mappings ().get_hirid ());
658 :
659 280 : item.get_discriminant_expression ().accept_vis (*this);
660 :
661 280 : const_context.exit ();
662 280 : }
663 :
664 : void
665 533 : ConstChecker::visit (Enum &enum_item)
666 : {
667 533 : check_default_const_generics (enum_item.get_generic_params (),
668 : ConstGenericCtx::Enum);
669 :
670 1779 : for (auto &item : enum_item.get_variants ())
671 1246 : item->accept_vis (*this);
672 533 : }
673 :
674 : void
675 102 : ConstChecker::visit (Union &union_item)
676 : {
677 102 : check_default_const_generics (union_item.get_generic_params (),
678 : ConstGenericCtx::Union);
679 102 : }
680 :
681 : void
682 544 : ConstChecker::visit (ConstantItem &const_item)
683 : {
684 544 : const_context.enter (const_item.get_mappings ().get_hirid ());
685 :
686 544 : const_item.get_expr ().accept_vis (*this);
687 :
688 544 : const_context.exit ();
689 544 : }
690 :
691 : void
692 75 : ConstChecker::visit (StaticItem &static_item)
693 : {
694 75 : const_context.enter (static_item.get_mappings ().get_hirid ());
695 :
696 75 : static_item.get_expr ().accept_vis (*this);
697 :
698 75 : const_context.exit ();
699 75 : }
700 :
701 : void
702 2703 : ConstChecker::visit (TraitItemFunc &item)
703 : {
704 2703 : if (item.has_definition ())
705 861 : item.get_block_expr ().accept_vis (*this);
706 2703 : }
707 :
708 : void
709 32 : ConstChecker::visit (TraitItemConst &item)
710 : {
711 32 : if (item.has_expr ())
712 7 : item.get_expr ().accept_vis (*this);
713 32 : }
714 :
715 : void
716 804 : ConstChecker::visit (TraitItemType &)
717 804 : {}
718 :
719 : void
720 4063 : ConstChecker::visit (Trait &trait)
721 : {
722 4063 : check_default_const_generics (trait.get_generic_params (),
723 : ConstGenericCtx::Trait);
724 :
725 7602 : for (auto &item : trait.get_trait_items ())
726 3539 : item->accept_vis (*this);
727 4063 : }
728 :
729 : void
730 6350 : ConstChecker::visit (ImplBlock &impl)
731 : {
732 6350 : check_default_const_generics (impl.get_generic_params (),
733 : ConstGenericCtx::Impl);
734 :
735 15712 : for (auto &item : impl.get_impl_items ())
736 9362 : item->accept_vis (*this);
737 6350 : }
738 :
739 : void
740 1 : ConstChecker::visit (ExternalStaticItem &)
741 1 : {}
742 :
743 : void
744 2681 : ConstChecker::visit (ExternalFunctionItem &)
745 2681 : {}
746 :
747 : void
748 2 : ConstChecker::visit (ExternalTypeItem &)
749 2 : {}
750 :
751 : void
752 1710 : ConstChecker::visit (ExternBlock &block)
753 : {
754 : // FIXME: Do we need to do this?
755 4394 : for (auto &item : block.get_extern_items ())
756 2684 : item->accept_vis (*this);
757 1710 : }
758 :
759 : void
760 0 : ConstChecker::visit (LiteralPattern &)
761 0 : {}
762 :
763 : void
764 0 : ConstChecker::visit (IdentifierPattern &)
765 0 : {}
766 :
767 : void
768 0 : ConstChecker::visit (WildcardPattern &)
769 0 : {}
770 :
771 : void
772 0 : ConstChecker::visit (RangePatternBoundLiteral &)
773 0 : {}
774 :
775 : void
776 0 : ConstChecker::visit (RangePatternBoundPath &)
777 0 : {}
778 :
779 : void
780 0 : ConstChecker::visit (RangePatternBoundQualPath &)
781 0 : {}
782 :
783 : void
784 0 : ConstChecker::visit (RangePattern &)
785 0 : {}
786 :
787 : void
788 0 : ConstChecker::visit (ReferencePattern &)
789 0 : {}
790 :
791 : void
792 0 : ConstChecker::visit (StructPatternFieldTuplePat &)
793 0 : {}
794 :
795 : void
796 0 : ConstChecker::visit (StructPatternFieldIdentPat &)
797 0 : {}
798 :
799 : void
800 0 : ConstChecker::visit (StructPatternFieldIdent &)
801 0 : {}
802 :
803 : void
804 0 : ConstChecker::visit (StructPattern &)
805 0 : {}
806 :
807 : void
808 0 : ConstChecker::visit (TupleStructItemsNoRest &)
809 0 : {}
810 :
811 : void
812 0 : ConstChecker::visit (TupleStructItemsHasRest &)
813 0 : {}
814 :
815 : void
816 0 : ConstChecker::visit (TupleStructPattern &)
817 0 : {}
818 :
819 : void
820 0 : ConstChecker::visit (TuplePatternItemsNoRest &)
821 0 : {}
822 :
823 : void
824 0 : ConstChecker::visit (TuplePatternItemsHasRest &)
825 0 : {}
826 :
827 : void
828 0 : ConstChecker::visit (TuplePattern &)
829 0 : {}
830 :
831 : void
832 0 : ConstChecker::visit (SlicePatternItemsNoRest &)
833 0 : {}
834 :
835 : void
836 0 : ConstChecker::visit (SlicePatternItemsHasRest &)
837 0 : {}
838 :
839 : void
840 0 : ConstChecker::visit (SlicePattern &)
841 0 : {}
842 :
843 : void
844 0 : ConstChecker::visit (AltPattern &)
845 0 : {}
846 :
847 : void
848 45 : ConstChecker::visit (EmptyStmt &)
849 45 : {}
850 :
851 : void
852 13345 : ConstChecker::visit (LetStmt &stmt)
853 : {
854 13345 : if (stmt.has_init_expr ())
855 12201 : stmt.get_init_expr ().accept_vis (*this);
856 13345 : }
857 :
858 : void
859 11391 : ConstChecker::visit (ExprStmt &stmt)
860 : {
861 11391 : stmt.get_expr ().accept_vis (*this);
862 11391 : }
863 :
864 : void
865 0 : ConstChecker::visit (TraitBound &)
866 0 : {}
867 :
868 : void
869 0 : ConstChecker::visit (ImplTraitType &)
870 0 : {}
871 :
872 : void
873 0 : ConstChecker::visit (TraitObjectType &)
874 0 : {}
875 :
876 : void
877 1 : ConstChecker::visit (ParenthesisedType &)
878 1 : {}
879 :
880 : void
881 39 : ConstChecker::visit (TupleType &)
882 39 : {}
883 :
884 : void
885 0 : ConstChecker::visit (NeverType &)
886 0 : {}
887 :
888 : void
889 393 : ConstChecker::visit (RawPointerType &)
890 393 : {}
891 :
892 : void
893 2086 : ConstChecker::visit (ReferenceType &type)
894 : {
895 2086 : if (const_context.is_in_context () && type.is_mut ())
896 1 : rust_error_at (type.get_locus (), ErrorCode::E0658,
897 : "mutable references are not allowed in constant functions");
898 2086 : }
899 :
900 : void
901 445 : ConstChecker::visit (ArrayType &type)
902 : {
903 445 : const_context.enter (type.get_mappings ().get_hirid ());
904 :
905 445 : type.get_size_expr ().accept_vis (*this);
906 :
907 445 : const_context.exit ();
908 445 : }
909 :
910 : void
911 1 : ConstChecker::visit (SliceType &)
912 1 : {}
913 :
914 : void
915 0 : ConstChecker::visit (InferredType &)
916 0 : {}
917 :
918 : void
919 9 : ConstChecker::visit (BareFunctionType &)
920 9 : {}
921 :
922 : } // namespace HIR
923 : } // namespace Rust
|