1 //! `TypeVisitable` implementations for MIR types
6 impl<'tcx> TypeVisitable<'tcx> for Terminator<'tcx> {
7 fn visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<V::BreakTy> {
8 use crate::mir::TerminatorKind::*;
11 SwitchInt { ref discr, switch_ty, .. } => {
12 discr.visit_with(visitor)?;
13 switch_ty.visit_with(visitor)
15 Drop { ref place, .. } => place.visit_with(visitor),
16 DropAndReplace { ref place, ref value, .. } => {
17 place.visit_with(visitor)?;
18 value.visit_with(visitor)
20 Yield { ref value, .. } => value.visit_with(visitor),
21 Call { ref func, ref args, ref destination, .. } => {
22 destination.visit_with(visitor)?;
23 func.visit_with(visitor)?;
24 args.visit_with(visitor)
26 Assert { ref cond, ref msg, .. } => {
27 cond.visit_with(visitor)?;
30 BoundsCheck { ref len, ref index } => {
31 len.visit_with(visitor)?;
32 index.visit_with(visitor)
34 Overflow(_, l, r) => {
35 l.visit_with(visitor)?;
38 OverflowNeg(op) | DivisionByZero(op) | RemainderByZero(op) => {
39 op.visit_with(visitor)
41 ResumedAfterReturn(_) | ResumedAfterPanic(_) => ControlFlow::CONTINUE,
44 InlineAsm { ref operands, .. } => operands.visit_with(visitor),
52 | FalseUnwind { .. } => ControlFlow::CONTINUE,
57 impl<'tcx> TypeVisitable<'tcx> for GeneratorKind {
58 fn visit_with<V: TypeVisitor<'tcx>>(&self, _: &mut V) -> ControlFlow<V::BreakTy> {
63 impl<'tcx> TypeVisitable<'tcx> for Place<'tcx> {
64 fn visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<V::BreakTy> {
65 self.local.visit_with(visitor)?;
66 self.projection.visit_with(visitor)
70 impl<'tcx> TypeVisitable<'tcx> for &'tcx ty::List<PlaceElem<'tcx>> {
71 fn visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<V::BreakTy> {
72 self.iter().try_for_each(|t| t.visit_with(visitor))
76 impl<'tcx> TypeVisitable<'tcx> for Rvalue<'tcx> {
77 fn visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<V::BreakTy> {
78 use crate::mir::Rvalue::*;
80 Use(ref op) => op.visit_with(visitor),
81 CopyForDeref(ref place) => {
82 let op = &Operand::Copy(*place);
83 op.visit_with(visitor)
85 Repeat(ref op, _) => op.visit_with(visitor),
86 ThreadLocalRef(did) => did.visit_with(visitor),
87 Ref(region, _, ref place) => {
88 region.visit_with(visitor)?;
89 place.visit_with(visitor)
91 AddressOf(_, ref place) => place.visit_with(visitor),
92 Len(ref place) => place.visit_with(visitor),
93 Cast(_, ref op, ty) => {
94 op.visit_with(visitor)?;
95 ty.visit_with(visitor)
97 BinaryOp(_, box (ref rhs, ref lhs)) | CheckedBinaryOp(_, box (ref rhs, ref lhs)) => {
98 rhs.visit_with(visitor)?;
99 lhs.visit_with(visitor)
101 UnaryOp(_, ref val) => val.visit_with(visitor),
102 Discriminant(ref place) => place.visit_with(visitor),
103 NullaryOp(_, ty) => ty.visit_with(visitor),
104 Aggregate(ref kind, ref fields) => {
106 AggregateKind::Array(ty) => {
107 ty.visit_with(visitor)?;
109 AggregateKind::Tuple => {}
110 AggregateKind::Adt(_, _, substs, user_ty, _) => {
111 substs.visit_with(visitor)?;
112 user_ty.visit_with(visitor)?;
114 AggregateKind::Closure(_, substs) => {
115 substs.visit_with(visitor)?;
117 AggregateKind::Generator(_, substs, _) => {
118 substs.visit_with(visitor)?;
121 fields.visit_with(visitor)
123 ShallowInitBox(ref op, ty) => {
124 op.visit_with(visitor)?;
125 ty.visit_with(visitor)
131 impl<'tcx> TypeVisitable<'tcx> for Operand<'tcx> {
132 fn visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<V::BreakTy> {
134 Operand::Copy(ref place) | Operand::Move(ref place) => place.visit_with(visitor),
135 Operand::Constant(ref c) => c.visit_with(visitor),
140 impl<'tcx> TypeVisitable<'tcx> for PlaceElem<'tcx> {
141 fn visit_with<Vs: TypeVisitor<'tcx>>(&self, visitor: &mut Vs) -> ControlFlow<Vs::BreakTy> {
142 use crate::mir::ProjectionElem::*;
145 Field(_, ty) => ty.visit_with(visitor),
146 Index(v) => v.visit_with(visitor),
147 _ => ControlFlow::CONTINUE,
152 impl<'tcx> TypeVisitable<'tcx> for GeneratorSavedLocal {
153 fn visit_with<V: TypeVisitor<'tcx>>(&self, _: &mut V) -> ControlFlow<V::BreakTy> {
154 ControlFlow::CONTINUE
158 impl<'tcx, R: Idx, C: Idx> TypeVisitable<'tcx> for BitMatrix<R, C> {
159 fn visit_with<V: TypeVisitor<'tcx>>(&self, _: &mut V) -> ControlFlow<V::BreakTy> {
160 ControlFlow::CONTINUE
164 impl<'tcx> TypeVisitable<'tcx> for Constant<'tcx> {
165 fn visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<V::BreakTy> {
166 self.literal.visit_with(visitor)?;
167 self.user_ty.visit_with(visitor)
171 impl<'tcx> TypeVisitable<'tcx> for ConstantKind<'tcx> {
172 fn visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<V::BreakTy> {
173 visitor.visit_mir_const(*self)
177 impl<'tcx> TypeSuperVisitable<'tcx> for ConstantKind<'tcx> {
178 fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<V::BreakTy> {
180 ConstantKind::Ty(c) => c.visit_with(visitor),
181 ConstantKind::Val(_, t) => t.visit_with(visitor),