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 4328 : ConstChecker::ConstChecker ()
32 4328 : : resolver (Resolver2_0::FinalizedNameResolutionContext::get ()),
33 4328 : mappings (Analysis::Mappings::get ())
34 4328 : {}
35 :
36 : void
37 4328 : ConstChecker::go (HIR::Crate &crate)
38 : {
39 22143 : for (auto &item : crate.get_items ())
40 17815 : item->accept_vis (*this);
41 4328 : }
42 :
43 : bool
44 552 : 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 1104 : return std::any_of (
51 552 : fn.get_outer_attrs ().begin (), fn.get_outer_attrs ().end (),
52 540 : [] (const AST::Attribute &attr) {
53 : // `starts_with` in C++11...
54 540 : return attr.get_path ().as_string ().rfind ("rustc_const_", 0) == 0;
55 552 : });
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 26847 : ConstChecker::ctx_allows_default (ConstGenericCtx ctx)
84 : {
85 26847 : switch (ctx)
86 : {
87 : case ConstGenericCtx::TypeAlias:
88 : case ConstGenericCtx::Struct:
89 : case ConstGenericCtx::Enum:
90 : case ConstGenericCtx::Trait:
91 : return true;
92 18938 : default:
93 18938 : return false;
94 : }
95 : }
96 :
97 : void
98 26847 : ConstChecker::check_default_const_generics (
99 : std::vector<std::unique_ptr<GenericParam>> ¶ms, ConstGenericCtx context)
100 : {
101 26847 : if (ctx_allows_default (context))
102 : return;
103 :
104 20843 : for (auto ¶m : params)
105 : {
106 1905 : if (param->get_kind () == GenericParam::GenericKind::CONST)
107 : {
108 29 : auto const_param = static_cast<ConstGenericParam *> (param.get ());
109 29 : 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 34291 : ConstChecker::visit (PathInExpression &)
129 34291 : {}
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 3580 : ConstChecker::visit (TypePath &)
145 3580 : {}
146 :
147 : void
148 15 : ConstChecker::visit (QualifiedPathInExpression &)
149 15 : {}
150 :
151 : void
152 0 : ConstChecker::visit (QualifiedPathInType &)
153 0 : {}
154 :
155 : void
156 19901 : ConstChecker::visit (LiteralExpr &)
157 19901 : {}
158 :
159 : void
160 2006 : ConstChecker::visit (BorrowExpr &expr)
161 : {
162 2006 : expr.get_expr ().accept_vis (*this);
163 2006 : }
164 :
165 : void
166 3911 : ConstChecker::visit (DereferenceExpr &expr)
167 : {
168 3911 : expr.get_expr ().accept_vis (*this);
169 3911 : }
170 :
171 : void
172 0 : ConstChecker::visit (ErrorPropagationExpr &expr)
173 : {
174 0 : expr.get_expr ().accept_vis (*this);
175 0 : }
176 :
177 : void
178 673 : ConstChecker::visit (NegationExpr &expr)
179 : {
180 673 : expr.get_expr ().accept_vis (*this);
181 673 : }
182 :
183 : void
184 3311 : ConstChecker::visit (ArithmeticOrLogicalExpr &expr)
185 : {
186 3311 : expr.get_lhs ().accept_vis (*this);
187 3311 : expr.get_rhs ().accept_vis (*this);
188 3311 : }
189 :
190 : void
191 3527 : ConstChecker::visit (ComparisonExpr &expr)
192 : {
193 3527 : expr.get_lhs ().accept_vis (*this);
194 3527 : expr.get_rhs ().accept_vis (*this);
195 3527 : }
196 :
197 : void
198 402 : ConstChecker::visit (LazyBooleanExpr &expr)
199 : {
200 402 : expr.get_lhs ().accept_vis (*this);
201 402 : expr.get_rhs ().accept_vis (*this);
202 402 : }
203 :
204 : void
205 5195 : ConstChecker::visit (TypeCastExpr &expr)
206 : {
207 5195 : expr.get_expr ().accept_vis (*this);
208 5195 : }
209 :
210 : void
211 2474 : ConstChecker::visit (AssignmentExpr &expr)
212 : {
213 2474 : expr.get_lhs ().accept_vis (*this);
214 2474 : expr.get_rhs ().accept_vis (*this);
215 2474 : }
216 :
217 : void
218 676 : ConstChecker::visit (CompoundAssignmentExpr &expr)
219 : {
220 676 : expr.get_lhs ().accept_vis (*this);
221 676 : expr.get_rhs ().accept_vis (*this);
222 676 : }
223 :
224 : void
225 293 : ConstChecker::visit (GroupedExpr &expr)
226 : {
227 293 : expr.get_expr_in_parens ().accept_vis (*this);
228 293 : }
229 :
230 : void
231 291 : ConstChecker::visit (ArrayElemsValues &elems)
232 : {
233 1765 : for (auto &elem : elems.get_values ())
234 1474 : elem->accept_vis (*this);
235 291 : }
236 :
237 : void
238 113 : ConstChecker::visit (ArrayElemsCopied &elems)
239 : {
240 113 : elems.get_elem_to_copy ().accept_vis (*this);
241 :
242 113 : const_context.enter (elems.get_mappings ().get_hirid ());
243 :
244 113 : elems.get_num_copies_expr ().accept_vis (*this);
245 :
246 113 : const_context.exit ();
247 113 : }
248 :
249 : void
250 404 : ConstChecker::visit (ArrayExpr &expr)
251 : {
252 404 : expr.get_internal_elements ().accept_vis (*this);
253 404 : }
254 :
255 : void
256 287 : ConstChecker::visit (ArrayIndexExpr &expr)
257 : {
258 287 : expr.get_array_expr ().accept_vis (*this);
259 287 : expr.get_index_expr ().accept_vis (*this);
260 287 : }
261 :
262 : void
263 542 : ConstChecker::visit (TupleExpr &expr)
264 : {
265 1483 : for (auto &elem : expr.get_tuple_elems ())
266 941 : elem->accept_vis (*this);
267 542 : }
268 :
269 : void
270 887 : ConstChecker::visit (TupleIndexExpr &expr)
271 : {
272 887 : expr.get_tuple_expr ().accept_vis (*this);
273 887 : }
274 :
275 : void
276 79 : ConstChecker::visit (StructExprStruct &)
277 79 : {}
278 :
279 : void
280 215 : ConstChecker::visit (StructExprFieldIdentifier &)
281 215 : {}
282 :
283 : void
284 2656 : ConstChecker::visit (StructExprFieldIdentifierValue &field)
285 : {
286 2656 : field.get_value ().accept_vis (*this);
287 2656 : }
288 :
289 : void
290 42 : ConstChecker::visit (StructExprFieldIndexValue &field)
291 : {
292 42 : field.get_value ().accept_vis (*this);
293 42 : }
294 :
295 : void
296 1342 : ConstChecker::visit (StructExprStructFields &expr)
297 : {
298 4255 : for (auto &field : expr.get_fields ())
299 2913 : field->accept_vis (*this);
300 1342 : }
301 :
302 : void
303 0 : ConstChecker::visit (StructExprStructBase &)
304 0 : {}
305 :
306 : void
307 12384 : ConstChecker::check_function_call (HirId fn_id, location_t locus)
308 : {
309 12384 : if (!const_context.is_in_context ())
310 11493 : return;
311 :
312 901 : auto maybe_fn = mappings.lookup_hir_item (fn_id);
313 901 : if (maybe_fn
314 901 : && 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 891 : auto maybe_extern_item = mappings.lookup_hir_extern_item (fn_id);
321 891 : if (maybe_extern_item
322 891 : && maybe_extern_item->first->get_extern_kind ()
323 : != ExternalItem::ExternKind::Function)
324 : return;
325 :
326 891 : auto is_error = false;
327 891 : if (maybe_fn)
328 : {
329 25 : auto fn = static_cast<Function *> (*maybe_fn);
330 25 : if (!fn->get_qualifiers ().is_const ())
331 891 : is_error = true;
332 : }
333 :
334 891 : if (maybe_extern_item)
335 : {
336 552 : {
337 552 : auto fn
338 552 : = static_cast<ExternalFunctionItem *> (maybe_extern_item->first);
339 552 : if (!is_const_extern_fn (*fn))
340 : is_error = true;
341 : }
342 : }
343 :
344 879 : 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 12447 : ConstChecker::visit (CallExpr &expr)
352 : {
353 12447 : if (!expr.has_fnexpr ())
354 : return;
355 :
356 12447 : NodeId ast_node_id = expr.get_fnexpr ().get_mappings ().get_nodeid ();
357 12447 : NodeId ref_node_id;
358 :
359 12447 : if (auto id = resolver.lookup (ast_node_id, Resolver2_0::Namespace::Values))
360 12384 : ref_node_id = *id;
361 : else
362 63 : return;
363 :
364 12384 : if (auto definition_id = mappings.lookup_node_to_hir (ref_node_id))
365 : {
366 12384 : check_function_call (*definition_id, expr.get_locus ());
367 :
368 26082 : for (auto &arg : expr.get_arguments ())
369 13698 : arg->accept_vis (*this);
370 : }
371 : else
372 : {
373 0 : rust_unreachable ();
374 : }
375 : }
376 :
377 : void
378 3030 : ConstChecker::visit (MethodCallExpr &expr)
379 : {
380 3030 : expr.get_receiver ().accept_vis (*this);
381 :
382 5084 : for (auto &arg : expr.get_arguments ())
383 2054 : arg->accept_vis (*this);
384 3030 : }
385 :
386 : void
387 5645 : ConstChecker::visit (FieldAccessExpr &expr)
388 : {
389 5645 : expr.get_receiver_expr ().accept_vis (*this);
390 5645 : }
391 :
392 : void
393 53 : ConstChecker::visit (ClosureExpr &expr)
394 : {
395 53 : expr.get_expr ().accept_vis (*this);
396 53 : }
397 :
398 : void
399 22792 : ConstChecker::visit (BlockExpr &expr)
400 : {
401 46625 : for (auto &stmt : expr.get_statements ())
402 23833 : stmt->accept_vis (*this);
403 :
404 22792 : if (expr.has_expr ())
405 16290 : expr.get_final_expr ().accept_vis (*this);
406 22792 : }
407 :
408 : void
409 377 : ConstChecker::visit (AnonConst &expr)
410 : {
411 377 : const_context.enter (expr.get_mappings ().get_hirid ());
412 :
413 377 : expr.get_inner_expr ().accept_vis (*this);
414 :
415 377 : const_context.exit ();
416 377 : }
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 13 : ConstChecker::visit (ContinueExpr &)
430 13 : {}
431 :
432 : void
433 85 : ConstChecker::visit (BreakExpr &expr)
434 : {
435 85 : if (expr.has_break_expr ())
436 19 : expr.get_expr ().accept_vis (*this);
437 85 : }
438 :
439 : void
440 66 : ConstChecker::visit (RangeFromToExpr &expr)
441 : {
442 66 : expr.get_from_expr ().accept_vis (*this);
443 66 : expr.get_to_expr ().accept_vis (*this);
444 66 : }
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 7 : ConstChecker::visit (RangeFromToInclExpr &expr)
464 : {
465 7 : expr.get_from_expr ().accept_vis (*this);
466 7 : expr.get_to_expr ().accept_vis (*this);
467 7 : }
468 :
469 : void
470 0 : ConstChecker::visit (RangeToInclExpr &)
471 : {
472 : // FIXME: Visit to_expr
473 0 : }
474 :
475 : void
476 1 : ConstChecker::visit (BoxExpr &expr)
477 : {
478 1 : expr.get_expr ().accept_vis (*this);
479 1 : }
480 :
481 : void
482 518 : ConstChecker::visit (ReturnExpr &expr)
483 : {
484 518 : if (expr.has_return_expr ())
485 487 : expr.get_expr ().accept_vis (*this);
486 518 : }
487 :
488 : void
489 3652 : ConstChecker::visit (UnsafeBlockExpr &expr)
490 : {
491 3652 : expr.get_block_expr ().accept_vis (*this);
492 3652 : }
493 :
494 : void
495 126 : ConstChecker::visit (LoopExpr &expr)
496 : {
497 126 : expr.get_loop_block ().accept_vis (*this);
498 126 : }
499 :
500 : void
501 74 : ConstChecker::visit (WhileLoopExpr &expr)
502 : {
503 74 : expr.get_predicate_expr ().accept_vis (*this);
504 74 : expr.get_loop_block ().accept_vis (*this);
505 74 : }
506 :
507 : void
508 0 : ConstChecker::visit (WhileLetLoopExpr &expr)
509 : {
510 0 : expr.get_cond ().accept_vis (*this);
511 0 : expr.get_loop_block ().accept_vis (*this);
512 0 : }
513 :
514 : void
515 1223 : ConstChecker::visit (IfExpr &expr)
516 : {
517 1223 : expr.get_if_condition ().accept_vis (*this);
518 1223 : expr.get_if_block ().accept_vis (*this);
519 1223 : }
520 :
521 : void
522 1257 : ConstChecker::visit (IfExprConseqElse &expr)
523 : {
524 1257 : expr.get_if_condition ().accept_vis (*this);
525 1257 : expr.get_if_block ().accept_vis (*this);
526 1257 : expr.get_else_block ().accept_vis (*this);
527 1257 : }
528 :
529 : void
530 1074 : ConstChecker::visit (MatchExpr &expr)
531 : {
532 1074 : expr.get_scrutinee_expr ().accept_vis (*this);
533 :
534 3545 : for (auto &match_arm : expr.get_match_cases ())
535 2471 : match_arm.get_expr ().accept_vis (*this);
536 1074 : }
537 :
538 : void
539 0 : ConstChecker::visit (AwaitExpr &)
540 : {
541 : // TODO: Visit expression
542 0 : }
543 :
544 : void
545 0 : ConstChecker::visit (AsyncBlockExpr &)
546 : {
547 : // TODO: Visit block expression
548 0 : }
549 :
550 : void
551 27 : ConstChecker::visit (InlineAsm &)
552 27 : {}
553 :
554 : void
555 2 : ConstChecker::visit (LlvmInlineAsm &)
556 2 : {}
557 :
558 : void
559 15 : ConstChecker::visit (OffsetOf &)
560 15 : {}
561 :
562 : void
563 0 : ConstChecker::visit (TypeParam &)
564 0 : {}
565 :
566 : void
567 0 : ConstChecker::visit (ConstGenericParam &)
568 0 : {}
569 :
570 : void
571 0 : ConstChecker::visit (LifetimeWhereClauseItem &)
572 0 : {}
573 :
574 : void
575 0 : ConstChecker::visit (TypeBoundWhereClauseItem &)
576 0 : {}
577 :
578 : void
579 1187 : ConstChecker::visit (Module &module)
580 : {
581 5091 : for (auto &item : module.get_items ())
582 3904 : item->accept_vis (*this);
583 1187 : }
584 :
585 : void
586 0 : ConstChecker::visit (ExternCrate &)
587 0 : {}
588 :
589 : void
590 0 : ConstChecker::visit (UseTreeGlob &)
591 0 : {}
592 :
593 : void
594 0 : ConstChecker::visit (UseTreeList &)
595 0 : {}
596 :
597 : void
598 0 : ConstChecker::visit (UseTreeRebind &)
599 0 : {}
600 :
601 : void
602 0 : ConstChecker::visit (UseDeclaration &)
603 0 : {}
604 :
605 : void
606 13206 : ConstChecker::visit (Function &function)
607 : {
608 13206 : auto const_fn = function.get_qualifiers ().is_const ();
609 13206 : if (const_fn)
610 890 : const_context.enter (function.get_mappings ().get_hirid ());
611 :
612 13206 : check_default_const_generics (function.get_generic_params (),
613 : ConstGenericCtx::Function);
614 :
615 19440 : for (auto ¶m : function.get_function_params ())
616 6234 : param.get_type ().accept_vis (*this);
617 :
618 13206 : function.get_definition ().accept_vis (*this);
619 :
620 13206 : if (const_fn)
621 890 : const_context.exit ();
622 13206 : }
623 :
624 : void
625 1235 : ConstChecker::visit (TypeAlias &type_alias)
626 : {
627 1235 : check_default_const_generics (type_alias.get_generic_params (),
628 : ConstGenericCtx::TypeAlias);
629 1235 : }
630 :
631 : void
632 1489 : ConstChecker::visit (StructStruct &struct_item)
633 : {
634 1489 : check_default_const_generics (struct_item.get_generic_params (),
635 : ConstGenericCtx::Struct);
636 1489 : }
637 :
638 : void
639 934 : ConstChecker::visit (TupleStruct &tuple_struct)
640 : {
641 934 : check_default_const_generics (tuple_struct.get_generic_params (),
642 : ConstGenericCtx::Struct);
643 934 : }
644 :
645 : void
646 415 : ConstChecker::visit (EnumItem &)
647 415 : {}
648 :
649 : void
650 391 : ConstChecker::visit (EnumItemTuple &)
651 391 : {}
652 :
653 : void
654 79 : ConstChecker::visit (EnumItemStruct &)
655 79 : {}
656 :
657 : void
658 274 : ConstChecker::visit (EnumItemDiscriminant &item)
659 : {
660 274 : const_context.enter (item.get_mappings ().get_hirid ());
661 :
662 274 : item.get_discriminant_expression ().accept_vis (*this);
663 :
664 274 : const_context.exit ();
665 274 : }
666 :
667 : void
668 493 : ConstChecker::visit (Enum &enum_item)
669 : {
670 493 : check_default_const_generics (enum_item.get_generic_params (),
671 : ConstGenericCtx::Enum);
672 :
673 1652 : for (auto &item : enum_item.get_variants ())
674 1159 : item->accept_vis (*this);
675 493 : }
676 :
677 : void
678 101 : ConstChecker::visit (Union &union_item)
679 : {
680 101 : check_default_const_generics (union_item.get_generic_params (),
681 : ConstGenericCtx::Union);
682 101 : }
683 :
684 : void
685 515 : ConstChecker::visit (ConstantItem &const_item)
686 : {
687 515 : const_context.enter (const_item.get_mappings ().get_hirid ());
688 :
689 515 : const_item.get_expr ().accept_vis (*this);
690 :
691 515 : const_context.exit ();
692 515 : }
693 :
694 : void
695 52 : ConstChecker::visit (StaticItem &static_item)
696 : {
697 52 : const_context.enter (static_item.get_mappings ().get_hirid ());
698 :
699 52 : static_item.get_expr ().accept_vis (*this);
700 :
701 52 : const_context.exit ();
702 52 : }
703 :
704 : void
705 2513 : ConstChecker::visit (TraitItemFunc &item)
706 : {
707 2513 : if (item.has_definition ())
708 850 : item.get_block_expr ().accept_vis (*this);
709 2513 : }
710 :
711 : void
712 31 : ConstChecker::visit (TraitItemConst &item)
713 : {
714 31 : if (item.has_expr ())
715 7 : item.get_expr ().accept_vis (*this);
716 31 : }
717 :
718 : void
719 711 : ConstChecker::visit (TraitItemType &)
720 711 : {}
721 :
722 : void
723 3758 : ConstChecker::visit (Trait &trait)
724 : {
725 3758 : check_default_const_generics (trait.get_generic_params (),
726 : ConstGenericCtx::Trait);
727 :
728 7013 : for (auto &item : trait.get_trait_items ())
729 3255 : item->accept_vis (*this);
730 3758 : }
731 :
732 : void
733 5631 : ConstChecker::visit (ImplBlock &impl)
734 : {
735 5631 : check_default_const_generics (impl.get_generic_params (),
736 : ConstGenericCtx::Impl);
737 :
738 13762 : for (auto &item : impl.get_impl_items ())
739 8131 : item->accept_vis (*this);
740 5631 : }
741 :
742 : void
743 1 : ConstChecker::visit (ExternalStaticItem &)
744 1 : {}
745 :
746 : void
747 2518 : ConstChecker::visit (ExternalFunctionItem &)
748 2518 : {}
749 :
750 : void
751 0 : ConstChecker::visit (ExternalTypeItem &)
752 0 : {}
753 :
754 : void
755 1633 : ConstChecker::visit (ExternBlock &block)
756 : {
757 : // FIXME: Do we need to do this?
758 4152 : for (auto &item : block.get_extern_items ())
759 2519 : item->accept_vis (*this);
760 1633 : }
761 :
762 : void
763 0 : ConstChecker::visit (LiteralPattern &)
764 0 : {}
765 :
766 : void
767 0 : ConstChecker::visit (IdentifierPattern &)
768 0 : {}
769 :
770 : void
771 0 : ConstChecker::visit (WildcardPattern &)
772 0 : {}
773 :
774 : void
775 0 : ConstChecker::visit (RangePatternBoundLiteral &)
776 0 : {}
777 :
778 : void
779 0 : ConstChecker::visit (RangePatternBoundPath &)
780 0 : {}
781 :
782 : void
783 0 : ConstChecker::visit (RangePatternBoundQualPath &)
784 0 : {}
785 :
786 : void
787 0 : ConstChecker::visit (RangePattern &)
788 0 : {}
789 :
790 : void
791 0 : ConstChecker::visit (ReferencePattern &)
792 0 : {}
793 :
794 : void
795 0 : ConstChecker::visit (StructPatternFieldTuplePat &)
796 0 : {}
797 :
798 : void
799 0 : ConstChecker::visit (StructPatternFieldIdentPat &)
800 0 : {}
801 :
802 : void
803 0 : ConstChecker::visit (StructPatternFieldIdent &)
804 0 : {}
805 :
806 : void
807 0 : ConstChecker::visit (StructPattern &)
808 0 : {}
809 :
810 : void
811 0 : ConstChecker::visit (TupleStructItemsNoRest &)
812 0 : {}
813 :
814 : void
815 0 : ConstChecker::visit (TupleStructItemsHasRest &)
816 0 : {}
817 :
818 : void
819 0 : ConstChecker::visit (TupleStructPattern &)
820 0 : {}
821 :
822 : void
823 0 : ConstChecker::visit (TuplePatternItemsNoRest &)
824 0 : {}
825 :
826 : void
827 0 : ConstChecker::visit (TuplePatternItemsHasRest &)
828 0 : {}
829 :
830 : void
831 0 : ConstChecker::visit (TuplePattern &)
832 0 : {}
833 :
834 : void
835 0 : ConstChecker::visit (SlicePatternItemsNoRest &)
836 0 : {}
837 :
838 : void
839 0 : ConstChecker::visit (SlicePatternItemsHasRest &)
840 0 : {}
841 :
842 : void
843 0 : ConstChecker::visit (SlicePattern &)
844 0 : {}
845 :
846 : void
847 0 : ConstChecker::visit (AltPattern &)
848 0 : {}
849 :
850 : void
851 45 : ConstChecker::visit (EmptyStmt &)
852 45 : {}
853 :
854 : void
855 12694 : ConstChecker::visit (LetStmt &stmt)
856 : {
857 12694 : if (stmt.has_init_expr ())
858 11578 : stmt.get_init_expr ().accept_vis (*this);
859 12694 : }
860 :
861 : void
862 10710 : ConstChecker::visit (ExprStmt &stmt)
863 : {
864 10710 : stmt.get_expr ().accept_vis (*this);
865 10710 : }
866 :
867 : void
868 0 : ConstChecker::visit (TraitBound &)
869 0 : {}
870 :
871 : void
872 0 : ConstChecker::visit (ImplTraitType &)
873 0 : {}
874 :
875 : void
876 0 : ConstChecker::visit (TraitObjectType &)
877 0 : {}
878 :
879 : void
880 1 : ConstChecker::visit (ParenthesisedType &)
881 1 : {}
882 :
883 : void
884 24 : ConstChecker::visit (TupleType &)
885 24 : {}
886 :
887 : void
888 0 : ConstChecker::visit (NeverType &)
889 0 : {}
890 :
891 : void
892 326 : ConstChecker::visit (RawPointerType &)
893 326 : {}
894 :
895 : void
896 1932 : ConstChecker::visit (ReferenceType &type)
897 : {
898 1932 : if (const_context.is_in_context () && type.is_mut ())
899 1 : rust_error_at (type.get_locus (), ErrorCode::E0658,
900 : "mutable references are not allowed in constant functions");
901 1932 : }
902 :
903 : void
904 362 : ConstChecker::visit (ArrayType &type)
905 : {
906 362 : const_context.enter (type.get_mappings ().get_hirid ());
907 :
908 362 : type.get_size_expr ().accept_vis (*this);
909 :
910 362 : const_context.exit ();
911 362 : }
912 :
913 : void
914 1 : ConstChecker::visit (SliceType &)
915 1 : {}
916 :
917 : void
918 0 : ConstChecker::visit (InferredType &)
919 0 : {}
920 :
921 : void
922 8 : ConstChecker::visit (BareFunctionType &)
923 8 : {}
924 :
925 : } // namespace HIR
926 : } // namespace Rust
|