1use crate::mir::*;
66use crate::ty::CanonicalUserTypeAnnotation;
67
68macro_rules! make_mir_visitor {
69 ($visitor_trait_name:ident, $($mutability:ident)?) => {
70 pub trait $visitor_trait_name<'tcx> {
71 fn visit_body(
75 &mut self,
76 body: &$($mutability)? Body<'tcx>,
77 ) {
78 self.super_body(body);
79 }
80
81 extra_body_methods!($($mutability)?);
82
83 fn visit_basic_block_data(
84 &mut self,
85 block: BasicBlock,
86 data: & $($mutability)? BasicBlockData<'tcx>,
87 ) {
88 self.super_basic_block_data(block, data);
89 }
90
91 fn visit_source_scope_data(
92 &mut self,
93 scope_data: & $($mutability)? SourceScopeData<'tcx>,
94 ) {
95 self.super_source_scope_data(scope_data);
96 }
97
98 fn visit_statement_debuginfo(
99 &mut self,
100 stmt_debuginfo: & $($mutability)? StmtDebugInfo<'tcx>,
101 location: Location
102 ) {
103 self.super_statement_debuginfo(stmt_debuginfo, location);
104 }
105
106 fn visit_statement(
107 &mut self,
108 statement: & $($mutability)? Statement<'tcx>,
109 location: Location,
110 ) {
111 self.super_statement(statement, location);
112 }
113
114 fn visit_assign(
115 &mut self,
116 place: & $($mutability)? Place<'tcx>,
117 rvalue: & $($mutability)? Rvalue<'tcx>,
118 location: Location,
119 ) {
120 self.super_assign(place, rvalue, location);
121 }
122
123 fn visit_terminator(
124 &mut self,
125 terminator: & $($mutability)? Terminator<'tcx>,
126 location: Location,
127 ) {
128 self.super_terminator(terminator, location);
129 }
130
131 fn visit_assert_message(
132 &mut self,
133 msg: & $($mutability)? AssertMessage<'tcx>,
134 location: Location,
135 ) {
136 self.super_assert_message(msg, location);
137 }
138
139 fn visit_rvalue(
140 &mut self,
141 rvalue: & $($mutability)? Rvalue<'tcx>,
142 location: Location,
143 ) {
144 self.super_rvalue(rvalue, location);
145 }
146
147 fn visit_operand(
148 &mut self,
149 operand: & $($mutability)? Operand<'tcx>,
150 location: Location,
151 ) {
152 self.super_operand(operand, location);
153 }
154
155 fn visit_ascribe_user_ty(
156 &mut self,
157 place: & $($mutability)? Place<'tcx>,
158 variance: $(& $mutability)? ty::Variance,
159 user_ty: & $($mutability)? UserTypeProjection,
160 location: Location,
161 ) {
162 self.super_ascribe_user_ty(place, variance, user_ty, location);
163 }
164
165 fn visit_coverage(
166 &mut self,
167 kind: & $($mutability)? coverage::CoverageKind,
168 location: Location,
169 ) {
170 self.super_coverage(kind, location);
171 }
172
173 fn visit_place(
174 &mut self,
175 place: & $($mutability)? Place<'tcx>,
176 context: PlaceContext,
177 location: Location,
178 ) {
179 self.super_place(place, context, location);
180 }
181
182 visit_place_fns!($($mutability)?);
183
184 fn visit_const_operand(
187 &mut self,
188 constant: & $($mutability)? ConstOperand<'tcx>,
189 location: Location,
190 ) {
191 self.super_const_operand(constant, location);
192 }
193
194 fn visit_ty_const(
195 &mut self,
196 ct: $( & $mutability)? ty::Const<'tcx>,
197 location: Location,
198 ) {
199 self.super_ty_const(ct, location);
200 }
201
202 fn visit_span(
203 &mut self,
204 span: $(& $mutability)? Span,
205 ) {
206 self.super_span(span);
207 }
208
209 fn visit_source_info(
210 &mut self,
211 source_info: & $($mutability)? SourceInfo,
212 ) {
213 self.super_source_info(source_info);
214 }
215
216 fn visit_ty(
217 &mut self,
218 ty: $(& $mutability)? Ty<'tcx>,
219 _: TyContext,
220 ) {
221 self.super_ty(ty);
222 }
223
224 fn visit_user_type_projection(
225 &mut self,
226 ty: & $($mutability)? UserTypeProjection,
227 ) {
228 self.super_user_type_projection(ty);
229 }
230
231 fn visit_user_type_annotation(
232 &mut self,
233 index: UserTypeAnnotationIndex,
234 ty: & $($mutability)? CanonicalUserTypeAnnotation<'tcx>,
235 ) {
236 self.super_user_type_annotation(index, ty);
237 }
238
239 fn visit_region(
240 &mut self,
241 region: $(& $mutability)? ty::Region<'tcx>,
242 _: Location,
243 ) {
244 self.super_region(region);
245 }
246
247 fn visit_args(
248 &mut self,
249 args: & $($mutability)? GenericArgs<'tcx>,
250 _: Location,
251 ) {
252 self.super_args(args);
253 }
254
255 fn visit_local_decl(
256 &mut self,
257 local: Local,
258 local_decl: & $($mutability)? LocalDecl<'tcx>,
259 ) {
260 self.super_local_decl(local, local_decl);
261 }
262
263 fn visit_var_debug_info(
264 &mut self,
265 var_debug_info: & $($mutability)* VarDebugInfo<'tcx>,
266 ) {
267 self.super_var_debug_info(var_debug_info);
268 }
269
270 fn visit_local(
271 &mut self,
272 local: $(& $mutability)? Local,
273 context: PlaceContext,
274 location: Location,
275 ) {
276 self.super_local(local, context, location)
277 }
278
279 fn visit_source_scope(
280 &mut self,
281 scope: $(& $mutability)? SourceScope,
282 ) {
283 self.super_source_scope(scope);
284 }
285
286 fn super_body(
290 &mut self,
291 body: &$($mutability)? Body<'tcx>,
292 ) {
293 super_body!(self, body, $($mutability, true)?);
294 }
295
296 fn super_basic_block_data(
297 &mut self,
298 block: BasicBlock,
299 data: & $($mutability)? BasicBlockData<'tcx>)
300 {
301 let BasicBlockData {
302 statements,
303 after_last_stmt_debuginfos,
304 terminator,
305 is_cleanup: _
306 } = data;
307
308 let mut index = 0;
309 for statement in statements {
310 let location = Location { block, statement_index: index };
311 self.visit_statement(statement, location);
312 index += 1;
313 }
314
315 let location = Location { block, statement_index: index };
316 for debuginfo in after_last_stmt_debuginfos as & $($mutability)? [_] {
317 self.visit_statement_debuginfo(debuginfo, location);
318 }
319 self.visit_terminator(terminator, location);
320 }
321
322 fn super_source_scope_data(
323 &mut self,
324 scope_data: & $($mutability)? SourceScopeData<'tcx>,
325 ) {
326 let SourceScopeData {
327 span,
328 parent_scope,
329 inlined,
330 inlined_parent_scope,
331 local_data: _,
332 } = scope_data;
333
334 self.visit_span($(& $mutability)? *span);
335 if let Some(parent_scope) = parent_scope {
336 self.visit_source_scope($(& $mutability)? *parent_scope);
337 }
338 if let Some((callee, callsite_span)) = inlined {
339 let location = Location::START;
340
341 self.visit_span($(& $mutability)? *callsite_span);
342
343 let ty::Instance { def: callee_def, args: callee_args } = callee;
344 match callee_def {
345 ty::InstanceKind::Item(_def_id) => {}
346
347 ty::InstanceKind::Intrinsic(_def_id)
348 | ty::InstanceKind::LlvmIntrinsic(_def_id)
349 | ty::InstanceKind::Shim(ty::ShimKind::VTable(_def_id))
350 | ty::InstanceKind::Shim(ty::ShimKind::Reify(_def_id, _))
351 | ty::InstanceKind::Virtual(_def_id, _)
352 | ty::InstanceKind::Shim(ty::ShimKind::ThreadLocal(_def_id))
353 | ty::InstanceKind::Shim(ty::ShimKind::ClosureOnce { call_once: _def_id, closure: _, track_caller: _ })
354 | ty::InstanceKind::Shim(ty::ShimKind::ConstructCoroutineInClosure {
355 coroutine_closure_def_id: _def_id,
356 receiver_by_ref: _,
357 })
358 | ty::InstanceKind::Shim(ty::ShimKind::DropGlue(_def_id, None)) => {}
359
360 ty::InstanceKind::Shim(ty::ShimKind::FnPtr(_def_id, ty))
361 | ty::InstanceKind::Shim(ty::ShimKind::DropGlue(_def_id, Some(ty)))
362 | ty::InstanceKind::Shim(ty::ShimKind::Clone(_def_id, ty))
363 | ty::InstanceKind::Shim(ty::ShimKind::FnAddrAsPtr(_def_id, ty))
364 | ty::InstanceKind::Shim(ty::ShimKind::FnPtrFromPtr(_def_id, ty))
365 | ty::InstanceKind::Shim(ty::ShimKind::AsyncDropGlue(_def_id, ty))
366 | ty::InstanceKind::Shim(ty::ShimKind::AsyncDropGlueCtor(_def_id, ty)) => {
367 self.visit_ty($(& $mutability)? *ty, TyContext::Location(location));
369 }
370 ty::InstanceKind::Shim(ty::ShimKind::FutureDropPoll(_def_id, proxy_ty, impl_ty)) => {
371 self.visit_ty($(& $mutability)? *proxy_ty, TyContext::Location(location));
372 self.visit_ty($(& $mutability)? *impl_ty, TyContext::Location(location));
373 }
374 }
375 self.visit_args(callee_args, location);
376 }
377 if let Some(inlined_parent_scope) = inlined_parent_scope {
378 self.visit_source_scope($(& $mutability)? *inlined_parent_scope);
379 }
380 }
381
382 fn super_statement_debuginfo(
383 &mut self,
384 stmt_debuginfo: & $($mutability)? StmtDebugInfo<'tcx>,
385 location: Location
386 ) {
387 match stmt_debuginfo {
388 StmtDebugInfo::AssignRef(local, place) => {
389 self.visit_local(
390 $(& $mutability)? *local,
391 PlaceContext::NonUse(NonUseContext::VarDebugInfo),
392 location
393 );
394 self.visit_place(
395 place,
396 PlaceContext::NonUse(NonUseContext::VarDebugInfo),
397 location
398 );
399 },
400 StmtDebugInfo::InvalidAssign(local) => {
401 self.visit_local(
402 $(& $mutability)? *local,
403 PlaceContext::NonUse(NonUseContext::VarDebugInfo),
404 location
405 );
406 }
407 }
408 }
409
410 fn super_statement(
411 &mut self,
412 statement: & $($mutability)? Statement<'tcx>,
413 location: Location
414 ) {
415 let Statement { source_info, kind, debuginfos } = statement;
416
417 self.visit_source_info(source_info);
418 for debuginfo in debuginfos as & $($mutability)? [_] {
419 self.visit_statement_debuginfo(debuginfo, location);
420 }
421 match kind {
422 StatementKind::Assign((place, rvalue)) => {
423 self.visit_assign(place, rvalue, location);
424 }
425 StatementKind::FakeRead((_, place)) => {
426 self.visit_place(
427 place,
428 PlaceContext::NonMutatingUse(NonMutatingUseContext::Inspect),
429 location
430 );
431 }
432 StatementKind::SetDiscriminant { place, .. } => {
433 self.visit_place(
434 place,
435 PlaceContext::MutatingUse(MutatingUseContext::SetDiscriminant),
436 location
437 );
438 }
439 StatementKind::StorageLive(local) => {
440 self.visit_local(
441 $(& $mutability)? *local,
442 PlaceContext::NonUse(NonUseContext::StorageLive),
443 location
444 );
445 }
446 StatementKind::StorageDead(local) => {
447 self.visit_local(
448 $(& $mutability)? *local,
449 PlaceContext::NonUse(NonUseContext::StorageDead),
450 location
451 );
452 }
453 StatementKind::PlaceMention(place) => {
454 self.visit_place(
455 place,
456 PlaceContext::NonMutatingUse(NonMutatingUseContext::PlaceMention),
457 location
458 );
459 }
460 StatementKind::AscribeUserType((place, user_ty), variance) => {
461 self.visit_ascribe_user_ty(
462 place,
463 $(& $mutability)? *variance,
464 user_ty,
465 location
466 );
467 }
468 StatementKind::Coverage(coverage) => {
469 self.visit_coverage(
470 coverage,
471 location
472 )
473 }
474 StatementKind::Intrinsic(intrinsic) => {
475 match intrinsic {
476 NonDivergingIntrinsic::Assume(op) => self.visit_operand(op, location),
477 NonDivergingIntrinsic::CopyNonOverlapping(CopyNonOverlapping {
478 src,
479 dst,
480 count
481 }) => {
482 self.visit_operand(src, location);
483 self.visit_operand(dst, location);
484 self.visit_operand(count, location);
485 }
486 }
487 }
488 StatementKind::BackwardIncompatibleDropHint { place, .. } => {
489 self.visit_place(
490 place,
491 PlaceContext::NonUse(NonUseContext::BackwardIncompatibleDropHint),
492 location
493 );
494 }
495 StatementKind::ConstEvalCounter => {}
496 StatementKind::Nop => {}
497 }
498 }
499
500 fn super_assign(
501 &mut self,
502 place: &$($mutability)? Place<'tcx>,
503 rvalue: &$($mutability)? Rvalue<'tcx>,
504 location: Location
505 ) {
506 self.visit_place(
507 place,
508 PlaceContext::MutatingUse(MutatingUseContext::Store),
509 location
510 );
511 self.visit_rvalue(rvalue, location);
512 }
513
514 fn super_terminator(
515 &mut self,
516 terminator: &$($mutability)? Terminator<'tcx>,
517 location: Location
518 ) {
519 let Terminator { source_info, kind } = terminator;
520
521 self.visit_source_info(source_info);
522 match kind {
523 TerminatorKind::Goto { .. }
524 | TerminatorKind::UnwindResume
525 | TerminatorKind::UnwindTerminate(_)
526 | TerminatorKind::CoroutineDrop
527 | TerminatorKind::Unreachable
528 | TerminatorKind::FalseEdge { .. }
529 | TerminatorKind::FalseUnwind { .. } => {}
530
531 TerminatorKind::Return => {
532 let $($mutability)? local = RETURN_PLACE;
535 self.visit_local(
536 $(& $mutability)? local,
537 PlaceContext::NonMutatingUse(NonMutatingUseContext::Move),
538 location,
539 );
540
541 assert_eq!(
542 local,
543 RETURN_PLACE,
544 "`MutVisitor` tried to mutate return place of `return` terminator"
545 );
546 }
547
548 TerminatorKind::SwitchInt { discr, targets: _ } => {
549 self.visit_operand(discr, location);
550 }
551
552 TerminatorKind::Drop {
553 place,
554 target: _,
555 unwind: _,
556 replace: _,
557 drop: _,
558 } => {
559 self.visit_place(
560 place,
561 PlaceContext::MutatingUse(MutatingUseContext::Drop),
562 location
563 );
564 }
565
566 TerminatorKind::Call {
567 func,
568 args,
569 destination,
570 target: _,
571 unwind: _,
572 call_source: _,
573 fn_span,
574 } => {
575 self.visit_span($(& $mutability)? *fn_span);
576 self.visit_operand(func, location);
577 for arg in args {
578 self.visit_operand(&$($mutability)? arg.node, location);
579 }
580 self.visit_place(
581 destination,
582 PlaceContext::MutatingUse(MutatingUseContext::Call),
583 location
584 );
585 }
586
587 TerminatorKind::TailCall { func, args, fn_span } => {
588 self.visit_span($(& $mutability)? *fn_span);
589 self.visit_operand(func, location);
590 for arg in args {
591 self.visit_operand(&$($mutability)? arg.node, location);
592 }
593 },
594
595 TerminatorKind::Assert { cond, expected: _, msg, target: _, unwind: _ } => {
596 self.visit_operand(cond, location);
597 self.visit_assert_message(msg, location);
598 }
599
600 TerminatorKind::Yield { value, resume: _, resume_arg, drop: _ } => {
601 self.visit_operand(value, location);
602 self.visit_place(
603 resume_arg,
604 PlaceContext::MutatingUse(MutatingUseContext::Yield),
605 location,
606 );
607 }
608
609 TerminatorKind::InlineAsm {
610 asm_macro: _,
611 template: _,
612 operands,
613 options: _,
614 line_spans: _,
615 targets: _,
616 unwind: _,
617 } => {
618 for op in operands {
619 match op {
620 InlineAsmOperand::In { value, .. } => {
621 self.visit_operand(value, location);
622 }
623 InlineAsmOperand::Out { place: Some(place), .. } => {
624 self.visit_place(
625 place,
626 PlaceContext::MutatingUse(MutatingUseContext::AsmOutput),
627 location,
628 );
629 }
630 InlineAsmOperand::InOut { in_value, out_place, .. } => {
631 self.visit_operand(in_value, location);
632 if let Some(out_place) = out_place {
633 self.visit_place(
634 out_place,
635 PlaceContext::MutatingUse(MutatingUseContext::AsmOutput),
636 location,
637 );
638 }
639 }
640 InlineAsmOperand::Const { value }
641 | InlineAsmOperand::SymFn { value } => {
642 self.visit_const_operand(value, location);
643 }
644 InlineAsmOperand::Out { place: None, .. }
645 | InlineAsmOperand::SymStatic { def_id: _ }
646 | InlineAsmOperand::Label { target_index: _ } => {}
647 }
648 }
649 }
650 }
651 }
652
653 fn super_assert_message(
654 &mut self,
655 msg: & $($mutability)? AssertMessage<'tcx>,
656 location: Location
657 ) {
658 use crate::mir::AssertKind::*;
659 match msg {
660 BoundsCheck { len, index } => {
661 self.visit_operand(len, location);
662 self.visit_operand(index, location);
663 }
664 Overflow(_, l, r) => {
665 self.visit_operand(l, location);
666 self.visit_operand(r, location);
667 }
668 OverflowNeg(op) | DivisionByZero(op) | RemainderByZero(op) | InvalidEnumConstruction(op) => {
669 self.visit_operand(op, location);
670 }
671 ResumedAfterReturn(_) | ResumedAfterPanic(_) | NullPointerDereference | NullReferenceConstructed | ResumedAfterDrop(_) => {
672 }
674 MisalignedPointerDereference { required, found } => {
675 self.visit_operand(required, location);
676 self.visit_operand(found, location);
677 }
678 }
679 }
680
681 fn super_rvalue(
682 &mut self,
683 rvalue: & $($mutability)? Rvalue<'tcx>,
684 location: Location
685 ) {
686 match rvalue {
687 Rvalue::Use(operand, _with_retag) => {
688 self.visit_operand(operand, location);
689 }
690
691 Rvalue::Repeat(value, ct) => {
692 self.visit_operand(value, location);
693 self.visit_ty_const($(&$mutability)? *ct, location);
694 }
695
696 Rvalue::ThreadLocalRef(_) => {}
697
698 Rvalue::Ref(r, bk, path) => {
699 self.visit_region($(& $mutability)? *r, location);
700 let ctx = match bk {
701 BorrowKind::Shared => PlaceContext::NonMutatingUse(
702 NonMutatingUseContext::SharedBorrow
703 ),
704 BorrowKind::Fake(_) => PlaceContext::NonMutatingUse(
705 NonMutatingUseContext::FakeBorrow
706 ),
707 BorrowKind::Mut { .. } =>
708 PlaceContext::MutatingUse(MutatingUseContext::Borrow),
709 };
710 self.visit_place(path, ctx, location);
711 }
712
713 Rvalue::Reborrow(target, mutability, place) => {
714 self.visit_ty($(& $mutability)? *target, TyContext::Location(location));
715 self.visit_place(
716 place,
717 match mutability {
718 Mutability::Not => PlaceContext::NonMutatingUse(NonMutatingUseContext::SharedBorrow),
719 Mutability::Mut => PlaceContext::MutatingUse(MutatingUseContext::Borrow),
720 },
721 location
722 );
723 }
724
725 Rvalue::CopyForDeref(place) => {
726 self.visit_place(
727 place,
728 PlaceContext::NonMutatingUse(NonMutatingUseContext::Inspect),
729 location
730 );
731 }
732
733 Rvalue::RawPtr(m, path) => {
734 let ctx = match m {
735 RawPtrKind::Mut => PlaceContext::MutatingUse(
736 MutatingUseContext::RawBorrow
737 ),
738 RawPtrKind::Const => PlaceContext::NonMutatingUse(
739 NonMutatingUseContext::RawBorrow
740 ),
741 RawPtrKind::FakeForPtrMetadata => PlaceContext::NonMutatingUse(
742 NonMutatingUseContext::Inspect
743 ),
744 };
745 self.visit_place(path, ctx, location);
746 }
747
748 Rvalue::Cast(_cast_kind, operand, ty) => {
749 self.visit_operand(operand, location);
750 self.visit_ty($(& $mutability)? *ty, TyContext::Location(location));
751 }
752
753 Rvalue::BinaryOp(_bin_op, (lhs, rhs)) => {
754 self.visit_operand(lhs, location);
755 self.visit_operand(rhs, location);
756 }
757
758 Rvalue::UnaryOp(_un_op, op) => {
759 self.visit_operand(op, location);
760 }
761
762 Rvalue::Discriminant(place) => {
763 self.visit_place(
764 place,
765 PlaceContext::NonMutatingUse(NonMutatingUseContext::Inspect),
766 location
767 );
768 }
769
770 Rvalue::Aggregate(kind, operands) => {
771 let kind = &$($mutability)? **kind;
772 match kind {
773 AggregateKind::Array(ty) => {
774 self.visit_ty($(& $mutability)? *ty, TyContext::Location(location));
775 }
776 AggregateKind::Tuple => {}
777 AggregateKind::Adt(
778 _adt_def,
779 _variant_index,
780 args,
781 _user_args,
782 _active_field_index
783 ) => {
784 self.visit_args(args, location);
785 }
786 AggregateKind::Closure(_, closure_args) => {
787 self.visit_args(closure_args, location);
788 }
789 AggregateKind::Coroutine(_, coroutine_args) => {
790 self.visit_args(coroutine_args, location);
791 }
792 AggregateKind::CoroutineClosure(_, coroutine_closure_args) => {
793 self.visit_args(coroutine_closure_args, location);
794 }
795 AggregateKind::RawPtr(ty, _) => {
796 self.visit_ty($(& $mutability)? *ty, TyContext::Location(location));
797 }
798 }
799
800 for operand in operands {
801 self.visit_operand(operand, location);
802 }
803 }
804
805 Rvalue::WrapUnsafeBinder(op, ty) => {
806 self.visit_operand(op, location);
807 self.visit_ty($(& $mutability)? *ty, TyContext::Location(location));
808 }
809
810
811 }
812 }
813
814 fn super_operand(
815 &mut self,
816 operand: & $($mutability)? Operand<'tcx>,
817 location: Location
818 ) {
819 match operand {
820 Operand::Copy(place) => {
821 self.visit_place(
822 place,
823 PlaceContext::NonMutatingUse(NonMutatingUseContext::Copy),
824 location
825 );
826 }
827 Operand::Move(place) => {
828 self.visit_place(
829 place,
830 PlaceContext::NonMutatingUse(NonMutatingUseContext::Move),
831 location
832 );
833 }
834 Operand::Constant(constant) => {
835 self.visit_const_operand(constant, location);
836 }
837 Operand::RuntimeChecks(_) => {}
838 }
839 }
840
841 fn super_ascribe_user_ty(
842 &mut self,
843 place: & $($mutability)? Place<'tcx>,
844 variance: $(& $mutability)? ty::Variance,
845 user_ty: & $($mutability)? UserTypeProjection,
846 location: Location)
847 {
848 self.visit_place(
849 place,
850 PlaceContext::NonUse(
851 NonUseContext::AscribeUserTy($(* &$mutability *)? variance)
852 ),
853 location
854 );
855 self.visit_user_type_projection(user_ty);
856 }
857
858 fn super_coverage(
859 &mut self,
860 _kind: & $($mutability)? coverage::CoverageKind,
861 _location: Location
862 ) {
863 }
864
865 fn super_local_decl(
866 &mut self,
867 local: Local,
868 local_decl: & $($mutability)? LocalDecl<'tcx>
869 ) {
870 let LocalDecl {
871 mutability: _,
872 ty,
873 user_ty,
874 source_info,
875 local_info: _,
876 } = local_decl;
877
878 self.visit_source_info(source_info);
879
880 self.visit_ty($(& $mutability)? *ty, TyContext::LocalDecl {
881 local,
882 source_info: *source_info,
883 });
884 if let Some(user_ty) = user_ty {
885 for user_ty in & $($mutability)? user_ty.contents {
886 self.visit_user_type_projection(user_ty);
887 }
888 }
889 }
890
891 fn super_local(
892 &mut self,
893 _local: $(& $mutability)? Local,
894 _context: PlaceContext,
895 _location: Location,
896 ) {
897 }
898
899 fn super_var_debug_info(
900 &mut self,
901 var_debug_info: & $($mutability)? VarDebugInfo<'tcx>
902 ) {
903 let VarDebugInfo {
904 name: _,
905 source_info,
906 composite,
907 value,
908 argument_index: _,
909 } = var_debug_info;
910
911 self.visit_source_info(source_info);
912 let location = Location::START;
913 if let Some(VarDebugInfoFragment {
914 ty,
915 projection
916 }) = composite {
917 self.visit_ty($(& $mutability)? *ty, TyContext::Location(location));
918 for elem in projection {
919 let ProjectionElem::Field(_, ty) = elem else { rustc_span::bug!() };
920 self.visit_ty($(& $mutability)? *ty, TyContext::Location(location));
921 }
922 }
923 match value {
924 VarDebugInfoContents::Const(c) => self.visit_const_operand(c, location),
925 VarDebugInfoContents::Place(place) =>
926 self.visit_place(
927 place,
928 PlaceContext::NonUse(NonUseContext::VarDebugInfo),
929 location
930 ),
931 }
932 }
933
934 fn super_source_scope(&mut self, _scope: $(& $mutability)? SourceScope) {}
935
936 fn super_const_operand(
937 &mut self,
938 constant: & $($mutability)? ConstOperand<'tcx>,
939 location: Location
940 ) {
941 let ConstOperand {
942 span,
943 user_ty: _, const_,
945 } = constant;
946
947 self.visit_span($(& $mutability)? *span);
948 match const_ {
949 Const::Ty(_, ct) => self.visit_ty_const($(&$mutability)? *ct, location),
950 Const::Val(_, ty) | Const::Unevaluated(_, ty) => {
951 self.visit_ty($(& $mutability)? *ty, TyContext::Location(location));
952 }
953 }
954 }
955
956 fn super_ty_const(
957 &mut self,
958 _ct: $(& $mutability)? ty::Const<'tcx>,
959 _location: Location,
960 ) {
961 }
962
963 fn super_span(&mut self, _span: $(& $mutability)? Span) {}
964
965 fn super_source_info(&mut self, source_info: & $($mutability)? SourceInfo) {
966 let SourceInfo { span, scope } = source_info;
967
968 self.visit_span($(& $mutability)? *span);
969 self.visit_source_scope($(& $mutability)? *scope);
970 }
971
972 fn super_user_type_projection(&mut self, _ty: & $($mutability)? UserTypeProjection) {}
973
974 fn super_user_type_annotation(
975 &mut self,
976 _index: UserTypeAnnotationIndex,
977 ty: & $($mutability)? CanonicalUserTypeAnnotation<'tcx>,
978 ) {
979 self.visit_span($(& $mutability)? ty.span);
980 self.visit_ty($(& $mutability)? ty.inferred_ty, TyContext::UserTy(ty.span));
981 }
982
983 fn super_ty(&mut self, _ty: $(& $mutability)? Ty<'tcx>) {}
984
985 fn super_region(&mut self, _region: $(& $mutability)? ty::Region<'tcx>) {}
986
987 fn super_args(&mut self, _args: & $($mutability)? GenericArgs<'tcx>) {}
988
989 fn visit_location(
992 &mut self,
993 body: &$($mutability)? Body<'tcx>,
994 location: Location
995 ) {
996 let basic_block =
997 & $($mutability)? basic_blocks!(body, $($mutability, true)?)[location.block];
998 if basic_block.statements.len() == location.statement_index {
999 self.visit_terminator( & $($mutability)? basic_block.terminator, location)
1000 } else {
1001 let statement = & $($mutability)?
1002 basic_block.statements[location.statement_index];
1003 self.visit_statement(statement, location)
1004 }
1005 }
1006 }
1007 }
1008}
1009
1010macro_rules! basic_blocks {
1011 ($body:ident, mut, true) => {
1012 $body.basic_blocks.as_mut()
1013 };
1014 ($body:ident, mut, false) => {
1015 $body.basic_blocks.as_mut_preserves_cfg()
1016 };
1017 ($body:ident,) => {
1018 $body.basic_blocks
1019 };
1020}
1021
1022macro_rules! basic_blocks_iter {
1023 ($body:ident, mut, $invalidate:tt) => {
1024 basic_blocks!($body, mut, $invalidate).iter_enumerated_mut()
1025 };
1026 ($body:ident,) => {
1027 basic_blocks!($body,).iter_enumerated()
1028 };
1029}
1030
1031macro_rules! extra_body_methods {
1032 (mut) => {
1033 fn visit_body_preserves_cfg(&mut self, body: &mut Body<'tcx>) {
1034 self.super_body_preserves_cfg(body);
1035 }
1036
1037 fn super_body_preserves_cfg(&mut self, body: &mut Body<'tcx>) {
1038 super_body!(self, body, mut, false);
1039 }
1040 };
1041 () => {};
1042}
1043
1044macro_rules! super_body {
1045 ($self:ident, $body:ident, $($mutability:ident, $invalidate:tt)?) => {
1046 let span = $body.span;
1047 if let Some(coroutine) = &$($mutability)? $body.coroutine {
1048 if let Some(yield_ty) = $(& $mutability)? coroutine.yield_ty {
1049 $self.visit_ty(
1050 yield_ty,
1051 TyContext::YieldTy(SourceInfo::outermost(span))
1052 );
1053 }
1054 if let Some(resume_ty) = $(& $mutability)? coroutine.resume_ty {
1055 $self.visit_ty(
1056 resume_ty,
1057 TyContext::ResumeTy(SourceInfo::outermost(span))
1058 );
1059 }
1060 }
1061
1062 for var_debug_info in &$($mutability)? $body.var_debug_info {
1063 $self.visit_var_debug_info(var_debug_info);
1064 }
1065
1066 for (bb, data) in basic_blocks_iter!($body, $($mutability, $invalidate)?) {
1067 $self.visit_basic_block_data(bb, data);
1068 }
1069
1070 for scope in &$($mutability)? $body.source_scopes {
1071 $self.visit_source_scope_data(scope);
1072 }
1073
1074 $self.visit_ty(
1075 $(& $mutability)? $body.return_ty(),
1076 TyContext::ReturnTy(SourceInfo::outermost($body.span))
1077 );
1078
1079 for local in $body.local_decls.indices() {
1080 $self.visit_local_decl(local, & $($mutability)? $body.local_decls[local]);
1081 }
1082
1083 macro_rules! type_annotations {
1084 (mut) => ($body.user_type_annotations.iter_enumerated_mut());
1085 () => ($body.user_type_annotations.iter_enumerated());
1086 }
1087
1088 for (index, annotation) in type_annotations!($($mutability)?) {
1089 $self.visit_user_type_annotation(
1090 index, annotation
1091 );
1092 }
1093
1094 $self.visit_span($(& $mutability)? $body.span);
1095
1096 if let Some(required_consts) = &$($mutability)? $body.required_consts {
1097 for const_ in required_consts {
1098 let location = Location::START;
1099 $self.visit_const_operand(const_, location);
1100 }
1101 }
1102 }
1103}
1104
1105macro_rules! visit_place_fns {
1106 (mut) => {
1107 fn tcx<'a>(&'a self) -> TyCtxt<'tcx>;
1108
1109 fn super_place(
1110 &mut self,
1111 place: &mut Place<'tcx>,
1112 context: PlaceContext,
1113 location: Location,
1114 ) {
1115 self.visit_local(&mut place.local, context, location);
1116
1117 if let Some(new_projection) = self.process_projection(&place.projection, location) {
1118 place.projection = self.tcx().mk_place_elems(&new_projection);
1119 }
1120 }
1121
1122 fn process_projection<'a>(
1123 &mut self,
1124 projection: &'a [PlaceElem<'tcx>],
1125 location: Location,
1126 ) -> Option<Vec<PlaceElem<'tcx>>> {
1127 let mut projection = Cow::Borrowed(projection);
1128
1129 for i in 0..projection.len() {
1130 if let Some(&elem) = projection.get(i) {
1131 if let Some(elem) = self.process_projection_elem(elem, location) {
1132 let vec = projection.to_mut();
1135 vec[i] = elem;
1136 }
1137 }
1138 }
1139
1140 match projection {
1141 Cow::Borrowed(_) => None,
1142 Cow::Owned(vec) => Some(vec),
1143 }
1144 }
1145
1146 fn process_projection_elem(
1147 &mut self,
1148 elem: PlaceElem<'tcx>,
1149 location: Location,
1150 ) -> Option<PlaceElem<'tcx>> {
1151 match elem {
1152 PlaceElem::Index(local) => {
1153 let mut new_local = local;
1154 self.visit_local(
1155 &mut new_local,
1156 PlaceContext::NonMutatingUse(NonMutatingUseContext::Copy),
1157 location,
1158 );
1159
1160 if new_local == local { None } else { Some(PlaceElem::Index(new_local)) }
1161 }
1162 PlaceElem::Field(field, ty) => {
1163 let mut new_ty = ty;
1164 self.visit_ty(&mut new_ty, TyContext::Location(location));
1165 if ty != new_ty { Some(PlaceElem::Field(field, new_ty)) } else { None }
1166 }
1167 PlaceElem::OpaqueCast(ty) => {
1168 let mut new_ty = ty;
1169 self.visit_ty(&mut new_ty, TyContext::Location(location));
1170 if ty != new_ty { Some(PlaceElem::OpaqueCast(new_ty)) } else { None }
1171 }
1172 PlaceElem::UnwrapUnsafeBinder(ty) => {
1173 let mut new_ty = ty;
1174 self.visit_ty(&mut new_ty, TyContext::Location(location));
1175 if ty != new_ty { Some(PlaceElem::UnwrapUnsafeBinder(new_ty)) } else { None }
1176 }
1177 PlaceElem::Deref
1178 | PlaceElem::PhantomDeref
1179 | PlaceElem::ConstantIndex { .. }
1180 | PlaceElem::Subslice { .. }
1181 | PlaceElem::Downcast(..)
1182 | PlaceElem::Wrap(_) => None,
1183 }
1184 }
1185 };
1186
1187 () => {
1188 fn visit_projection(
1189 &mut self,
1190 place_ref: PlaceRef<'tcx>,
1191 context: PlaceContext,
1192 location: Location,
1193 ) {
1194 self.super_projection(place_ref, context, location);
1195 }
1196
1197 fn visit_projection_elem(
1198 &mut self,
1199 place_ref: PlaceRef<'tcx>,
1200 elem: PlaceElem<'tcx>,
1201 context: PlaceContext,
1202 location: Location,
1203 ) {
1204 self.super_projection_elem(place_ref, elem, context, location);
1205 }
1206
1207 fn super_place(
1208 &mut self,
1209 place: &Place<'tcx>,
1210 mut context: PlaceContext,
1211 location: Location,
1212 ) {
1213 if !place.projection.is_empty() && context.is_use() {
1214 context = if context.is_mutating_use() {
1216 PlaceContext::MutatingUse(MutatingUseContext::Projection)
1217 } else {
1218 PlaceContext::NonMutatingUse(NonMutatingUseContext::Projection)
1219 };
1220 }
1221
1222 self.visit_local(place.local, context, location);
1223
1224 self.visit_projection(place.as_ref(), context, location);
1225 }
1226
1227 fn super_projection(
1228 &mut self,
1229 place_ref: PlaceRef<'tcx>,
1230 context: PlaceContext,
1231 location: Location,
1232 ) {
1233 for (base, elem) in place_ref.iter_projections().rev() {
1234 self.visit_projection_elem(base, elem, context, location);
1235 }
1236 }
1237
1238 fn super_projection_elem(
1239 &mut self,
1240 _place_ref: PlaceRef<'tcx>,
1241 elem: PlaceElem<'tcx>,
1242 context: PlaceContext,
1243 location: Location,
1244 ) {
1245 match elem {
1246 ProjectionElem::OpaqueCast(ty)
1247 | ProjectionElem::Field(_, ty)
1248 | ProjectionElem::UnwrapUnsafeBinder(ty) => {
1249 self.visit_ty(ty, TyContext::Location(location));
1250 }
1251 ProjectionElem::Index(local) => {
1252 self.visit_local(
1253 local,
1254 if context.is_use() {
1255 PlaceContext::NonMutatingUse(NonMutatingUseContext::Copy)
1257 } else {
1258 context
1259 },
1260 location,
1261 );
1262 }
1263 ProjectionElem::Deref
1264 | ProjectionElem::PhantomDeref
1265 | ProjectionElem::Subslice { from: _, to: _, from_end: _ }
1266 | ProjectionElem::ConstantIndex { offset: _, min_length: _, from_end: _ }
1267 | ProjectionElem::Downcast(_, _)
1268 | ProjectionElem::Wrap(_) => {}
1269 }
1270 }
1271 };
1272}
1273
1274pub trait Visitor<'tcx> {
fn visit_body(&mut self, body: &Body<'tcx>) { self.super_body(body); }
fn visit_basic_block_data(&mut self, block: BasicBlock,
data: &BasicBlockData<'tcx>) {
self.super_basic_block_data(block, data);
}
fn visit_source_scope_data(&mut self,
scope_data: &SourceScopeData<'tcx>) {
self.super_source_scope_data(scope_data);
}
fn visit_statement_debuginfo(&mut self,
stmt_debuginfo: &StmtDebugInfo<'tcx>, location: Location) {
self.super_statement_debuginfo(stmt_debuginfo, location);
}
fn visit_statement(&mut self, statement: &Statement<'tcx>,
location: Location) {
self.super_statement(statement, location);
}
fn visit_assign(&mut self, place: &Place<'tcx>, rvalue: &Rvalue<'tcx>,
location: Location) {
self.super_assign(place, rvalue, location);
}
fn visit_terminator(&mut self, terminator: &Terminator<'tcx>,
location: Location) {
self.super_terminator(terminator, location);
}
fn visit_assert_message(&mut self, msg: &AssertMessage<'tcx>,
location: Location) {
self.super_assert_message(msg, location);
}
fn visit_rvalue(&mut self, rvalue: &Rvalue<'tcx>, location: Location) {
self.super_rvalue(rvalue, location);
}
fn visit_operand(&mut self, operand: &Operand<'tcx>, location: Location) {
self.super_operand(operand, location);
}
fn visit_ascribe_user_ty(&mut self, place: &Place<'tcx>,
variance: ty::Variance, user_ty: &UserTypeProjection,
location: Location) {
self.super_ascribe_user_ty(place, variance, user_ty, location);
}
fn visit_coverage(&mut self, kind: &coverage::CoverageKind,
location: Location) {
self.super_coverage(kind, location);
}
fn visit_place(&mut self, place: &Place<'tcx>, context: PlaceContext,
location: Location) {
self.super_place(place, context, location);
}
fn visit_projection(&mut self, place_ref: PlaceRef<'tcx>,
context: PlaceContext, location: Location) {
self.super_projection(place_ref, context, location);
}
fn visit_projection_elem(&mut self, place_ref: PlaceRef<'tcx>,
elem: PlaceElem<'tcx>, context: PlaceContext, location: Location) {
self.super_projection_elem(place_ref, elem, context, location);
}
fn super_place(&mut self, place: &Place<'tcx>, mut context: PlaceContext,
location: Location) {
if !place.projection.is_empty() && context.is_use() {
context =
if context.is_mutating_use() {
PlaceContext::MutatingUse(MutatingUseContext::Projection)
} else {
PlaceContext::NonMutatingUse(NonMutatingUseContext::Projection)
};
}
self.visit_local(place.local, context, location);
self.visit_projection(place.as_ref(), context, location);
}
fn super_projection(&mut self, place_ref: PlaceRef<'tcx>,
context: PlaceContext, location: Location) {
for (base, elem) in place_ref.iter_projections().rev() {
self.visit_projection_elem(base, elem, context, location);
}
}
fn super_projection_elem(&mut self, _place_ref: PlaceRef<'tcx>,
elem: PlaceElem<'tcx>, context: PlaceContext, location: Location) {
match elem {
ProjectionElem::OpaqueCast(ty) | ProjectionElem::Field(_, ty) |
ProjectionElem::UnwrapUnsafeBinder(ty) => {
self.visit_ty(ty, TyContext::Location(location));
}
ProjectionElem::Index(local) => {
self.visit_local(local,
if context.is_use() {
PlaceContext::NonMutatingUse(NonMutatingUseContext::Copy)
} else { context }, location);
}
ProjectionElem::Deref | ProjectionElem::PhantomDeref |
ProjectionElem::Subslice { from: _, to: _, from_end: _ } |
ProjectionElem::ConstantIndex {
offset: _, min_length: _, from_end: _ } |
ProjectionElem::Downcast(_, _) | ProjectionElem::Wrap(_) => {}
}
}
fn visit_const_operand(&mut self, constant: &ConstOperand<'tcx>,
location: Location) {
self.super_const_operand(constant, location);
}
fn visit_ty_const(&mut self, ct: ty::Const<'tcx>, location: Location) {
self.super_ty_const(ct, location);
}
fn visit_span(&mut self, span: Span) { self.super_span(span); }
fn visit_source_info(&mut self, source_info: &SourceInfo) {
self.super_source_info(source_info);
}
fn visit_ty(&mut self, ty: Ty<'tcx>, _: TyContext) { self.super_ty(ty); }
fn visit_user_type_projection(&mut self, ty: &UserTypeProjection) {
self.super_user_type_projection(ty);
}
fn visit_user_type_annotation(&mut self, index: UserTypeAnnotationIndex,
ty: &CanonicalUserTypeAnnotation<'tcx>) {
self.super_user_type_annotation(index, ty);
}
fn visit_region(&mut self, region: ty::Region<'tcx>, _: Location) {
self.super_region(region);
}
fn visit_args(&mut self, args: &GenericArgs<'tcx>, _: Location) {
self.super_args(args);
}
fn visit_local_decl(&mut self, local: Local,
local_decl: &LocalDecl<'tcx>) {
self.super_local_decl(local, local_decl);
}
fn visit_var_debug_info(&mut self, var_debug_info: &VarDebugInfo<'tcx>) {
self.super_var_debug_info(var_debug_info);
}
fn visit_local(&mut self, local: Local, context: PlaceContext,
location: Location) {
self.super_local(local, context, location)
}
fn visit_source_scope(&mut self, scope: SourceScope) {
self.super_source_scope(scope);
}
fn super_body(&mut self, body: &Body<'tcx>) {
let span = body.span;
if let Some(coroutine) = &body.coroutine {
if let Some(yield_ty) = coroutine.yield_ty {
self.visit_ty(yield_ty,
TyContext::YieldTy(SourceInfo::outermost(span)));
}
if let Some(resume_ty) = coroutine.resume_ty {
self.visit_ty(resume_ty,
TyContext::ResumeTy(SourceInfo::outermost(span)));
}
}
for var_debug_info in &body.var_debug_info {
self.visit_var_debug_info(var_debug_info);
}
for (bb, data) in body.basic_blocks.iter_enumerated() {
self.visit_basic_block_data(bb, data);
}
for scope in &body.source_scopes {
self.visit_source_scope_data(scope);
}
self.visit_ty(body.return_ty(),
TyContext::ReturnTy(SourceInfo::outermost(body.span)));
for local in body.local_decls.indices() {
self.visit_local_decl(local, &body.local_decls[local]);
}
macro_rules! type_annotations {
(mut) => (body.user_type_annotations.iter_enumerated_mut()); () =>
(body.user_type_annotations.iter_enumerated());
}
for (index, annotation) in
body.user_type_annotations.iter_enumerated() {
self.visit_user_type_annotation(index, annotation);
}
self.visit_span(body.span);
if let Some(required_consts) = &body.required_consts {
for const_ in required_consts {
let location = Location::START;
self.visit_const_operand(const_, location);
}
};
}
fn super_basic_block_data(&mut self, block: BasicBlock,
data: &BasicBlockData<'tcx>) {
let BasicBlockData {
statements,
after_last_stmt_debuginfos,
terminator,
is_cleanup: _ } = data;
let mut index = 0;
for statement in statements {
let location = Location { block, statement_index: index };
self.visit_statement(statement, location);
index += 1;
}
let location = Location { block, statement_index: index };
for debuginfo in after_last_stmt_debuginfos as &[_] {
self.visit_statement_debuginfo(debuginfo, location);
}
self.visit_terminator(terminator, location);
}
fn super_source_scope_data(&mut self,
scope_data: &SourceScopeData<'tcx>) {
let SourceScopeData {
span,
parent_scope,
inlined,
inlined_parent_scope,
local_data: _ } = scope_data;
self.visit_span(*span);
if let Some(parent_scope) = parent_scope {
self.visit_source_scope(*parent_scope);
}
if let Some((callee, callsite_span)) = inlined {
let location = Location::START;
self.visit_span(*callsite_span);
let ty::Instance { def: callee_def, args: callee_args } = callee;
match callee_def {
ty::InstanceKind::Item(_def_id) => {}
ty::InstanceKind::Intrinsic(_def_id) |
ty::InstanceKind::LlvmIntrinsic(_def_id) |
ty::InstanceKind::Shim(ty::ShimKind::VTable(_def_id)) |
ty::InstanceKind::Shim(ty::ShimKind::Reify(_def_id, _)) |
ty::InstanceKind::Virtual(_def_id, _) |
ty::InstanceKind::Shim(ty::ShimKind::ThreadLocal(_def_id)) |
ty::InstanceKind::Shim(ty::ShimKind::ClosureOnce {
call_once: _def_id, closure: _, track_caller: _ }) |
ty::InstanceKind::Shim(ty::ShimKind::ConstructCoroutineInClosure {
coroutine_closure_def_id: _def_id, receiver_by_ref: _ }) |
ty::InstanceKind::Shim(ty::ShimKind::DropGlue(_def_id,
None)) => {}
ty::InstanceKind::Shim(ty::ShimKind::FnPtr(_def_id, ty)) |
ty::InstanceKind::Shim(ty::ShimKind::DropGlue(_def_id,
Some(ty))) |
ty::InstanceKind::Shim(ty::ShimKind::Clone(_def_id, ty)) |
ty::InstanceKind::Shim(ty::ShimKind::FnAddrAsPtr(_def_id,
ty)) |
ty::InstanceKind::Shim(ty::ShimKind::FnPtrFromPtr(_def_id,
ty)) |
ty::InstanceKind::Shim(ty::ShimKind::AsyncDropGlue(_def_id,
ty)) |
ty::InstanceKind::Shim(ty::ShimKind::AsyncDropGlueCtor(_def_id,
ty)) => {
self.visit_ty(*ty, TyContext::Location(location));
}
ty::InstanceKind::Shim(ty::ShimKind::FutureDropPoll(_def_id,
proxy_ty, impl_ty)) => {
self.visit_ty(*proxy_ty, TyContext::Location(location));
self.visit_ty(*impl_ty, TyContext::Location(location));
}
}
self.visit_args(callee_args, location);
}
if let Some(inlined_parent_scope) = inlined_parent_scope {
self.visit_source_scope(*inlined_parent_scope);
}
}
fn super_statement_debuginfo(&mut self,
stmt_debuginfo: &StmtDebugInfo<'tcx>, location: Location) {
match stmt_debuginfo {
StmtDebugInfo::AssignRef(local, place) => {
self.visit_local(*local,
PlaceContext::NonUse(NonUseContext::VarDebugInfo),
location);
self.visit_place(place,
PlaceContext::NonUse(NonUseContext::VarDebugInfo),
location);
}
StmtDebugInfo::InvalidAssign(local) => {
self.visit_local(*local,
PlaceContext::NonUse(NonUseContext::VarDebugInfo),
location);
}
}
}
fn super_statement(&mut self, statement: &Statement<'tcx>,
location: Location) {
let Statement { source_info, kind, debuginfos } = statement;
self.visit_source_info(source_info);
for debuginfo in debuginfos as &[_] {
self.visit_statement_debuginfo(debuginfo, location);
}
match kind {
StatementKind::Assign((place, rvalue)) => {
self.visit_assign(place, rvalue, location);
}
StatementKind::FakeRead((_, place)) => {
self.visit_place(place,
PlaceContext::NonMutatingUse(NonMutatingUseContext::Inspect),
location);
}
StatementKind::SetDiscriminant { place, .. } => {
self.visit_place(place,
PlaceContext::MutatingUse(MutatingUseContext::SetDiscriminant),
location);
}
StatementKind::StorageLive(local) => {
self.visit_local(*local,
PlaceContext::NonUse(NonUseContext::StorageLive), location);
}
StatementKind::StorageDead(local) => {
self.visit_local(*local,
PlaceContext::NonUse(NonUseContext::StorageDead), location);
}
StatementKind::PlaceMention(place) => {
self.visit_place(place,
PlaceContext::NonMutatingUse(NonMutatingUseContext::PlaceMention),
location);
}
StatementKind::AscribeUserType((place, user_ty), variance) => {
self.visit_ascribe_user_ty(place, *variance, user_ty,
location);
}
StatementKind::Coverage(coverage) => {
self.visit_coverage(coverage, location)
}
StatementKind::Intrinsic(intrinsic) => {
match intrinsic {
NonDivergingIntrinsic::Assume(op) =>
self.visit_operand(op, location),
NonDivergingIntrinsic::CopyNonOverlapping(CopyNonOverlapping {
src, dst, count }) => {
self.visit_operand(src, location);
self.visit_operand(dst, location);
self.visit_operand(count, location);
}
}
}
StatementKind::BackwardIncompatibleDropHint { place, .. } => {
self.visit_place(place,
PlaceContext::NonUse(NonUseContext::BackwardIncompatibleDropHint),
location);
}
StatementKind::ConstEvalCounter => {}
StatementKind::Nop => {}
}
}
fn super_assign(&mut self, place: &Place<'tcx>, rvalue: &Rvalue<'tcx>,
location: Location) {
self.visit_place(place,
PlaceContext::MutatingUse(MutatingUseContext::Store), location);
self.visit_rvalue(rvalue, location);
}
fn super_terminator(&mut self, terminator: &Terminator<'tcx>,
location: Location) {
let Terminator { source_info, kind } = terminator;
self.visit_source_info(source_info);
match kind {
TerminatorKind::Goto { .. } | TerminatorKind::UnwindResume |
TerminatorKind::UnwindTerminate(_) |
TerminatorKind::CoroutineDrop | TerminatorKind::Unreachable |
TerminatorKind::FalseEdge { .. } |
TerminatorKind::FalseUnwind { .. } => {}
TerminatorKind::Return => {
let local = RETURN_PLACE;
self.visit_local(local,
PlaceContext::NonMutatingUse(NonMutatingUseContext::Move),
location);
{
match (&local, &RETURN_PLACE) {
(left_val, right_val) => {
if !(*left_val == *right_val) {
let kind = ::core::panicking::AssertKind::Eq;
::core::panicking::assert_failed(kind, &*left_val,
&*right_val,
::core::option::Option::Some(format_args!("`MutVisitor` tried to mutate return place of `return` terminator")));
}
}
}
};
}
TerminatorKind::SwitchInt { discr, targets: _ } => {
self.visit_operand(discr, location);
}
TerminatorKind::Drop {
place, target: _, unwind: _, replace: _, drop: _ } => {
self.visit_place(place,
PlaceContext::MutatingUse(MutatingUseContext::Drop),
location);
}
TerminatorKind::Call {
func,
args,
destination,
target: _,
unwind: _,
call_source: _,
fn_span } => {
self.visit_span(*fn_span);
self.visit_operand(func, location);
for arg in args { self.visit_operand(&arg.node, location); }
self.visit_place(destination,
PlaceContext::MutatingUse(MutatingUseContext::Call),
location);
}
TerminatorKind::TailCall { func, args, fn_span } => {
self.visit_span(*fn_span);
self.visit_operand(func, location);
for arg in args { self.visit_operand(&arg.node, location); }
}
TerminatorKind::Assert {
cond, expected: _, msg, target: _, unwind: _ } => {
self.visit_operand(cond, location);
self.visit_assert_message(msg, location);
}
TerminatorKind::Yield { value, resume: _, resume_arg, drop: _ } =>
{
self.visit_operand(value, location);
self.visit_place(resume_arg,
PlaceContext::MutatingUse(MutatingUseContext::Yield),
location);
}
TerminatorKind::InlineAsm {
asm_macro: _,
template: _,
operands,
options: _,
line_spans: _,
targets: _,
unwind: _ } => {
for op in operands {
match op {
InlineAsmOperand::In { value, .. } => {
self.visit_operand(value, location);
}
InlineAsmOperand::Out { place: Some(place), .. } => {
self.visit_place(place,
PlaceContext::MutatingUse(MutatingUseContext::AsmOutput),
location);
}
InlineAsmOperand::InOut { in_value, out_place, .. } => {
self.visit_operand(in_value, location);
if let Some(out_place) = out_place {
self.visit_place(out_place,
PlaceContext::MutatingUse(MutatingUseContext::AsmOutput),
location);
}
}
InlineAsmOperand::Const { value } |
InlineAsmOperand::SymFn { value } => {
self.visit_const_operand(value, location);
}
InlineAsmOperand::Out { place: None, .. } |
InlineAsmOperand::SymStatic { def_id: _ } |
InlineAsmOperand::Label { target_index: _ } => {}
}
}
}
}
}
fn super_assert_message(&mut self, msg: &AssertMessage<'tcx>,
location: Location) {
use crate::mir::AssertKind::*;
match msg {
BoundsCheck { len, index } => {
self.visit_operand(len, location);
self.visit_operand(index, location);
}
Overflow(_, l, r) => {
self.visit_operand(l, location);
self.visit_operand(r, location);
}
OverflowNeg(op) | DivisionByZero(op) | RemainderByZero(op) |
InvalidEnumConstruction(op) => {
self.visit_operand(op, location);
}
ResumedAfterReturn(_) | ResumedAfterPanic(_) |
NullPointerDereference | NullReferenceConstructed |
ResumedAfterDrop(_) => {}
MisalignedPointerDereference { required, found } => {
self.visit_operand(required, location);
self.visit_operand(found, location);
}
}
}
fn super_rvalue(&mut self, rvalue: &Rvalue<'tcx>, location: Location) {
match rvalue {
Rvalue::Use(operand, _with_retag) => {
self.visit_operand(operand, location);
}
Rvalue::Repeat(value, ct) => {
self.visit_operand(value, location);
self.visit_ty_const(*ct, location);
}
Rvalue::ThreadLocalRef(_) => {}
Rvalue::Ref(r, bk, path) => {
self.visit_region(*r, location);
let ctx =
match bk {
BorrowKind::Shared =>
PlaceContext::NonMutatingUse(NonMutatingUseContext::SharedBorrow),
BorrowKind::Fake(_) =>
PlaceContext::NonMutatingUse(NonMutatingUseContext::FakeBorrow),
BorrowKind::Mut { .. } =>
PlaceContext::MutatingUse(MutatingUseContext::Borrow),
};
self.visit_place(path, ctx, location);
}
Rvalue::Reborrow(target, mutability, place) => {
self.visit_ty(*target, TyContext::Location(location));
self.visit_place(place,
match mutability {
Mutability::Not =>
PlaceContext::NonMutatingUse(NonMutatingUseContext::SharedBorrow),
Mutability::Mut =>
PlaceContext::MutatingUse(MutatingUseContext::Borrow),
}, location);
}
Rvalue::CopyForDeref(place) => {
self.visit_place(place,
PlaceContext::NonMutatingUse(NonMutatingUseContext::Inspect),
location);
}
Rvalue::RawPtr(m, path) => {
let ctx =
match m {
RawPtrKind::Mut =>
PlaceContext::MutatingUse(MutatingUseContext::RawBorrow),
RawPtrKind::Const =>
PlaceContext::NonMutatingUse(NonMutatingUseContext::RawBorrow),
RawPtrKind::FakeForPtrMetadata =>
PlaceContext::NonMutatingUse(NonMutatingUseContext::Inspect),
};
self.visit_place(path, ctx, location);
}
Rvalue::Cast(_cast_kind, operand, ty) => {
self.visit_operand(operand, location);
self.visit_ty(*ty, TyContext::Location(location));
}
Rvalue::BinaryOp(_bin_op, (lhs, rhs)) => {
self.visit_operand(lhs, location);
self.visit_operand(rhs, location);
}
Rvalue::UnaryOp(_un_op, op) => {
self.visit_operand(op, location);
}
Rvalue::Discriminant(place) => {
self.visit_place(place,
PlaceContext::NonMutatingUse(NonMutatingUseContext::Inspect),
location);
}
Rvalue::Aggregate(kind, operands) => {
let kind = &**kind;
match kind {
AggregateKind::Array(ty) => {
self.visit_ty(*ty, TyContext::Location(location));
}
AggregateKind::Tuple => {}
AggregateKind::Adt(_adt_def, _variant_index, args,
_user_args, _active_field_index) => {
self.visit_args(args, location);
}
AggregateKind::Closure(_, closure_args) => {
self.visit_args(closure_args, location);
}
AggregateKind::Coroutine(_, coroutine_args) => {
self.visit_args(coroutine_args, location);
}
AggregateKind::CoroutineClosure(_, coroutine_closure_args)
=> {
self.visit_args(coroutine_closure_args, location);
}
AggregateKind::RawPtr(ty, _) => {
self.visit_ty(*ty, TyContext::Location(location));
}
}
for operand in operands {
self.visit_operand(operand, location);
}
}
Rvalue::WrapUnsafeBinder(op, ty) => {
self.visit_operand(op, location);
self.visit_ty(*ty, TyContext::Location(location));
}
}
}
fn super_operand(&mut self, operand: &Operand<'tcx>, location: Location) {
match operand {
Operand::Copy(place) => {
self.visit_place(place,
PlaceContext::NonMutatingUse(NonMutatingUseContext::Copy),
location);
}
Operand::Move(place) => {
self.visit_place(place,
PlaceContext::NonMutatingUse(NonMutatingUseContext::Move),
location);
}
Operand::Constant(constant) => {
self.visit_const_operand(constant, location);
}
Operand::RuntimeChecks(_) => {}
}
}
fn super_ascribe_user_ty(&mut self, place: &Place<'tcx>,
variance: ty::Variance, user_ty: &UserTypeProjection,
location: Location) {
self.visit_place(place,
PlaceContext::NonUse(NonUseContext::AscribeUserTy(variance)),
location);
self.visit_user_type_projection(user_ty);
}
fn super_coverage(&mut self, _kind: &coverage::CoverageKind,
_location: Location) {}
fn super_local_decl(&mut self, local: Local,
local_decl: &LocalDecl<'tcx>) {
let LocalDecl { mutability: _, ty, user_ty, source_info, local_info: _
} = local_decl;
self.visit_source_info(source_info);
self.visit_ty(*ty,
TyContext::LocalDecl { local, source_info: *source_info });
if let Some(user_ty) = user_ty {
for user_ty in &user_ty.contents {
self.visit_user_type_projection(user_ty);
}
}
}
fn super_local(&mut self, _local: Local, _context: PlaceContext,
_location: Location) {}
fn super_var_debug_info(&mut self, var_debug_info: &VarDebugInfo<'tcx>) {
let VarDebugInfo {
name: _, source_info, composite, value, argument_index: _ } =
var_debug_info;
self.visit_source_info(source_info);
let location = Location::START;
if let Some(VarDebugInfoFragment { ty, projection }) = composite {
self.visit_ty(*ty, TyContext::Location(location));
for elem in projection {
let ProjectionElem::Field(_, ty) =
elem else {
::rustc_span::macros::bug_impl(None,
format_args!("impossible case reached"), Location::caller())
};
self.visit_ty(*ty, TyContext::Location(location));
}
}
match value {
VarDebugInfoContents::Const(c) =>
self.visit_const_operand(c, location),
VarDebugInfoContents::Place(place) =>
self.visit_place(place,
PlaceContext::NonUse(NonUseContext::VarDebugInfo),
location),
}
}
fn super_source_scope(&mut self, _scope: SourceScope) {}
fn super_const_operand(&mut self, constant: &ConstOperand<'tcx>,
location: Location) {
let ConstOperand { span, user_ty: _, const_ } = constant;
self.visit_span(*span);
match const_ {
Const::Ty(_, ct) => self.visit_ty_const(*ct, location),
Const::Val(_, ty) | Const::Unevaluated(_, ty) => {
self.visit_ty(*ty, TyContext::Location(location));
}
}
}
fn super_ty_const(&mut self, _ct: ty::Const<'tcx>, _location: Location) {}
fn super_span(&mut self, _span: Span) {}
fn super_source_info(&mut self, source_info: &SourceInfo) {
let SourceInfo { span, scope } = source_info;
self.visit_span(*span);
self.visit_source_scope(*scope);
}
fn super_user_type_projection(&mut self, _ty: &UserTypeProjection) {}
fn super_user_type_annotation(&mut self, _index: UserTypeAnnotationIndex,
ty: &CanonicalUserTypeAnnotation<'tcx>) {
self.visit_span(ty.span);
self.visit_ty(ty.inferred_ty, TyContext::UserTy(ty.span));
}
fn super_ty(&mut self, _ty: Ty<'tcx>) {}
fn super_region(&mut self, _region: ty::Region<'tcx>) {}
fn super_args(&mut self, _args: &GenericArgs<'tcx>) {}
fn visit_location(&mut self, body: &Body<'tcx>, location: Location) {
let basic_block = &body.basic_blocks[location.block];
if basic_block.statements.len() == location.statement_index {
self.visit_terminator(&basic_block.terminator, location)
} else {
let statement = &basic_block.statements[location.statement_index];
self.visit_statement(statement, location)
}
}
}make_mir_visitor!(Visitor,);
1275pub trait MutVisitor<'tcx> {
fn visit_body(&mut self, body: &mut Body<'tcx>) { self.super_body(body); }
fn visit_body_preserves_cfg(&mut self, body: &mut Body<'tcx>) {
self.super_body_preserves_cfg(body);
}
fn super_body_preserves_cfg(&mut self, body: &mut Body<'tcx>) {
let span = body.span;
if let Some(coroutine) = &mut body.coroutine {
if let Some(yield_ty) = &mut coroutine.yield_ty {
self.visit_ty(yield_ty,
TyContext::YieldTy(SourceInfo::outermost(span)));
}
if let Some(resume_ty) = &mut coroutine.resume_ty {
self.visit_ty(resume_ty,
TyContext::ResumeTy(SourceInfo::outermost(span)));
}
}
for var_debug_info in &mut body.var_debug_info {
self.visit_var_debug_info(var_debug_info);
}
for (bb, data) in
body.basic_blocks.as_mut_preserves_cfg().iter_enumerated_mut() {
self.visit_basic_block_data(bb, data);
}
for scope in &mut body.source_scopes {
self.visit_source_scope_data(scope);
}
self.visit_ty(&mut body.return_ty(),
TyContext::ReturnTy(SourceInfo::outermost(body.span)));
for local in body.local_decls.indices() {
self.visit_local_decl(local, &mut body.local_decls[local]);
}
macro_rules! type_annotations {
(mut) => (body.user_type_annotations.iter_enumerated_mut()); () =>
(body.user_type_annotations.iter_enumerated());
}
for (index, annotation) in
body.user_type_annotations.iter_enumerated_mut() {
self.visit_user_type_annotation(index, annotation);
}
self.visit_span(&mut body.span);
if let Some(required_consts) = &mut body.required_consts {
for const_ in required_consts {
let location = Location::START;
self.visit_const_operand(const_, location);
}
};
}
fn visit_basic_block_data(&mut self, block: BasicBlock,
data: &mut BasicBlockData<'tcx>) {
self.super_basic_block_data(block, data);
}
fn visit_source_scope_data(&mut self,
scope_data: &mut SourceScopeData<'tcx>) {
self.super_source_scope_data(scope_data);
}
fn visit_statement_debuginfo(&mut self,
stmt_debuginfo: &mut StmtDebugInfo<'tcx>, location: Location) {
self.super_statement_debuginfo(stmt_debuginfo, location);
}
fn visit_statement(&mut self, statement: &mut Statement<'tcx>,
location: Location) {
self.super_statement(statement, location);
}
fn visit_assign(&mut self, place: &mut Place<'tcx>,
rvalue: &mut Rvalue<'tcx>, location: Location) {
self.super_assign(place, rvalue, location);
}
fn visit_terminator(&mut self, terminator: &mut Terminator<'tcx>,
location: Location) {
self.super_terminator(terminator, location);
}
fn visit_assert_message(&mut self, msg: &mut AssertMessage<'tcx>,
location: Location) {
self.super_assert_message(msg, location);
}
fn visit_rvalue(&mut self, rvalue: &mut Rvalue<'tcx>,
location: Location) {
self.super_rvalue(rvalue, location);
}
fn visit_operand(&mut self, operand: &mut Operand<'tcx>,
location: Location) {
self.super_operand(operand, location);
}
fn visit_ascribe_user_ty(&mut self, place: &mut Place<'tcx>,
variance: &mut ty::Variance, user_ty: &mut UserTypeProjection,
location: Location) {
self.super_ascribe_user_ty(place, variance, user_ty, location);
}
fn visit_coverage(&mut self, kind: &mut coverage::CoverageKind,
location: Location) {
self.super_coverage(kind, location);
}
fn visit_place(&mut self, place: &mut Place<'tcx>, context: PlaceContext,
location: Location) {
self.super_place(place, context, location);
}
fn tcx<'a>(&'a self)
-> TyCtxt<'tcx>;
fn super_place(&mut self, place: &mut Place<'tcx>, context: PlaceContext,
location: Location) {
self.visit_local(&mut place.local, context, location);
if let Some(new_projection) =
self.process_projection(&place.projection, location) {
place.projection = self.tcx().mk_place_elems(&new_projection);
}
}
fn process_projection<'a>(&mut self, projection: &'a [PlaceElem<'tcx>],
location: Location) -> Option<Vec<PlaceElem<'tcx>>> {
let mut projection = Cow::Borrowed(projection);
for i in 0..projection.len() {
if let Some(&elem) = projection.get(i) {
if let Some(elem) =
self.process_projection_elem(elem, location) {
let vec = projection.to_mut();
vec[i] = elem;
}
}
}
match projection {
Cow::Borrowed(_) => None,
Cow::Owned(vec) => Some(vec),
}
}
fn process_projection_elem(&mut self, elem: PlaceElem<'tcx>,
location: Location) -> Option<PlaceElem<'tcx>> {
match elem {
PlaceElem::Index(local) => {
let mut new_local = local;
self.visit_local(&mut new_local,
PlaceContext::NonMutatingUse(NonMutatingUseContext::Copy),
location);
if new_local == local {
None
} else { Some(PlaceElem::Index(new_local)) }
}
PlaceElem::Field(field, ty) => {
let mut new_ty = ty;
self.visit_ty(&mut new_ty, TyContext::Location(location));
if ty != new_ty {
Some(PlaceElem::Field(field, new_ty))
} else { None }
}
PlaceElem::OpaqueCast(ty) => {
let mut new_ty = ty;
self.visit_ty(&mut new_ty, TyContext::Location(location));
if ty != new_ty {
Some(PlaceElem::OpaqueCast(new_ty))
} else { None }
}
PlaceElem::UnwrapUnsafeBinder(ty) => {
let mut new_ty = ty;
self.visit_ty(&mut new_ty, TyContext::Location(location));
if ty != new_ty {
Some(PlaceElem::UnwrapUnsafeBinder(new_ty))
} else { None }
}
PlaceElem::Deref | PlaceElem::PhantomDeref |
PlaceElem::ConstantIndex { .. } | PlaceElem::Subslice { .. } |
PlaceElem::Downcast(..) | PlaceElem::Wrap(_) => None,
}
}
fn visit_const_operand(&mut self, constant: &mut ConstOperand<'tcx>,
location: Location) {
self.super_const_operand(constant, location);
}
fn visit_ty_const(&mut self, ct: &mut ty::Const<'tcx>,
location: Location) {
self.super_ty_const(ct, location);
}
fn visit_span(&mut self, span: &mut Span) { self.super_span(span); }
fn visit_source_info(&mut self, source_info: &mut SourceInfo) {
self.super_source_info(source_info);
}
fn visit_ty(&mut self, ty: &mut Ty<'tcx>, _: TyContext) {
self.super_ty(ty);
}
fn visit_user_type_projection(&mut self, ty: &mut UserTypeProjection) {
self.super_user_type_projection(ty);
}
fn visit_user_type_annotation(&mut self, index: UserTypeAnnotationIndex,
ty: &mut CanonicalUserTypeAnnotation<'tcx>) {
self.super_user_type_annotation(index, ty);
}
fn visit_region(&mut self, region: &mut ty::Region<'tcx>, _: Location) {
self.super_region(region);
}
fn visit_args(&mut self, args: &mut GenericArgs<'tcx>, _: Location) {
self.super_args(args);
}
fn visit_local_decl(&mut self, local: Local,
local_decl: &mut LocalDecl<'tcx>) {
self.super_local_decl(local, local_decl);
}
fn visit_var_debug_info(&mut self,
var_debug_info: &mut VarDebugInfo<'tcx>) {
self.super_var_debug_info(var_debug_info);
}
fn visit_local(&mut self, local: &mut Local, context: PlaceContext,
location: Location) {
self.super_local(local, context, location)
}
fn visit_source_scope(&mut self, scope: &mut SourceScope) {
self.super_source_scope(scope);
}
fn super_body(&mut self, body: &mut Body<'tcx>) {
let span = body.span;
if let Some(coroutine) = &mut body.coroutine {
if let Some(yield_ty) = &mut coroutine.yield_ty {
self.visit_ty(yield_ty,
TyContext::YieldTy(SourceInfo::outermost(span)));
}
if let Some(resume_ty) = &mut coroutine.resume_ty {
self.visit_ty(resume_ty,
TyContext::ResumeTy(SourceInfo::outermost(span)));
}
}
for var_debug_info in &mut body.var_debug_info {
self.visit_var_debug_info(var_debug_info);
}
for (bb, data) in body.basic_blocks.as_mut().iter_enumerated_mut() {
self.visit_basic_block_data(bb, data);
}
for scope in &mut body.source_scopes {
self.visit_source_scope_data(scope);
}
self.visit_ty(&mut body.return_ty(),
TyContext::ReturnTy(SourceInfo::outermost(body.span)));
for local in body.local_decls.indices() {
self.visit_local_decl(local, &mut body.local_decls[local]);
}
macro_rules! type_annotations {
(mut) => (body.user_type_annotations.iter_enumerated_mut()); () =>
(body.user_type_annotations.iter_enumerated());
}
for (index, annotation) in
body.user_type_annotations.iter_enumerated_mut() {
self.visit_user_type_annotation(index, annotation);
}
self.visit_span(&mut body.span);
if let Some(required_consts) = &mut body.required_consts {
for const_ in required_consts {
let location = Location::START;
self.visit_const_operand(const_, location);
}
};
}
fn super_basic_block_data(&mut self, block: BasicBlock,
data: &mut BasicBlockData<'tcx>) {
let BasicBlockData {
statements,
after_last_stmt_debuginfos,
terminator,
is_cleanup: _ } = data;
let mut index = 0;
for statement in statements {
let location = Location { block, statement_index: index };
self.visit_statement(statement, location);
index += 1;
}
let location = Location { block, statement_index: index };
for debuginfo in after_last_stmt_debuginfos as &mut [_] {
self.visit_statement_debuginfo(debuginfo, location);
}
self.visit_terminator(terminator, location);
}
fn super_source_scope_data(&mut self,
scope_data: &mut SourceScopeData<'tcx>) {
let SourceScopeData {
span,
parent_scope,
inlined,
inlined_parent_scope,
local_data: _ } = scope_data;
self.visit_span(&mut *span);
if let Some(parent_scope) = parent_scope {
self.visit_source_scope(&mut *parent_scope);
}
if let Some((callee, callsite_span)) = inlined {
let location = Location::START;
self.visit_span(&mut *callsite_span);
let ty::Instance { def: callee_def, args: callee_args } = callee;
match callee_def {
ty::InstanceKind::Item(_def_id) => {}
ty::InstanceKind::Intrinsic(_def_id) |
ty::InstanceKind::LlvmIntrinsic(_def_id) |
ty::InstanceKind::Shim(ty::ShimKind::VTable(_def_id)) |
ty::InstanceKind::Shim(ty::ShimKind::Reify(_def_id, _)) |
ty::InstanceKind::Virtual(_def_id, _) |
ty::InstanceKind::Shim(ty::ShimKind::ThreadLocal(_def_id)) |
ty::InstanceKind::Shim(ty::ShimKind::ClosureOnce {
call_once: _def_id, closure: _, track_caller: _ }) |
ty::InstanceKind::Shim(ty::ShimKind::ConstructCoroutineInClosure {
coroutine_closure_def_id: _def_id, receiver_by_ref: _ }) |
ty::InstanceKind::Shim(ty::ShimKind::DropGlue(_def_id,
None)) => {}
ty::InstanceKind::Shim(ty::ShimKind::FnPtr(_def_id, ty)) |
ty::InstanceKind::Shim(ty::ShimKind::DropGlue(_def_id,
Some(ty))) |
ty::InstanceKind::Shim(ty::ShimKind::Clone(_def_id, ty)) |
ty::InstanceKind::Shim(ty::ShimKind::FnAddrAsPtr(_def_id,
ty)) |
ty::InstanceKind::Shim(ty::ShimKind::FnPtrFromPtr(_def_id,
ty)) |
ty::InstanceKind::Shim(ty::ShimKind::AsyncDropGlue(_def_id,
ty)) |
ty::InstanceKind::Shim(ty::ShimKind::AsyncDropGlueCtor(_def_id,
ty)) => {
self.visit_ty(&mut *ty, TyContext::Location(location));
}
ty::InstanceKind::Shim(ty::ShimKind::FutureDropPoll(_def_id,
proxy_ty, impl_ty)) => {
self.visit_ty(&mut *proxy_ty,
TyContext::Location(location));
self.visit_ty(&mut *impl_ty, TyContext::Location(location));
}
}
self.visit_args(callee_args, location);
}
if let Some(inlined_parent_scope) = inlined_parent_scope {
self.visit_source_scope(&mut *inlined_parent_scope);
}
}
fn super_statement_debuginfo(&mut self,
stmt_debuginfo: &mut StmtDebugInfo<'tcx>, location: Location) {
match stmt_debuginfo {
StmtDebugInfo::AssignRef(local, place) => {
self.visit_local(&mut *local,
PlaceContext::NonUse(NonUseContext::VarDebugInfo),
location);
self.visit_place(place,
PlaceContext::NonUse(NonUseContext::VarDebugInfo),
location);
}
StmtDebugInfo::InvalidAssign(local) => {
self.visit_local(&mut *local,
PlaceContext::NonUse(NonUseContext::VarDebugInfo),
location);
}
}
}
fn super_statement(&mut self, statement: &mut Statement<'tcx>,
location: Location) {
let Statement { source_info, kind, debuginfos } = statement;
self.visit_source_info(source_info);
for debuginfo in debuginfos as &mut [_] {
self.visit_statement_debuginfo(debuginfo, location);
}
match kind {
StatementKind::Assign((place, rvalue)) => {
self.visit_assign(place, rvalue, location);
}
StatementKind::FakeRead((_, place)) => {
self.visit_place(place,
PlaceContext::NonMutatingUse(NonMutatingUseContext::Inspect),
location);
}
StatementKind::SetDiscriminant { place, .. } => {
self.visit_place(place,
PlaceContext::MutatingUse(MutatingUseContext::SetDiscriminant),
location);
}
StatementKind::StorageLive(local) => {
self.visit_local(&mut *local,
PlaceContext::NonUse(NonUseContext::StorageLive), location);
}
StatementKind::StorageDead(local) => {
self.visit_local(&mut *local,
PlaceContext::NonUse(NonUseContext::StorageDead), location);
}
StatementKind::PlaceMention(place) => {
self.visit_place(place,
PlaceContext::NonMutatingUse(NonMutatingUseContext::PlaceMention),
location);
}
StatementKind::AscribeUserType((place, user_ty), variance) => {
self.visit_ascribe_user_ty(place, &mut *variance, user_ty,
location);
}
StatementKind::Coverage(coverage) => {
self.visit_coverage(coverage, location)
}
StatementKind::Intrinsic(intrinsic) => {
match intrinsic {
NonDivergingIntrinsic::Assume(op) =>
self.visit_operand(op, location),
NonDivergingIntrinsic::CopyNonOverlapping(CopyNonOverlapping {
src, dst, count }) => {
self.visit_operand(src, location);
self.visit_operand(dst, location);
self.visit_operand(count, location);
}
}
}
StatementKind::BackwardIncompatibleDropHint { place, .. } => {
self.visit_place(place,
PlaceContext::NonUse(NonUseContext::BackwardIncompatibleDropHint),
location);
}
StatementKind::ConstEvalCounter => {}
StatementKind::Nop => {}
}
}
fn super_assign(&mut self, place: &mut Place<'tcx>,
rvalue: &mut Rvalue<'tcx>, location: Location) {
self.visit_place(place,
PlaceContext::MutatingUse(MutatingUseContext::Store), location);
self.visit_rvalue(rvalue, location);
}
fn super_terminator(&mut self, terminator: &mut Terminator<'tcx>,
location: Location) {
let Terminator { source_info, kind } = terminator;
self.visit_source_info(source_info);
match kind {
TerminatorKind::Goto { .. } | TerminatorKind::UnwindResume |
TerminatorKind::UnwindTerminate(_) |
TerminatorKind::CoroutineDrop | TerminatorKind::Unreachable |
TerminatorKind::FalseEdge { .. } |
TerminatorKind::FalseUnwind { .. } => {}
TerminatorKind::Return => {
let mut local = RETURN_PLACE;
self.visit_local(&mut local,
PlaceContext::NonMutatingUse(NonMutatingUseContext::Move),
location);
{
match (&local, &RETURN_PLACE) {
(left_val, right_val) => {
if !(*left_val == *right_val) {
let kind = ::core::panicking::AssertKind::Eq;
::core::panicking::assert_failed(kind, &*left_val,
&*right_val,
::core::option::Option::Some(format_args!("`MutVisitor` tried to mutate return place of `return` terminator")));
}
}
}
};
}
TerminatorKind::SwitchInt { discr, targets: _ } => {
self.visit_operand(discr, location);
}
TerminatorKind::Drop {
place, target: _, unwind: _, replace: _, drop: _ } => {
self.visit_place(place,
PlaceContext::MutatingUse(MutatingUseContext::Drop),
location);
}
TerminatorKind::Call {
func,
args,
destination,
target: _,
unwind: _,
call_source: _,
fn_span } => {
self.visit_span(&mut *fn_span);
self.visit_operand(func, location);
for arg in args {
self.visit_operand(&mut arg.node, location);
}
self.visit_place(destination,
PlaceContext::MutatingUse(MutatingUseContext::Call),
location);
}
TerminatorKind::TailCall { func, args, fn_span } => {
self.visit_span(&mut *fn_span);
self.visit_operand(func, location);
for arg in args {
self.visit_operand(&mut arg.node, location);
}
}
TerminatorKind::Assert {
cond, expected: _, msg, target: _, unwind: _ } => {
self.visit_operand(cond, location);
self.visit_assert_message(msg, location);
}
TerminatorKind::Yield { value, resume: _, resume_arg, drop: _ } =>
{
self.visit_operand(value, location);
self.visit_place(resume_arg,
PlaceContext::MutatingUse(MutatingUseContext::Yield),
location);
}
TerminatorKind::InlineAsm {
asm_macro: _,
template: _,
operands,
options: _,
line_spans: _,
targets: _,
unwind: _ } => {
for op in operands {
match op {
InlineAsmOperand::In { value, .. } => {
self.visit_operand(value, location);
}
InlineAsmOperand::Out { place: Some(place), .. } => {
self.visit_place(place,
PlaceContext::MutatingUse(MutatingUseContext::AsmOutput),
location);
}
InlineAsmOperand::InOut { in_value, out_place, .. } => {
self.visit_operand(in_value, location);
if let Some(out_place) = out_place {
self.visit_place(out_place,
PlaceContext::MutatingUse(MutatingUseContext::AsmOutput),
location);
}
}
InlineAsmOperand::Const { value } |
InlineAsmOperand::SymFn { value } => {
self.visit_const_operand(value, location);
}
InlineAsmOperand::Out { place: None, .. } |
InlineAsmOperand::SymStatic { def_id: _ } |
InlineAsmOperand::Label { target_index: _ } => {}
}
}
}
}
}
fn super_assert_message(&mut self, msg: &mut AssertMessage<'tcx>,
location: Location) {
use crate::mir::AssertKind::*;
match msg {
BoundsCheck { len, index } => {
self.visit_operand(len, location);
self.visit_operand(index, location);
}
Overflow(_, l, r) => {
self.visit_operand(l, location);
self.visit_operand(r, location);
}
OverflowNeg(op) | DivisionByZero(op) | RemainderByZero(op) |
InvalidEnumConstruction(op) => {
self.visit_operand(op, location);
}
ResumedAfterReturn(_) | ResumedAfterPanic(_) |
NullPointerDereference | NullReferenceConstructed |
ResumedAfterDrop(_) => {}
MisalignedPointerDereference { required, found } => {
self.visit_operand(required, location);
self.visit_operand(found, location);
}
}
}
fn super_rvalue(&mut self, rvalue: &mut Rvalue<'tcx>,
location: Location) {
match rvalue {
Rvalue::Use(operand, _with_retag) => {
self.visit_operand(operand, location);
}
Rvalue::Repeat(value, ct) => {
self.visit_operand(value, location);
self.visit_ty_const(&mut *ct, location);
}
Rvalue::ThreadLocalRef(_) => {}
Rvalue::Ref(r, bk, path) => {
self.visit_region(&mut *r, location);
let ctx =
match bk {
BorrowKind::Shared =>
PlaceContext::NonMutatingUse(NonMutatingUseContext::SharedBorrow),
BorrowKind::Fake(_) =>
PlaceContext::NonMutatingUse(NonMutatingUseContext::FakeBorrow),
BorrowKind::Mut { .. } =>
PlaceContext::MutatingUse(MutatingUseContext::Borrow),
};
self.visit_place(path, ctx, location);
}
Rvalue::Reborrow(target, mutability, place) => {
self.visit_ty(&mut *target, TyContext::Location(location));
self.visit_place(place,
match mutability {
Mutability::Not =>
PlaceContext::NonMutatingUse(NonMutatingUseContext::SharedBorrow),
Mutability::Mut =>
PlaceContext::MutatingUse(MutatingUseContext::Borrow),
}, location);
}
Rvalue::CopyForDeref(place) => {
self.visit_place(place,
PlaceContext::NonMutatingUse(NonMutatingUseContext::Inspect),
location);
}
Rvalue::RawPtr(m, path) => {
let ctx =
match m {
RawPtrKind::Mut =>
PlaceContext::MutatingUse(MutatingUseContext::RawBorrow),
RawPtrKind::Const =>
PlaceContext::NonMutatingUse(NonMutatingUseContext::RawBorrow),
RawPtrKind::FakeForPtrMetadata =>
PlaceContext::NonMutatingUse(NonMutatingUseContext::Inspect),
};
self.visit_place(path, ctx, location);
}
Rvalue::Cast(_cast_kind, operand, ty) => {
self.visit_operand(operand, location);
self.visit_ty(&mut *ty, TyContext::Location(location));
}
Rvalue::BinaryOp(_bin_op, (lhs, rhs)) => {
self.visit_operand(lhs, location);
self.visit_operand(rhs, location);
}
Rvalue::UnaryOp(_un_op, op) => {
self.visit_operand(op, location);
}
Rvalue::Discriminant(place) => {
self.visit_place(place,
PlaceContext::NonMutatingUse(NonMutatingUseContext::Inspect),
location);
}
Rvalue::Aggregate(kind, operands) => {
let kind = &mut **kind;
match kind {
AggregateKind::Array(ty) => {
self.visit_ty(&mut *ty, TyContext::Location(location));
}
AggregateKind::Tuple => {}
AggregateKind::Adt(_adt_def, _variant_index, args,
_user_args, _active_field_index) => {
self.visit_args(args, location);
}
AggregateKind::Closure(_, closure_args) => {
self.visit_args(closure_args, location);
}
AggregateKind::Coroutine(_, coroutine_args) => {
self.visit_args(coroutine_args, location);
}
AggregateKind::CoroutineClosure(_, coroutine_closure_args)
=> {
self.visit_args(coroutine_closure_args, location);
}
AggregateKind::RawPtr(ty, _) => {
self.visit_ty(&mut *ty, TyContext::Location(location));
}
}
for operand in operands {
self.visit_operand(operand, location);
}
}
Rvalue::WrapUnsafeBinder(op, ty) => {
self.visit_operand(op, location);
self.visit_ty(&mut *ty, TyContext::Location(location));
}
}
}
fn super_operand(&mut self, operand: &mut Operand<'tcx>,
location: Location) {
match operand {
Operand::Copy(place) => {
self.visit_place(place,
PlaceContext::NonMutatingUse(NonMutatingUseContext::Copy),
location);
}
Operand::Move(place) => {
self.visit_place(place,
PlaceContext::NonMutatingUse(NonMutatingUseContext::Move),
location);
}
Operand::Constant(constant) => {
self.visit_const_operand(constant, location);
}
Operand::RuntimeChecks(_) => {}
}
}
fn super_ascribe_user_ty(&mut self, place: &mut Place<'tcx>,
variance: &mut ty::Variance, user_ty: &mut UserTypeProjection,
location: Location) {
self.visit_place(place,
PlaceContext::NonUse(NonUseContext::AscribeUserTy(*&mut *variance)),
location);
self.visit_user_type_projection(user_ty);
}
fn super_coverage(&mut self, _kind: &mut coverage::CoverageKind,
_location: Location) {}
fn super_local_decl(&mut self, local: Local,
local_decl: &mut LocalDecl<'tcx>) {
let LocalDecl { mutability: _, ty, user_ty, source_info, local_info: _
} = local_decl;
self.visit_source_info(source_info);
self.visit_ty(&mut *ty,
TyContext::LocalDecl { local, source_info: *source_info });
if let Some(user_ty) = user_ty {
for user_ty in &mut user_ty.contents {
self.visit_user_type_projection(user_ty);
}
}
}
fn super_local(&mut self, _local: &mut Local, _context: PlaceContext,
_location: Location) {}
fn super_var_debug_info(&mut self,
var_debug_info: &mut VarDebugInfo<'tcx>) {
let VarDebugInfo {
name: _, source_info, composite, value, argument_index: _ } =
var_debug_info;
self.visit_source_info(source_info);
let location = Location::START;
if let Some(VarDebugInfoFragment { ty, projection }) = composite {
self.visit_ty(&mut *ty, TyContext::Location(location));
for elem in projection {
let ProjectionElem::Field(_, ty) =
elem else {
::rustc_span::macros::bug_impl(None,
format_args!("impossible case reached"), Location::caller())
};
self.visit_ty(&mut *ty, TyContext::Location(location));
}
}
match value {
VarDebugInfoContents::Const(c) =>
self.visit_const_operand(c, location),
VarDebugInfoContents::Place(place) =>
self.visit_place(place,
PlaceContext::NonUse(NonUseContext::VarDebugInfo),
location),
}
}
fn super_source_scope(&mut self, _scope: &mut SourceScope) {}
fn super_const_operand(&mut self, constant: &mut ConstOperand<'tcx>,
location: Location) {
let ConstOperand { span, user_ty: _, const_ } = constant;
self.visit_span(&mut *span);
match const_ {
Const::Ty(_, ct) => self.visit_ty_const(&mut *ct, location),
Const::Val(_, ty) | Const::Unevaluated(_, ty) => {
self.visit_ty(&mut *ty, TyContext::Location(location));
}
}
}
fn super_ty_const(&mut self, _ct: &mut ty::Const<'tcx>,
_location: Location) {}
fn super_span(&mut self, _span: &mut Span) {}
fn super_source_info(&mut self, source_info: &mut SourceInfo) {
let SourceInfo { span, scope } = source_info;
self.visit_span(&mut *span);
self.visit_source_scope(&mut *scope);
}
fn super_user_type_projection(&mut self, _ty: &mut UserTypeProjection) {}
fn super_user_type_annotation(&mut self, _index: UserTypeAnnotationIndex,
ty: &mut CanonicalUserTypeAnnotation<'tcx>) {
self.visit_span(&mut ty.span);
self.visit_ty(&mut ty.inferred_ty, TyContext::UserTy(ty.span));
}
fn super_ty(&mut self, _ty: &mut Ty<'tcx>) {}
fn super_region(&mut self, _region: &mut ty::Region<'tcx>) {}
fn super_args(&mut self, _args: &mut GenericArgs<'tcx>) {}
fn visit_location(&mut self, body: &mut Body<'tcx>, location: Location) {
let basic_block = &mut body.basic_blocks.as_mut()[location.block];
if basic_block.statements.len() == location.statement_index {
self.visit_terminator(&mut basic_block.terminator, location)
} else {
let statement =
&mut basic_block.statements[location.statement_index];
self.visit_statement(statement, location)
}
}
}make_mir_visitor!(MutVisitor, mut);
1276
1277#[derive(#[automatically_derived]impl ::core::marker::Copy for TyContext { }Copy, #[automatically_derived]#[doc(hidden)]unsafe impl ::core::clone::TrivialClone
for TyContext {
}
#[automatically_derived]impl ::core::clone::Clone for TyContext {
#[inline]
#[rustc_trivial_field_reads]
fn clone(&self) -> Self {
let _: ::core::clone::AssertParamIsClone<Local>;
let _: ::core::clone::AssertParamIsClone<SourceInfo>;
let _: ::core::clone::AssertParamIsClone<Span>;
let _: ::core::clone::AssertParamIsClone<Location>;
*self
}
}Clone, #[automatically_derived]impl ::core::fmt::Debug for TyContext {
#[inline]
#[rustc_trivial_field_reads]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match self {
Self::LocalDecl { local: __self_0, source_info: __self_1 } =>
::core::fmt::Formatter::debug_struct_field2_finish(f,
"LocalDecl local source_info", __self_0, &__self_1),
Self::UserTy(__self_0) =>
::core::fmt::Formatter::debug_struct_field1_finish(f,
"UserTy", &__self_0),
Self::ReturnTy(__self_0) =>
::core::fmt::Formatter::debug_struct_field1_finish(f,
"ReturnTy", &__self_0),
Self::YieldTy(__self_0) =>
::core::fmt::Formatter::debug_struct_field1_finish(f,
"YieldTy", &__self_0),
Self::ResumeTy(__self_0) =>
::core::fmt::Formatter::debug_struct_field1_finish(f,
"ResumeTy", &__self_0),
Self::Location(__self_0) =>
::core::fmt::Formatter::debug_struct_field1_finish(f,
"Location", &__self_0),
}
}
}Debug, #[automatically_derived]impl ::core::hash::Hash for TyContext {
#[inline]
fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) {
::core::hash::Hash::hash(&::core::intrinsics::discriminant_value(self),
state);
match self {
Self::LocalDecl { local: __self_0, source_info: __self_1 } => {
::core::hash::Hash::hash(__self_0, state);
::core::hash::Hash::hash(__self_1, state)
}
Self::UserTy(__self_0) =>
::core::hash::Hash::hash(__self_0, state),
Self::ReturnTy(__self_0) =>
::core::hash::Hash::hash(__self_0, state),
Self::YieldTy(__self_0) =>
::core::hash::Hash::hash(__self_0, state),
Self::ResumeTy(__self_0) =>
::core::hash::Hash::hash(__self_0, state),
Self::Location(__self_0) =>
::core::hash::Hash::hash(__self_0, state),
}
}
}Hash, #[automatically_derived]impl ::core::cmp::Eq for TyContext {
#[inline]
#[doc(hidden)]
#[coverage(off)]
fn assert_fields_are_eq(&self) {
let _: ::core::cmp::AssertParamIsEq<Local>;
let _: ::core::cmp::AssertParamIsEq<SourceInfo>;
let _: ::core::cmp::AssertParamIsEq<Span>;
let _: ::core::cmp::AssertParamIsEq<Location>;
}
}Eq, #[automatically_derived]impl ::core::marker::StructuralPartialEq for TyContext
{
}
#[automatically_derived]impl ::core::cmp::PartialEq for TyContext {
#[inline]
fn eq(&self, other: &Self) -> bool {
::core::intrinsics::discriminant_value(self) ==
::core::intrinsics::discriminant_value(other) &&
match (self, other) {
(Self::LocalDecl { local: __self_0, source_info: __self_1 },
Self::LocalDecl { local: __arg1_0, source_info: __arg1_1 })
=> __self_0 == __arg1_0 && __self_1 == __arg1_1,
(Self::UserTy(__self_0), Self::UserTy(__arg1_0)) =>
__self_0 == __arg1_0,
(Self::ReturnTy(__self_0), Self::ReturnTy(__arg1_0)) =>
__self_0 == __arg1_0,
(Self::YieldTy(__self_0), Self::YieldTy(__arg1_0)) =>
__self_0 == __arg1_0,
(Self::ResumeTy(__self_0), Self::ResumeTy(__arg1_0)) =>
__self_0 == __arg1_0,
(Self::Location(__self_0), Self::Location(__arg1_0)) =>
__self_0 == __arg1_0,
_ => unsafe { ::core::intrinsics::unreachable() }
}
}
}PartialEq)]
1280pub enum TyContext {
1281 LocalDecl {
1282 local: Local,
1284
1285 source_info: SourceInfo,
1287 },
1288
1289 UserTy(Span),
1291
1292 ReturnTy(SourceInfo),
1294
1295 YieldTy(SourceInfo),
1296
1297 ResumeTy(SourceInfo),
1298
1299 Location(Location),
1301}
1302
1303#[derive(#[automatically_derived]impl ::core::marker::Copy for NonMutatingUseContext {
}Copy, #[automatically_derived]#[doc(hidden)]unsafe impl ::core::clone::TrivialClone
for NonMutatingUseContext {
}
#[automatically_derived]impl ::core::clone::Clone for NonMutatingUseContext {
#[inline]
#[rustc_trivial_field_reads]
fn clone(&self) -> Self { *self }
}Clone, #[automatically_derived]impl ::core::fmt::Debug for NonMutatingUseContext {
#[inline]
#[rustc_trivial_field_reads]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::debug_c_like_enum_write_str(f,
"Inspect Copy Move SharedBorrow FakeBorrow RawBorrow PlaceMention Projection",
match self {
NonMutatingUseContext::Inspect => 0usize,
NonMutatingUseContext::Copy => 8usize,
NonMutatingUseContext::Move => 13usize,
NonMutatingUseContext::SharedBorrow => 18usize,
NonMutatingUseContext::FakeBorrow => 31usize,
NonMutatingUseContext::RawBorrow => 42usize,
NonMutatingUseContext::PlaceMention => 52usize,
NonMutatingUseContext::Projection => 65usize,
})
}
}Debug, #[automatically_derived]impl ::core::marker::StructuralPartialEq for
NonMutatingUseContext {
}
#[automatically_derived]impl ::core::cmp::PartialEq for NonMutatingUseContext
{
#[inline]
fn eq(&self, other: &Self) -> bool {
::core::intrinsics::discriminant_value(self) ==
::core::intrinsics::discriminant_value(other)
}
}PartialEq, #[automatically_derived]impl ::core::cmp::Eq for NonMutatingUseContext { }Eq)]
1304pub enum NonMutatingUseContext {
1305 Inspect,
1307 Copy,
1309 Move,
1311 SharedBorrow,
1313 FakeBorrow,
1317 RawBorrow,
1319 PlaceMention,
1324 Projection,
1331}
1332
1333#[derive(#[automatically_derived]impl ::core::marker::Copy for MutatingUseContext { }Copy, #[automatically_derived]#[doc(hidden)]unsafe impl ::core::clone::TrivialClone
for MutatingUseContext {
}
#[automatically_derived]impl ::core::clone::Clone for MutatingUseContext {
#[inline]
#[rustc_trivial_field_reads]
fn clone(&self) -> Self { *self }
}Clone, #[automatically_derived]impl ::core::fmt::Debug for MutatingUseContext {
#[inline]
#[rustc_trivial_field_reads]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::debug_c_like_enum_write_str(f,
"Store SetDiscriminant AsmOutput Call Yield Drop Borrow RawBorrow Projection",
match self {
MutatingUseContext::Store => 0usize,
MutatingUseContext::SetDiscriminant => 6usize,
MutatingUseContext::AsmOutput => 22usize,
MutatingUseContext::Call => 32usize,
MutatingUseContext::Yield => 37usize,
MutatingUseContext::Drop => 43usize,
MutatingUseContext::Borrow => 48usize,
MutatingUseContext::RawBorrow => 55usize,
MutatingUseContext::Projection => 65usize,
})
}
}Debug, #[automatically_derived]impl ::core::marker::StructuralPartialEq for
MutatingUseContext {
}
#[automatically_derived]impl ::core::cmp::PartialEq for MutatingUseContext {
#[inline]
fn eq(&self, other: &Self) -> bool {
::core::intrinsics::discriminant_value(self) ==
::core::intrinsics::discriminant_value(other)
}
}PartialEq, #[automatically_derived]impl ::core::cmp::Eq for MutatingUseContext { }Eq)]
1334pub enum MutatingUseContext {
1335 Store,
1337 SetDiscriminant,
1339 AsmOutput,
1341 Call,
1343 Yield,
1345 Drop,
1347 Borrow,
1349 RawBorrow,
1351 Projection,
1358}
1359
1360#[derive(#[automatically_derived]impl ::core::marker::Copy for NonUseContext { }Copy, #[automatically_derived]#[doc(hidden)]unsafe impl ::core::clone::TrivialClone
for NonUseContext {
}
#[automatically_derived]impl ::core::clone::Clone for NonUseContext {
#[inline]
#[rustc_trivial_field_reads]
fn clone(&self) -> Self {
let _: ::core::clone::AssertParamIsClone<ty::Variance>;
*self
}
}Clone, #[automatically_derived]impl ::core::fmt::Debug for NonUseContext {
#[inline]
#[rustc_trivial_field_reads]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match self {
Self::StorageLive =>
::core::fmt::Formatter::write_str(f, "StorageLive"),
Self::StorageDead =>
::core::fmt::Formatter::write_str(f, "StorageDead"),
Self::AscribeUserTy(__self_0) =>
::core::fmt::Formatter::debug_struct_field1_finish(f,
"AscribeUserTy", &__self_0),
Self::VarDebugInfo =>
::core::fmt::Formatter::write_str(f, "VarDebugInfo"),
Self::BackwardIncompatibleDropHint =>
::core::fmt::Formatter::write_str(f,
"BackwardIncompatibleDropHint"),
}
}
}Debug, #[automatically_derived]impl ::core::marker::StructuralPartialEq for
NonUseContext {
}
#[automatically_derived]impl ::core::cmp::PartialEq for NonUseContext {
#[inline]
fn eq(&self, other: &Self) -> bool {
::core::intrinsics::discriminant_value(self) ==
::core::intrinsics::discriminant_value(other) &&
match (self, other) {
(Self::AscribeUserTy(__self_0), Self::AscribeUserTy(__arg1_0))
=> __self_0 == __arg1_0,
_ => true,
}
}
}PartialEq, #[automatically_derived]impl ::core::cmp::Eq for NonUseContext {
#[inline]
#[doc(hidden)]
#[coverage(off)]
fn assert_fields_are_eq(&self) {
let _: ::core::cmp::AssertParamIsEq<ty::Variance>;
}
}Eq)]
1361pub enum NonUseContext {
1362 StorageLive,
1364 StorageDead,
1366 AscribeUserTy(ty::Variance),
1368 VarDebugInfo,
1370 BackwardIncompatibleDropHint,
1372}
1373
1374#[derive(#[automatically_derived]impl ::core::marker::Copy for PlaceContext { }Copy, #[automatically_derived]#[doc(hidden)]unsafe impl ::core::clone::TrivialClone
for PlaceContext {
}
#[automatically_derived]impl ::core::clone::Clone for PlaceContext {
#[inline]
#[rustc_trivial_field_reads]
fn clone(&self) -> Self {
let _: ::core::clone::AssertParamIsClone<NonMutatingUseContext>;
let _: ::core::clone::AssertParamIsClone<MutatingUseContext>;
let _: ::core::clone::AssertParamIsClone<NonUseContext>;
*self
}
}Clone, #[automatically_derived]impl ::core::fmt::Debug for PlaceContext {
#[inline]
#[rustc_trivial_field_reads]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match self {
Self::NonMutatingUse(__self_0) =>
::core::fmt::Formatter::debug_struct_field1_finish(f,
"NonMutatingUse", &__self_0),
Self::MutatingUse(__self_0) =>
::core::fmt::Formatter::debug_struct_field1_finish(f,
"MutatingUse", &__self_0),
Self::NonUse(__self_0) =>
::core::fmt::Formatter::debug_struct_field1_finish(f,
"NonUse", &__self_0),
}
}
}Debug, #[automatically_derived]impl ::core::marker::StructuralPartialEq for
PlaceContext {
}
#[automatically_derived]impl ::core::cmp::PartialEq for PlaceContext {
#[inline]
fn eq(&self, other: &Self) -> bool {
::core::intrinsics::discriminant_value(self) ==
::core::intrinsics::discriminant_value(other) &&
match (self, other) {
(Self::NonMutatingUse(__self_0),
Self::NonMutatingUse(__arg1_0)) => __self_0 == __arg1_0,
(Self::MutatingUse(__self_0), Self::MutatingUse(__arg1_0)) =>
__self_0 == __arg1_0,
(Self::NonUse(__self_0), Self::NonUse(__arg1_0)) =>
__self_0 == __arg1_0,
_ => unsafe { ::core::intrinsics::unreachable() }
}
}
}PartialEq, #[automatically_derived]impl ::core::cmp::Eq for PlaceContext {
#[inline]
#[doc(hidden)]
#[coverage(off)]
fn assert_fields_are_eq(&self) {
let _: ::core::cmp::AssertParamIsEq<NonMutatingUseContext>;
let _: ::core::cmp::AssertParamIsEq<MutatingUseContext>;
let _: ::core::cmp::AssertParamIsEq<NonUseContext>;
}
}Eq)]
1375pub enum PlaceContext {
1376 NonMutatingUse(NonMutatingUseContext),
1377 MutatingUse(MutatingUseContext),
1378 NonUse(NonUseContext),
1379}
1380
1381impl PlaceContext {
1382 #[inline]
1384 pub fn is_drop(self) -> bool {
1385 #[allow(non_exhaustive_omitted_patterns)] match self {
PlaceContext::MutatingUse(MutatingUseContext::Drop) => true,
_ => false,
}matches!(self, PlaceContext::MutatingUse(MutatingUseContext::Drop))
1386 }
1387
1388 pub fn is_borrow(self) -> bool {
1391 #[allow(non_exhaustive_omitted_patterns)] match self {
PlaceContext::NonMutatingUse(NonMutatingUseContext::SharedBorrow) |
PlaceContext::MutatingUse(MutatingUseContext::Borrow) => true,
_ => false,
}matches!(
1392 self,
1393 PlaceContext::NonMutatingUse(NonMutatingUseContext::SharedBorrow)
1394 | PlaceContext::MutatingUse(MutatingUseContext::Borrow)
1395 )
1396 }
1397
1398 pub fn is_address_of(self) -> bool {
1400 #[allow(non_exhaustive_omitted_patterns)] match self {
PlaceContext::NonMutatingUse(NonMutatingUseContext::RawBorrow) |
PlaceContext::MutatingUse(MutatingUseContext::RawBorrow) => true,
_ => false,
}matches!(
1401 self,
1402 PlaceContext::NonMutatingUse(NonMutatingUseContext::RawBorrow)
1403 | PlaceContext::MutatingUse(MutatingUseContext::RawBorrow)
1404 )
1405 }
1406
1407 #[inline]
1409 pub fn may_observe_address(self) -> bool {
1410 #[allow(non_exhaustive_omitted_patterns)] match self {
PlaceContext::NonMutatingUse(NonMutatingUseContext::SharedBorrow |
NonMutatingUseContext::RawBorrow | NonMutatingUseContext::FakeBorrow)
|
PlaceContext::MutatingUse(MutatingUseContext::Drop |
MutatingUseContext::Borrow | MutatingUseContext::RawBorrow |
MutatingUseContext::AsmOutput) => true,
_ => false,
}matches!(
1411 self,
1412 PlaceContext::NonMutatingUse(
1413 NonMutatingUseContext::SharedBorrow
1414 | NonMutatingUseContext::RawBorrow
1415 | NonMutatingUseContext::FakeBorrow
1416 ) | PlaceContext::MutatingUse(
1417 MutatingUseContext::Drop
1418 | MutatingUseContext::Borrow
1419 | MutatingUseContext::RawBorrow
1420 | MutatingUseContext::AsmOutput
1421 )
1422 )
1423 }
1424
1425 #[inline]
1427 pub fn is_storage_marker(self) -> bool {
1428 #[allow(non_exhaustive_omitted_patterns)] match self {
PlaceContext::NonUse(NonUseContext::StorageLive |
NonUseContext::StorageDead) => true,
_ => false,
}matches!(
1429 self,
1430 PlaceContext::NonUse(NonUseContext::StorageLive | NonUseContext::StorageDead)
1431 )
1432 }
1433
1434 #[inline]
1436 pub fn is_mutating_use(self) -> bool {
1437 #[allow(non_exhaustive_omitted_patterns)] match self {
PlaceContext::MutatingUse(..) => true,
_ => false,
}matches!(self, PlaceContext::MutatingUse(..))
1438 }
1439
1440 #[inline]
1442 pub fn is_use(self) -> bool {
1443 !#[allow(non_exhaustive_omitted_patterns)] match self {
PlaceContext::NonUse(..) => true,
_ => false,
}matches!(self, PlaceContext::NonUse(..))
1444 }
1445
1446 pub fn is_place_assignment(self) -> bool {
1448 #[allow(non_exhaustive_omitted_patterns)] match self {
PlaceContext::MutatingUse(MutatingUseContext::Store |
MutatingUseContext::Call | MutatingUseContext::AsmOutput) => true,
_ => false,
}matches!(
1449 self,
1450 PlaceContext::MutatingUse(
1451 MutatingUseContext::Store
1452 | MutatingUseContext::Call
1453 | MutatingUseContext::AsmOutput,
1454 )
1455 )
1456 }
1457
1458 pub fn ambient_variance(self) -> ty::Variance {
1460 use NonMutatingUseContext::*;
1461 use NonUseContext::*;
1462 match self {
1463 PlaceContext::MutatingUse(_) => ty::Invariant,
1464 PlaceContext::NonUse(
1465 StorageDead | StorageLive | VarDebugInfo | BackwardIncompatibleDropHint,
1466 ) => ty::Invariant,
1467 PlaceContext::NonMutatingUse(
1468 Inspect | Copy | Move | PlaceMention | SharedBorrow | FakeBorrow | RawBorrow
1469 | Projection,
1470 ) => ty::Covariant,
1471 PlaceContext::NonUse(AscribeUserTy(variance)) => variance,
1472 }
1473 }
1474}
1475
1476pub struct VisitPlacesWith<F>(pub F);
1478
1479impl<'tcx, F> Visitor<'tcx> for VisitPlacesWith<F>
1480where
1481 F: FnMut(Place<'tcx>, PlaceContext),
1482{
1483 fn visit_local(&mut self, local: Local, ctxt: PlaceContext, _: Location) {
1484 (self.0)(local.into(), ctxt);
1485 }
1486
1487 fn visit_place(&mut self, place: &Place<'tcx>, ctxt: PlaceContext, location: Location) {
1488 (self.0)(*place, ctxt);
1489 self.visit_projection(place.as_ref(), ctxt, location);
1490 }
1491}