Skip to content

Commit 4f513b5

Browse files
committedMar 23, 2020
Split out some impls from rustc::mir into a separate submodule
1 parent 5aa15bf commit 4f513b5

File tree

2 files changed

+323
-322
lines changed

2 files changed

+323
-322
lines changed
 

‎src/librustc/mir/mod.rs

+1-322
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ pub mod mono;
4545
mod query;
4646
pub mod tcx;
4747
pub mod traversal;
48+
mod type_foldable;
4849
pub mod visit;
4950

5051
/// Types for locals
@@ -2683,325 +2684,3 @@ impl Location {
26832684
}
26842685
}
26852686
}
2686-
2687-
/*
2688-
* `TypeFoldable` implementations for MIR types
2689-
*/
2690-
2691-
CloneTypeFoldableAndLiftImpls! {
2692-
BlockTailInfo,
2693-
MirPhase,
2694-
SourceInfo,
2695-
FakeReadCause,
2696-
RetagKind,
2697-
SourceScope,
2698-
SourceScopeData,
2699-
SourceScopeLocalData,
2700-
UserTypeAnnotationIndex,
2701-
}
2702-
2703-
impl<'tcx> TypeFoldable<'tcx> for Terminator<'tcx> {
2704-
fn super_fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
2705-
use crate::mir::TerminatorKind::*;
2706-
2707-
let kind = match self.kind {
2708-
Goto { target } => Goto { target },
2709-
SwitchInt { ref discr, switch_ty, ref values, ref targets } => SwitchInt {
2710-
discr: discr.fold_with(folder),
2711-
switch_ty: switch_ty.fold_with(folder),
2712-
values: values.clone(),
2713-
targets: targets.clone(),
2714-
},
2715-
Drop { ref location, target, unwind } => {
2716-
Drop { location: location.fold_with(folder), target, unwind }
2717-
}
2718-
DropAndReplace { ref location, ref value, target, unwind } => DropAndReplace {
2719-
location: location.fold_with(folder),
2720-
value: value.fold_with(folder),
2721-
target,
2722-
unwind,
2723-
},
2724-
Yield { ref value, resume, ref resume_arg, drop } => Yield {
2725-
value: value.fold_with(folder),
2726-
resume,
2727-
resume_arg: resume_arg.fold_with(folder),
2728-
drop,
2729-
},
2730-
Call { ref func, ref args, ref destination, cleanup, from_hir_call } => {
2731-
let dest =
2732-
destination.as_ref().map(|&(ref loc, dest)| (loc.fold_with(folder), dest));
2733-
2734-
Call {
2735-
func: func.fold_with(folder),
2736-
args: args.fold_with(folder),
2737-
destination: dest,
2738-
cleanup,
2739-
from_hir_call,
2740-
}
2741-
}
2742-
Assert { ref cond, expected, ref msg, target, cleanup } => {
2743-
use AssertKind::*;
2744-
let msg = match msg {
2745-
BoundsCheck { ref len, ref index } => {
2746-
BoundsCheck { len: len.fold_with(folder), index: index.fold_with(folder) }
2747-
}
2748-
Overflow(_)
2749-
| OverflowNeg
2750-
| DivisionByZero
2751-
| RemainderByZero
2752-
| ResumedAfterReturn(_)
2753-
| ResumedAfterPanic(_) => msg.clone(),
2754-
};
2755-
Assert { cond: cond.fold_with(folder), expected, msg, target, cleanup }
2756-
}
2757-
GeneratorDrop => GeneratorDrop,
2758-
Resume => Resume,
2759-
Abort => Abort,
2760-
Return => Return,
2761-
Unreachable => Unreachable,
2762-
FalseEdges { real_target, imaginary_target } => {
2763-
FalseEdges { real_target, imaginary_target }
2764-
}
2765-
FalseUnwind { real_target, unwind } => FalseUnwind { real_target, unwind },
2766-
};
2767-
Terminator { source_info: self.source_info, kind }
2768-
}
2769-
2770-
fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
2771-
use crate::mir::TerminatorKind::*;
2772-
2773-
match self.kind {
2774-
SwitchInt { ref discr, switch_ty, .. } => {
2775-
discr.visit_with(visitor) || switch_ty.visit_with(visitor)
2776-
}
2777-
Drop { ref location, .. } => location.visit_with(visitor),
2778-
DropAndReplace { ref location, ref value, .. } => {
2779-
location.visit_with(visitor) || value.visit_with(visitor)
2780-
}
2781-
Yield { ref value, .. } => value.visit_with(visitor),
2782-
Call { ref func, ref args, ref destination, .. } => {
2783-
let dest = if let Some((ref loc, _)) = *destination {
2784-
loc.visit_with(visitor)
2785-
} else {
2786-
false
2787-
};
2788-
dest || func.visit_with(visitor) || args.visit_with(visitor)
2789-
}
2790-
Assert { ref cond, ref msg, .. } => {
2791-
if cond.visit_with(visitor) {
2792-
use AssertKind::*;
2793-
match msg {
2794-
BoundsCheck { ref len, ref index } => {
2795-
len.visit_with(visitor) || index.visit_with(visitor)
2796-
}
2797-
Overflow(_)
2798-
| OverflowNeg
2799-
| DivisionByZero
2800-
| RemainderByZero
2801-
| ResumedAfterReturn(_)
2802-
| ResumedAfterPanic(_) => false,
2803-
}
2804-
} else {
2805-
false
2806-
}
2807-
}
2808-
Goto { .. }
2809-
| Resume
2810-
| Abort
2811-
| Return
2812-
| GeneratorDrop
2813-
| Unreachable
2814-
| FalseEdges { .. }
2815-
| FalseUnwind { .. } => false,
2816-
}
2817-
}
2818-
}
2819-
2820-
impl<'tcx> TypeFoldable<'tcx> for GeneratorKind {
2821-
fn super_fold_with<F: TypeFolder<'tcx>>(&self, _: &mut F) -> Self {
2822-
*self
2823-
}
2824-
2825-
fn super_visit_with<V: TypeVisitor<'tcx>>(&self, _: &mut V) -> bool {
2826-
false
2827-
}
2828-
}
2829-
2830-
impl<'tcx> TypeFoldable<'tcx> for Place<'tcx> {
2831-
fn super_fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
2832-
Place { local: self.local.fold_with(folder), projection: self.projection.fold_with(folder) }
2833-
}
2834-
2835-
fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
2836-
self.local.visit_with(visitor) || self.projection.visit_with(visitor)
2837-
}
2838-
}
2839-
2840-
impl<'tcx> TypeFoldable<'tcx> for &'tcx ty::List<PlaceElem<'tcx>> {
2841-
fn super_fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
2842-
let v = self.iter().map(|t| t.fold_with(folder)).collect::<Vec<_>>();
2843-
folder.tcx().intern_place_elems(&v)
2844-
}
2845-
2846-
fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
2847-
self.iter().any(|t| t.visit_with(visitor))
2848-
}
2849-
}
2850-
2851-
impl<'tcx> TypeFoldable<'tcx> for Rvalue<'tcx> {
2852-
fn super_fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
2853-
use crate::mir::Rvalue::*;
2854-
match *self {
2855-
Use(ref op) => Use(op.fold_with(folder)),
2856-
Repeat(ref op, len) => Repeat(op.fold_with(folder), len),
2857-
Ref(region, bk, ref place) => {
2858-
Ref(region.fold_with(folder), bk, place.fold_with(folder))
2859-
}
2860-
AddressOf(mutability, ref place) => AddressOf(mutability, place.fold_with(folder)),
2861-
Len(ref place) => Len(place.fold_with(folder)),
2862-
Cast(kind, ref op, ty) => Cast(kind, op.fold_with(folder), ty.fold_with(folder)),
2863-
BinaryOp(op, ref rhs, ref lhs) => {
2864-
BinaryOp(op, rhs.fold_with(folder), lhs.fold_with(folder))
2865-
}
2866-
CheckedBinaryOp(op, ref rhs, ref lhs) => {
2867-
CheckedBinaryOp(op, rhs.fold_with(folder), lhs.fold_with(folder))
2868-
}
2869-
UnaryOp(op, ref val) => UnaryOp(op, val.fold_with(folder)),
2870-
Discriminant(ref place) => Discriminant(place.fold_with(folder)),
2871-
NullaryOp(op, ty) => NullaryOp(op, ty.fold_with(folder)),
2872-
Aggregate(ref kind, ref fields) => {
2873-
let kind = box match **kind {
2874-
AggregateKind::Array(ty) => AggregateKind::Array(ty.fold_with(folder)),
2875-
AggregateKind::Tuple => AggregateKind::Tuple,
2876-
AggregateKind::Adt(def, v, substs, user_ty, n) => AggregateKind::Adt(
2877-
def,
2878-
v,
2879-
substs.fold_with(folder),
2880-
user_ty.fold_with(folder),
2881-
n,
2882-
),
2883-
AggregateKind::Closure(id, substs) => {
2884-
AggregateKind::Closure(id, substs.fold_with(folder))
2885-
}
2886-
AggregateKind::Generator(id, substs, movablity) => {
2887-
AggregateKind::Generator(id, substs.fold_with(folder), movablity)
2888-
}
2889-
};
2890-
Aggregate(kind, fields.fold_with(folder))
2891-
}
2892-
}
2893-
}
2894-
2895-
fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
2896-
use crate::mir::Rvalue::*;
2897-
match *self {
2898-
Use(ref op) => op.visit_with(visitor),
2899-
Repeat(ref op, _) => op.visit_with(visitor),
2900-
Ref(region, _, ref place) => region.visit_with(visitor) || place.visit_with(visitor),
2901-
AddressOf(_, ref place) => place.visit_with(visitor),
2902-
Len(ref place) => place.visit_with(visitor),
2903-
Cast(_, ref op, ty) => op.visit_with(visitor) || ty.visit_with(visitor),
2904-
BinaryOp(_, ref rhs, ref lhs) | CheckedBinaryOp(_, ref rhs, ref lhs) => {
2905-
rhs.visit_with(visitor) || lhs.visit_with(visitor)
2906-
}
2907-
UnaryOp(_, ref val) => val.visit_with(visitor),
2908-
Discriminant(ref place) => place.visit_with(visitor),
2909-
NullaryOp(_, ty) => ty.visit_with(visitor),
2910-
Aggregate(ref kind, ref fields) => {
2911-
(match **kind {
2912-
AggregateKind::Array(ty) => ty.visit_with(visitor),
2913-
AggregateKind::Tuple => false,
2914-
AggregateKind::Adt(_, _, substs, user_ty, _) => {
2915-
substs.visit_with(visitor) || user_ty.visit_with(visitor)
2916-
}
2917-
AggregateKind::Closure(_, substs) => substs.visit_with(visitor),
2918-
AggregateKind::Generator(_, substs, _) => substs.visit_with(visitor),
2919-
}) || fields.visit_with(visitor)
2920-
}
2921-
}
2922-
}
2923-
}
2924-
2925-
impl<'tcx> TypeFoldable<'tcx> for Operand<'tcx> {
2926-
fn super_fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
2927-
match *self {
2928-
Operand::Copy(ref place) => Operand::Copy(place.fold_with(folder)),
2929-
Operand::Move(ref place) => Operand::Move(place.fold_with(folder)),
2930-
Operand::Constant(ref c) => Operand::Constant(c.fold_with(folder)),
2931-
}
2932-
}
2933-
2934-
fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
2935-
match *self {
2936-
Operand::Copy(ref place) | Operand::Move(ref place) => place.visit_with(visitor),
2937-
Operand::Constant(ref c) => c.visit_with(visitor),
2938-
}
2939-
}
2940-
}
2941-
2942-
impl<'tcx> TypeFoldable<'tcx> for PlaceElem<'tcx> {
2943-
fn super_fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
2944-
use crate::mir::ProjectionElem::*;
2945-
2946-
match *self {
2947-
Deref => Deref,
2948-
Field(f, ty) => Field(f, ty.fold_with(folder)),
2949-
Index(v) => Index(v.fold_with(folder)),
2950-
Downcast(symbol, variantidx) => Downcast(symbol, variantidx),
2951-
ConstantIndex { offset, min_length, from_end } => {
2952-
ConstantIndex { offset, min_length, from_end }
2953-
}
2954-
Subslice { from, to, from_end } => Subslice { from, to, from_end },
2955-
}
2956-
}
2957-
2958-
fn super_visit_with<Vs: TypeVisitor<'tcx>>(&self, visitor: &mut Vs) -> bool {
2959-
use crate::mir::ProjectionElem::*;
2960-
2961-
match self {
2962-
Field(_, ty) => ty.visit_with(visitor),
2963-
Index(v) => v.visit_with(visitor),
2964-
_ => false,
2965-
}
2966-
}
2967-
}
2968-
2969-
impl<'tcx> TypeFoldable<'tcx> for Field {
2970-
fn super_fold_with<F: TypeFolder<'tcx>>(&self, _: &mut F) -> Self {
2971-
*self
2972-
}
2973-
fn super_visit_with<V: TypeVisitor<'tcx>>(&self, _: &mut V) -> bool {
2974-
false
2975-
}
2976-
}
2977-
2978-
impl<'tcx> TypeFoldable<'tcx> for GeneratorSavedLocal {
2979-
fn super_fold_with<F: TypeFolder<'tcx>>(&self, _: &mut F) -> Self {
2980-
*self
2981-
}
2982-
fn super_visit_with<V: TypeVisitor<'tcx>>(&self, _: &mut V) -> bool {
2983-
false
2984-
}
2985-
}
2986-
2987-
impl<'tcx, R: Idx, C: Idx> TypeFoldable<'tcx> for BitMatrix<R, C> {
2988-
fn super_fold_with<F: TypeFolder<'tcx>>(&self, _: &mut F) -> Self {
2989-
self.clone()
2990-
}
2991-
fn super_visit_with<V: TypeVisitor<'tcx>>(&self, _: &mut V) -> bool {
2992-
false
2993-
}
2994-
}
2995-
2996-
impl<'tcx> TypeFoldable<'tcx> for Constant<'tcx> {
2997-
fn super_fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
2998-
Constant {
2999-
span: self.span,
3000-
user_ty: self.user_ty.fold_with(folder),
3001-
literal: self.literal.fold_with(folder),
3002-
}
3003-
}
3004-
fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
3005-
self.literal.visit_with(visitor)
3006-
}
3007-
}

