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