@@ -18,7 +18,7 @@ macro_rules! span_bug {
18
18
}
19
19
20
20
///////////////////////////////////////////////////////////////////////////
21
- // Lift and TypeFoldable macros
21
+ // Lift and TypeFoldable/TypeVisitable macros
22
22
//
23
23
// When possible, use one of these (relatively) convenient macros to write
24
24
// the impls for you.
@@ -48,7 +48,7 @@ macro_rules! CloneLiftImpls {
48
48
/// Used for types that are `Copy` and which **do not care arena
49
49
/// allocated data** (i.e., don't need to be folded).
50
50
#[ macro_export]
51
- macro_rules! TrivialTypeFoldableImpls {
51
+ macro_rules! TrivialTypeTraversalImpls {
52
52
( for <$tcx: lifetime> { $( $ty: ty, ) + } ) => {
53
53
$(
54
54
impl <$tcx> $crate:: ty:: fold:: TypeFoldable <$tcx> for $ty {
@@ -58,8 +58,10 @@ macro_rules! TrivialTypeFoldableImpls {
58
58
) -> :: std:: result:: Result <$ty, F :: Error > {
59
59
Ok ( self )
60
60
}
61
+ }
61
62
62
- fn visit_with<F : $crate:: ty:: fold:: TypeVisitor <$tcx>>(
63
+ impl <$tcx> $crate:: ty:: visit:: TypeVisitable <$tcx> for $ty {
64
+ fn visit_with<F : $crate:: ty:: visit:: TypeVisitor <$tcx>>(
63
65
& self ,
64
66
_: & mut F )
65
67
-> :: std:: ops:: ControlFlow <F :: BreakTy >
@@ -71,7 +73,7 @@ macro_rules! TrivialTypeFoldableImpls {
71
73
} ;
72
74
73
75
( $( $ty: ty, ) +) => {
74
- TrivialTypeFoldableImpls ! {
76
+ TrivialTypeTraversalImpls ! {
75
77
for <' tcx> {
76
78
$( $ty, ) +
77
79
}
@@ -80,15 +82,15 @@ macro_rules! TrivialTypeFoldableImpls {
80
82
}
81
83
82
84
#[ macro_export]
83
- macro_rules! TrivialTypeFoldableAndLiftImpls {
85
+ macro_rules! TrivialTypeTraversalAndLiftImpls {
84
86
( $( $t: tt) * ) => {
85
- TrivialTypeFoldableImpls ! { $( $t) * }
87
+ TrivialTypeTraversalImpls ! { $( $t) * }
86
88
CloneLiftImpls ! { $( $t) * }
87
89
}
88
90
}
89
91
90
92
#[ macro_export]
91
- macro_rules! EnumTypeFoldableImpl {
93
+ macro_rules! EnumTypeTraversalImpl {
92
94
( impl <$( $p: tt) ,* > TypeFoldable <$tcx: tt> for $s: path {
93
95
$( $variants: tt) *
94
96
} $( where $( $wc: tt) * ) * ) => {
@@ -99,14 +101,22 @@ macro_rules! EnumTypeFoldableImpl {
99
101
self ,
100
102
folder: & mut V ,
101
103
) -> :: std:: result:: Result <Self , V :: Error > {
102
- EnumTypeFoldableImpl !( @FoldVariants ( self , folder) input( $( $variants) * ) output( ) )
104
+ EnumTypeTraversalImpl !( @FoldVariants ( self , folder) input( $( $variants) * ) output( ) )
103
105
}
106
+ }
107
+ } ;
104
108
105
- fn visit_with<V : $crate:: ty:: fold:: TypeVisitor <$tcx>>(
109
+ ( impl <$( $p: tt) ,* > TypeVisitable <$tcx: tt> for $s: path {
110
+ $( $variants: tt) *
111
+ } $( where $( $wc: tt) * ) * ) => {
112
+ impl <$( $p) ,* > $crate:: ty:: visit:: TypeVisitable <$tcx> for $s
113
+ $( where $( $wc) * ) *
114
+ {
115
+ fn visit_with<V : $crate:: ty:: visit:: TypeVisitor <$tcx>>(
106
116
& self ,
107
117
visitor: & mut V ,
108
118
) -> :: std:: ops:: ControlFlow <V :: BreakTy > {
109
- EnumTypeFoldableImpl !( @VisitVariants ( self , visitor) input( $( $variants) * ) output( ) )
119
+ EnumTypeTraversalImpl !( @VisitVariants ( self , visitor) input( $( $variants) * ) output( ) )
110
120
}
111
121
}
112
122
} ;
@@ -120,7 +130,7 @@ macro_rules! EnumTypeFoldableImpl {
120
130
( @FoldVariants ( $this: expr, $folder: expr)
121
131
input( ( $variant: path) ( $( $variant_arg: ident) ,* ) , $( $input: tt) * )
122
132
output( $( $output: tt) * ) ) => {
123
- EnumTypeFoldableImpl !(
133
+ EnumTypeTraversalImpl !(
124
134
@FoldVariants ( $this, $folder)
125
135
input( $( $input) * )
126
136
output(
@@ -137,7 +147,7 @@ macro_rules! EnumTypeFoldableImpl {
137
147
( @FoldVariants ( $this: expr, $folder: expr)
138
148
input( ( $variant: path) { $( $variant_arg: ident) ,* $( , ) ? } , $( $input: tt) * )
139
149
output( $( $output: tt) * ) ) => {
140
- EnumTypeFoldableImpl !(
150
+ EnumTypeTraversalImpl !(
141
151
@FoldVariants ( $this, $folder)
142
152
input( $( $input) * )
143
153
output(
@@ -155,7 +165,7 @@ macro_rules! EnumTypeFoldableImpl {
155
165
( @FoldVariants ( $this: expr, $folder: expr)
156
166
input( ( $variant: path) , $( $input: tt) * )
157
167
output( $( $output: tt) * ) ) => {
158
- EnumTypeFoldableImpl !(
168
+ EnumTypeTraversalImpl !(
159
169
@FoldVariants ( $this, $folder)
160
170
input( $( $input) * )
161
171
output(
@@ -174,12 +184,12 @@ macro_rules! EnumTypeFoldableImpl {
174
184
( @VisitVariants ( $this: expr, $visitor: expr)
175
185
input( ( $variant: path) ( $( $variant_arg: ident) ,* ) , $( $input: tt) * )
176
186
output( $( $output: tt) * ) ) => {
177
- EnumTypeFoldableImpl !(
187
+ EnumTypeTraversalImpl !(
178
188
@VisitVariants ( $this, $visitor)
179
189
input( $( $input) * )
180
190
output(
181
191
$variant ( $( $variant_arg) ,* ) => {
182
- $( $crate:: ty:: fold :: TypeFoldable :: visit_with(
192
+ $( $crate:: ty:: visit :: TypeVisitable :: visit_with(
183
193
$variant_arg, $visitor
184
194
) ?; ) *
185
195
:: std:: ops:: ControlFlow :: CONTINUE
@@ -192,12 +202,12 @@ macro_rules! EnumTypeFoldableImpl {
192
202
( @VisitVariants ( $this: expr, $visitor: expr)
193
203
input( ( $variant: path) { $( $variant_arg: ident) ,* $( , ) ? } , $( $input: tt) * )
194
204
output( $( $output: tt) * ) ) => {
195
- EnumTypeFoldableImpl !(
205
+ EnumTypeTraversalImpl !(
196
206
@VisitVariants ( $this, $visitor)
197
207
input( $( $input) * )
198
208
output(
199
209
$variant { $( $variant_arg) ,* } => {
200
- $( $crate:: ty:: fold :: TypeFoldable :: visit_with(
210
+ $( $crate:: ty:: visit :: TypeVisitable :: visit_with(
201
211
$variant_arg, $visitor
202
212
) ?; ) *
203
213
:: std:: ops:: ControlFlow :: CONTINUE
@@ -210,7 +220,7 @@ macro_rules! EnumTypeFoldableImpl {
210
220
( @VisitVariants ( $this: expr, $visitor: expr)
211
221
input( ( $variant: path) , $( $input: tt) * )
212
222
output( $( $output: tt) * ) ) => {
213
- EnumTypeFoldableImpl !(
223
+ EnumTypeTraversalImpl !(
214
224
@VisitVariants ( $this, $visitor)
215
225
input( $( $input) * )
216
226
output(
0 commit comments