‎src/librustc/mir/type_foldable.rs

+322
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,322 @@
1+
//! `TypeFoldable` implementations for MIR types
2+
3+
use super::*;
4+
use crate::ty;
5+
6+
CloneTypeFoldableAndLiftImpls! {
7+
BlockTailInfo,
8+
MirPhase,
9+
SourceInfo,
10+
FakeReadCause,
11+
RetagKind,
12+
SourceScope,
13+
SourceScopeData,
14+
SourceScopeLocalData,
15+
UserTypeAnnotationIndex,
16+
}
17+
18+
impl<'tcx> TypeFoldable<'tcx> for Terminator<'tcx> {
19+
fn super_fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
20+
use crate::mir::TerminatorKind::*;
21+
22+
let kind = match self.kind {
23+
Goto { target } => Goto { target },
24+
SwitchInt { ref discr, switch_ty, ref values, ref targets } => SwitchInt {
25+
discr: discr.fold_with(folder),
26+
switch_ty: switch_ty.fold_with(folder),
27+
values: values.clone(),
28+
targets: targets.clone(),
29+
},
30+
Drop { ref location, target, unwind } => {
31+
Drop { location: location.fold_with(folder), target, unwind }
32+
}
33+
DropAndReplace { ref location, ref value, target, unwind } => DropAndReplace {
34+
location: location.fold_with(folder),
35+
value: value.fold_with(folder),
36+
target,
37+
unwind,
38+
},
39+
Yield { ref value, resume, ref resume_arg, drop } => Yield {
40+
value: value.fold_with(folder),
41+
resume,
42+
resume_arg: resume_arg.fold_with(folder),
43+
drop,
44+
},
45+
Call { ref func, ref args, ref destination, cleanup, from_hir_call } => {
46+
let dest =
47+
destination.as_ref().map(|&(ref loc, dest)| (loc.fold_with(folder), dest));
48+
49+
Call {
50+
func: func.fold_with(folder),
51+
args: args.fold_with(folder),
52+
destination: dest,
53+
cleanup,
54+
from_hir_call,
55+
}
56+
}
57+
Assert { ref cond, expected, ref msg, target, cleanup } => {
58+
use AssertKind::*;
59+
let msg = match msg {
60+
BoundsCheck { ref len, ref index } => {
61+
BoundsCheck { len: len.fold_with(folder), index: index.fold_with(folder) }
62+
}
63+
Overflow(_)
64+
| OverflowNeg
65+
| DivisionByZero
66+
| RemainderByZero
67+
| ResumedAfterReturn(_)
68+
| ResumedAfterPanic(_) => msg.clone(),
69+
};
70+
Assert { cond: cond.fold_with(folder), expected, msg, target, cleanup }
71+
}
72+
GeneratorDrop => GeneratorDrop,
73+
Resume => Resume,
74+
Abort => Abort,
75+
Return => Return,
76+
Unreachable => Unreachable,
77+
FalseEdges { real_target, imaginary_target } => {
78+
FalseEdges { real_target, imaginary_target }
79+
}
80+
FalseUnwind { real_target, unwind } => FalseUnwind { real_target, unwind },
81+
};
82+
Terminator { source_info: self.source_info, kind }
83+
}
84+
85+
fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
86+
use crate::mir::TerminatorKind::*;
87+
88+
match self.kind {
89+
SwitchInt { ref discr, switch_ty, .. } => {
90+
discr.visit_with(visitor) || switch_ty.visit_with(visitor)
91+
}
92+
Drop { ref location, .. } => location.visit_with(visitor),
93+
DropAndReplace { ref location, ref value, .. } => {
94+
location.visit_with(visitor) || value.visit_with(visitor)
95+
}
96+
Yield { ref value, .. } => value.visit_with(visitor),
97+
Call { ref func, ref args, ref destination, .. } => {
98+
let dest = if let Some((ref loc, _)) = *destination {
99+
loc.visit_with(visitor)
100+
} else {
101+
false
102+
};
103+
dest || func.visit_with(visitor) || args.visit_with(visitor)
104+
}
105+
Assert { ref cond, ref msg, .. } => {
106+
if cond.visit_with(visitor) {
107+
use AssertKind::*;
108+
match msg {
109+
BoundsCheck { ref len, ref index } => {
110+
len.visit_with(visitor) || index.visit_with(visitor)
111+
}
112+
Overflow(_)
113+
| OverflowNeg
114+
| DivisionByZero
115+
| RemainderByZero
116+
| ResumedAfterReturn(_)
117+
| ResumedAfterPanic(_) => false,
118+
}
119+
} else {
120+
false
121+
}
122+
}
123+
Goto { .. }
124+
| Resume
125+
| Abort
126+
| Return
127+
| GeneratorDrop
128+
| Unreachable
129+
| FalseEdges { .. }
130+
| FalseUnwind { .. } => false,
131+
}
132+
}
133+
}
134+
135+
impl<'tcx> TypeFoldable<'tcx> for GeneratorKind {
136+
fn super_fold_with<F: TypeFolder<'tcx>>(&self, _: &mut F) -> Self {
137+
*self
138+
}
139+
140+
fn super_visit_with<V: TypeVisitor<'tcx>>(&self, _: &mut V) -> bool {
141+
false
142+
}
143+
}
144+
145+
impl<'tcx> TypeFoldable<'tcx> for Place<'tcx> {
146+
fn super_fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
147+
Place { local: self.local.fold_with(folder), projection: self.projection.fold_with(folder) }
148+
}
149+
150+
fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
151+
self.local.visit_with(visitor) || self.projection.visit_with(visitor)
152+
}
153+
}
154+
155+
impl<'tcx> TypeFoldable<'tcx> for &'tcx ty::List<PlaceElem<'tcx>> {
156+
fn super_fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
157+
let v = self.iter().map(|t| t.fold_with(folder)).collect::<Vec<_>>();
158+
folder.tcx().intern_place_elems(&v)
159+
}
160+
161+
fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
162+
self.iter().any(|t| t.visit_with(visitor))
163+
}
164+
}
165+
166+
impl<'tcx> TypeFoldable<'tcx> for Rvalue<'tcx> {
167+
fn super_fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
168+
use crate::mir::Rvalue::*;
169+
match *self {
170+
Use(ref op) => Use(op.fold_with(folder)),
171+
Repeat(ref op, len) => Repeat(op.fold_with(folder), len),
172+
Ref(region, bk, ref place) => {
173+
Ref(region.fold_with(folder), bk, place.fold_with(folder))
174+
}
175+
AddressOf(mutability, ref place) => AddressOf(mutability, place.fold_with(folder)),
176+
Len(ref place) => Len(place.fold_with(folder)),
177+
Cast(kind, ref op, ty) => Cast(kind, op.fold_with(folder), ty.fold_with(folder)),
178+
BinaryOp(op, ref rhs, ref lhs) => {
179+
BinaryOp(op, rhs.fold_with(folder), lhs.fold_with(folder))
180+
}
181+
CheckedBinaryOp(op, ref rhs, ref lhs) => {
182+
CheckedBinaryOp(op, rhs.fold_with(folder), lhs.fold_with(folder))
183+
}
184+
UnaryOp(op, ref val) => UnaryOp(op, val.fold_with(folder)),
185+
Discriminant(ref place) => Discriminant(place.fold_with(folder)),
186+
NullaryOp(op, ty) => NullaryOp(op, ty.fold_with(folder)),
187+
Aggregate(ref kind, ref fields) => {
188+
let kind = box match **kind {
189+
AggregateKind::Array(ty) => AggregateKind::Array(ty.fold_with(folder)),
190+
AggregateKind::Tuple => AggregateKind::Tuple,
191+
AggregateKind::Adt(def, v, substs, user_ty, n) => AggregateKind::Adt(
192+
def,
193+
v,
194+
substs.fold_with(folder),
195+
user_ty.fold_with(folder),
196+
n,
197+
),
198+
AggregateKind::Closure(id, substs) => {
199+
AggregateKind::Closure(id, substs.fold_with(folder))
200+
}
201+
AggregateKind::Generator(id, substs, movablity) => {
202+
AggregateKind::Generator(id, substs.fold_with(folder), movablity)
203+
}
204+
};
205+
Aggregate(kind, fields.fold_with(folder))
206+
}
207+
}
208+
}
209+
210+
fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
211+
use crate::mir::Rvalue::*;
212+
match *self {
213+
Use(ref op) => op.visit_with(visitor),
214+
Repeat(ref op, _) => op.visit_with(visitor),
215+
Ref(region, _, ref place) => region.visit_with(visitor) || place.visit_with(visitor),
216+
AddressOf(_, ref place) => place.visit_with(visitor),
217+
Len(ref place) => place.visit_with(visitor),
218+
Cast(_, ref op, ty) => op.visit_with(visitor) || ty.visit_with(visitor),
219+
BinaryOp(_, ref rhs, ref lhs) | CheckedBinaryOp(_, ref rhs, ref lhs) => {
220+
rhs.visit_with(visitor) || lhs.visit_with(visitor)
221+
}
222+
UnaryOp(_, ref val) => val.visit_with(visitor),
223+
Discriminant(ref place) => place.visit_with(visitor),
224+
NullaryOp(_, ty) => ty.visit_with(visitor),
225+
Aggregate(ref kind, ref fields) => {
226+
(match **kind {
227+
AggregateKind::Array(ty) => ty.visit_with(visitor),
228+
AggregateKind::Tuple => false,
229+
AggregateKind::Adt(_, _, substs, user_ty, _) => {
230+
substs.visit_with(visitor) || user_ty.visit_with(visitor)
231+
}
232+
AggregateKind::Closure(_, substs) => substs.visit_with(visitor),
233+
AggregateKind::Generator(_, substs, _) => substs.visit_with(visitor),
234+
}) || fields.visit_with(visitor)
235+
}
236+
}
237+
}
238+
}
239+
240+
impl<'tcx> TypeFoldable<'tcx> for Operand<'tcx> {
241+
fn super_fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
242+
match *self {
243+
Operand::Copy(ref place) => Operand::Copy(place.fold_with(folder)),
244+
Operand::Move(ref place) => Operand::Move(place.fold_with(folder)),
245+
Operand::Constant(ref c) => Operand::Constant(c.fold_with(folder)),
246+
}
247+
}
248+
249+
fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
250+
match *self {
251+
Operand::Copy(ref place) | Operand::Move(ref place) => place.visit_with(visitor),
252+
Operand::Constant(ref c) => c.visit_with(visitor),
253+
}
254+
}
255+
}
256+
257+
impl<'tcx> TypeFoldable<'tcx> for PlaceElem<'tcx> {
258+
fn super_fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
259+
use crate::mir::ProjectionElem::*;
260+
261+
match *self {
262+
Deref => Deref,
263+
Field(f, ty) => Field(f, ty.fold_with(folder)),
264+
Index(v) => Index(v.fold_with(folder)),
265+
Downcast(symbol, variantidx) => Downcast(symbol, variantidx),
266+
ConstantIndex { offset, min_length, from_end } => {
267+
ConstantIndex { offset, min_length, from_end }
268+
}
269+
Subslice { from, to, from_end } => Subslice { from, to, from_end },
270+
}
271+
}
272+
273+
fn super_visit_with<Vs: TypeVisitor<'tcx>>(&self, visitor: &mut Vs) -> bool {
274+
use crate::mir::ProjectionElem::*;
275+
276+
match self {
277+
Field(_, ty) => ty.visit_with(visitor),
278+
Index(v) => v.visit_with(visitor),
279+
_ => false,
280+
}
281+
}
282+
}
283+
284+
impl<'tcx> TypeFoldable<'tcx> for Field {
285+
fn super_fold_with<F: TypeFolder<'tcx>>(&self, _: &mut F) -> Self {
286+
*self
287+
}
288+
fn super_visit_with<V: TypeVisitor<'tcx>>(&self, _: &mut V) -> bool {
289+
false
290+
}
291+
}
292+
293+
impl<'tcx> TypeFoldable<'tcx> for GeneratorSavedLocal {
294+
fn super_fold_with<F: TypeFolder<'tcx>>(&self, _: &mut F) -> Self {
295+
*self
296+
}
297+
fn super_visit_with<V: TypeVisitor<'tcx>>(&self, _: &mut V) -> bool {
298+
false
299+
}
300+
}
301+
302+
impl<'tcx, R: Idx, C: Idx> TypeFoldable<'tcx> for BitMatrix<R, C> {
303+
fn super_fold_with<F: TypeFolder<'tcx>>(&self, _: &mut F) -> Self {
304+
self.clone()
305+
}
306+
fn super_visit_with<V: TypeVisitor<'tcx>>(&self, _: &mut V) -> bool {
307+
false
308+
}
309+
}
310+
311+
impl<'tcx> TypeFoldable<'tcx> for Constant<'tcx> {
312+
fn super_fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
313+
Constant {
314+
span: self.span,
315+
user_ty: self.user_ty.fold_with(folder),
316+
literal: self.literal.fold_with(folder),
317+
}
318+
}
319+
fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
320+
self.literal.visit_with(visitor)
321+
}
322+
}

0 commit comments

Comments
 (0)
Please sign in to comment.