Skip to content

Commit 9ffdc2d

Browse files
committed
impl TypeVisitable in type traversal macros
1 parent e4b9625 commit 9ffdc2d

14 files changed

+57
-35
lines changed

compiler/rustc_middle/src/infer/canonical.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -293,15 +293,15 @@ impl<'tcx, V> Canonical<'tcx, V> {
293293
pub type QueryOutlivesConstraint<'tcx> =
294294
ty::Binder<'tcx, ty::OutlivesPredicate<GenericArg<'tcx>, Region<'tcx>>>;
295295

296-
TrivialTypeFoldableAndLiftImpls! {
296+
TrivialTypeTraversalAndLiftImpls! {
297297
for <'tcx> {
298298
crate::infer::canonical::Certainty,
299299
crate::infer::canonical::CanonicalVarInfo<'tcx>,
300300
crate::infer::canonical::CanonicalVarKind<'tcx>,
301301
}
302302
}
303303

304-
TrivialTypeFoldableImpls! {
304+
TrivialTypeTraversalImpls! {
305305
for <'tcx> {
306306
crate::infer::canonical::CanonicalVarInfos<'tcx>,
307307
}

compiler/rustc_middle/src/macros.rs

+28-18
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ macro_rules! span_bug {
1818
}
1919

2020
///////////////////////////////////////////////////////////////////////////
21-
// Lift and TypeFoldable macros
21+
// Lift and TypeFoldable/TypeVisitable macros
2222
//
2323
// When possible, use one of these (relatively) convenient macros to write
2424
// the impls for you.
@@ -48,7 +48,7 @@ macro_rules! CloneLiftImpls {
4848
/// Used for types that are `Copy` and which **do not care arena
4949
/// allocated data** (i.e., don't need to be folded).
5050
#[macro_export]
51-
macro_rules! TrivialTypeFoldableImpls {
51+
macro_rules! TrivialTypeTraversalImpls {
5252
(for <$tcx:lifetime> { $($ty:ty,)+ }) => {
5353
$(
5454
impl<$tcx> $crate::ty::fold::TypeFoldable<$tcx> for $ty {
@@ -58,8 +58,10 @@ macro_rules! TrivialTypeFoldableImpls {
5858
) -> ::std::result::Result<$ty, F::Error> {
5959
Ok(self)
6060
}
61+
}
6162

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>>(
6365
&self,
6466
_: &mut F)
6567
-> ::std::ops::ControlFlow<F::BreakTy>
@@ -71,7 +73,7 @@ macro_rules! TrivialTypeFoldableImpls {
7173
};
7274

7375
($($ty:ty,)+) => {
74-
TrivialTypeFoldableImpls! {
76+
TrivialTypeTraversalImpls! {
7577
for <'tcx> {
7678
$($ty,)+
7779
}
@@ -80,15 +82,15 @@ macro_rules! TrivialTypeFoldableImpls {
8082
}
8183

8284
#[macro_export]
83-
macro_rules! TrivialTypeFoldableAndLiftImpls {
85+
macro_rules! TrivialTypeTraversalAndLiftImpls {
8486
($($t:tt)*) => {
85-
TrivialTypeFoldableImpls! { $($t)* }
87+
TrivialTypeTraversalImpls! { $($t)* }
8688
CloneLiftImpls! { $($t)* }
8789
}
8890
}
8991

9092
#[macro_export]
91-
macro_rules! EnumTypeFoldableImpl {
93+
macro_rules! EnumTypeTraversalImpl {
9294
(impl<$($p:tt),*> TypeFoldable<$tcx:tt> for $s:path {
9395
$($variants:tt)*
9496
} $(where $($wc:tt)*)*) => {
@@ -99,14 +101,22 @@ macro_rules! EnumTypeFoldableImpl {
99101
self,
100102
folder: &mut V,
101103
) -> ::std::result::Result<Self, V::Error> {
102-
EnumTypeFoldableImpl!(@FoldVariants(self, folder) input($($variants)*) output())
104+
EnumTypeTraversalImpl!(@FoldVariants(self, folder) input($($variants)*) output())
103105
}
106+
}
107+
};
104108

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>>(
106116
&self,
107117
visitor: &mut V,
108118
) -> ::std::ops::ControlFlow<V::BreakTy> {
109-
EnumTypeFoldableImpl!(@VisitVariants(self, visitor) input($($variants)*) output())
119+
EnumTypeTraversalImpl!(@VisitVariants(self, visitor) input($($variants)*) output())
110120
}
111121
}
112122
};
@@ -120,7 +130,7 @@ macro_rules! EnumTypeFoldableImpl {
120130
(@FoldVariants($this:expr, $folder:expr)
121131
input( ($variant:path) ( $($variant_arg:ident),* ) , $($input:tt)*)
122132
output( $($output:tt)*) ) => {
123-
EnumTypeFoldableImpl!(
133+
EnumTypeTraversalImpl!(
124134
@FoldVariants($this, $folder)
125135
input($($input)*)
126136
output(
@@ -137,7 +147,7 @@ macro_rules! EnumTypeFoldableImpl {
137147
(@FoldVariants($this:expr, $folder:expr)
138148
input( ($variant:path) { $($variant_arg:ident),* $(,)? } , $($input:tt)*)
139149
output( $($output:tt)*) ) => {
140-
EnumTypeFoldableImpl!(
150+
EnumTypeTraversalImpl!(
141151
@FoldVariants($this, $folder)
142152
input($($input)*)
143153
output(
@@ -155,7 +165,7 @@ macro_rules! EnumTypeFoldableImpl {
155165
(@FoldVariants($this:expr, $folder:expr)
156166
input( ($variant:path), $($input:tt)*)
157167
output( $($output:tt)*) ) => {
158-
EnumTypeFoldableImpl!(
168+
EnumTypeTraversalImpl!(
159169
@FoldVariants($this, $folder)
160170
input($($input)*)
161171
output(
@@ -174,12 +184,12 @@ macro_rules! EnumTypeFoldableImpl {
174184
(@VisitVariants($this:expr, $visitor:expr)
175185
input( ($variant:path) ( $($variant_arg:ident),* ) , $($input:tt)*)
176186
output( $($output:tt)*) ) => {
177-
EnumTypeFoldableImpl!(
187+
EnumTypeTraversalImpl!(
178188
@VisitVariants($this, $visitor)
179189
input($($input)*)
180190
output(
181191
$variant ( $($variant_arg),* ) => {
182-
$($crate::ty::fold::TypeFoldable::visit_with(
192+
$($crate::ty::visit::TypeVisitable::visit_with(
183193
$variant_arg, $visitor
184194
)?;)*
185195
::std::ops::ControlFlow::CONTINUE
@@ -192,12 +202,12 @@ macro_rules! EnumTypeFoldableImpl {
192202
(@VisitVariants($this:expr, $visitor:expr)
193203
input( ($variant:path) { $($variant_arg:ident),* $(,)? } , $($input:tt)*)
194204
output( $($output:tt)*) ) => {
195-
EnumTypeFoldableImpl!(
205+
EnumTypeTraversalImpl!(
196206
@VisitVariants($this, $visitor)
197207
input($($input)*)
198208
output(
199209
$variant { $($variant_arg),* } => {
200-
$($crate::ty::fold::TypeFoldable::visit_with(
210+
$($crate::ty::visit::TypeVisitable::visit_with(
201211
$variant_arg, $visitor
202212
)?;)*
203213
::std::ops::ControlFlow::CONTINUE
@@ -210,7 +220,7 @@ macro_rules! EnumTypeFoldableImpl {
210220
(@VisitVariants($this:expr, $visitor:expr)
211221
input( ($variant:path), $($input:tt)*)
212222
output( $($output:tt)*) ) => {
213-
EnumTypeFoldableImpl!(
223+
EnumTypeTraversalImpl!(
214224
@VisitVariants($this, $visitor)
215225
input($($input)*)
216226
output(

compiler/rustc_middle/src/mir/graph_cyclic_cache.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,6 @@ impl<CTX> HashStable<CTX> for GraphIsCyclicCache {
5858
}
5959
}
6060

61-
TrivialTypeFoldableAndLiftImpls! {
61+
TrivialTypeTraversalAndLiftImpls! {
6262
GraphIsCyclicCache,
6363
}

compiler/rustc_middle/src/mir/interpret/error.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ impl From<ErrorGuaranteed> for ErrorHandled {
2929
}
3030
}
3131

32-
TrivialTypeFoldableAndLiftImpls! {
32+
TrivialTypeTraversalAndLiftImpls! {
3333
ErrorHandled,
3434
}
3535

compiler/rustc_middle/src/mir/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -762,7 +762,7 @@ pub enum ImplicitSelfKind {
762762
None,
763763
}
764764

765-
TrivialTypeFoldableAndLiftImpls! { BindingForm<'tcx>, }
765+
TrivialTypeTraversalAndLiftImpls! { BindingForm<'tcx>, }
766766

767767
mod binding_form_impl {
768768
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
@@ -2641,7 +2641,7 @@ impl UserTypeProjection {
26412641
}
26422642
}
26432643

2644-
TrivialTypeFoldableAndLiftImpls! { ProjectionKind, }
2644+
TrivialTypeTraversalAndLiftImpls! { ProjectionKind, }
26452645

26462646
impl<'tcx> TypeFoldable<'tcx> for UserTypeProjection {
26472647
fn try_fold_with<F: FallibleTypeFolder<'tcx>>(self, folder: &mut F) -> Result<Self, F::Error> {

compiler/rustc_middle/src/mir/predecessors.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,6 @@ impl<CTX> HashStable<CTX> for PredecessorCache {
7373
}
7474
}
7575

76-
TrivialTypeFoldableAndLiftImpls! {
76+
TrivialTypeTraversalAndLiftImpls! {
7777
PredecessorCache,
7878
}

compiler/rustc_middle/src/mir/switch_sources.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,6 @@ impl<CTX> HashStable<CTX> for SwitchSourceCache {
7373
}
7474
}
7575

76-
TrivialTypeFoldableAndLiftImpls! {
76+
TrivialTypeTraversalAndLiftImpls! {
7777
SwitchSourceCache,
7878
}

compiler/rustc_middle/src/mir/traversal.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,6 @@ impl<CTX> HashStable<CTX> for PostorderCache {
384384
}
385385
}
386386

387-
TrivialTypeFoldableAndLiftImpls! {
387+
TrivialTypeTraversalAndLiftImpls! {
388388
PostorderCache,
389389
}

compiler/rustc_middle/src/mir/type_foldable.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use super::*;
44
use crate::ty;
55
use rustc_data_structures::functor::IdFunctor;
66

7-
TrivialTypeFoldableAndLiftImpls! {
7+
TrivialTypeTraversalAndLiftImpls! {
88
BlockTailInfo,
99
MirPhase,
1010
SourceInfo,

compiler/rustc_middle/src/thir/abstract_const.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ impl From<ErrorGuaranteed> for NotConstEvaluatable {
4242
}
4343
}
4444

45-
TrivialTypeFoldableAndLiftImpls! {
45+
TrivialTypeTraversalAndLiftImpls! {
4646
NotConstEvaluatable,
4747
}
4848

compiler/rustc_middle/src/traits/select.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ impl From<ErrorGuaranteed> for OverflowError {
283283
}
284284
}
285285

286-
TrivialTypeFoldableAndLiftImpls! {
286+
TrivialTypeTraversalAndLiftImpls! {
287287
OverflowError,
288288
}
289289

compiler/rustc_middle/src/traits/structural_impls.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ impl<N: fmt::Debug> fmt::Debug for traits::ImplSourceConstDestructData<N> {
129129
///////////////////////////////////////////////////////////////////////////
130130
// Lift implementations
131131

132-
TrivialTypeFoldableAndLiftImpls! {
132+
TrivialTypeTraversalAndLiftImpls! {
133133
super::IfExpressionCause,
134134
super::ImplSourceDiscriminantKindData,
135135
super::ImplSourcePointeeData,

compiler/rustc_middle/src/ty/binding.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ pub enum BindingMode {
88
BindByValue(Mutability),
99
}
1010

11-
TrivialTypeFoldableAndLiftImpls! { BindingMode, }
11+
TrivialTypeTraversalAndLiftImpls! { BindingMode, }
1212

1313
impl BindingMode {
1414
pub fn convert(ba: BindingAnnotation) -> BindingMode {

compiler/rustc_middle/src/ty/structural_impls.rs

+15-3
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ impl<'tcx> fmt::Debug for ty::PredicateKind<'tcx> {
183183
// For things that don't carry any arena-allocated data (and are
184184
// copy...), just add them to this list.
185185

186-
TrivialTypeFoldableAndLiftImpls! {
186+
TrivialTypeTraversalAndLiftImpls! {
187187
(),
188188
bool,
189189
usize,
@@ -692,19 +692,31 @@ impl<'tcx, A: TypeFoldable<'tcx>, B: TypeFoldable<'tcx>, C: TypeFoldable<'tcx>>
692692
}
693693
}
694694

695-
EnumTypeFoldableImpl! {
695+
EnumTypeTraversalImpl! {
696696
impl<'tcx, T> TypeFoldable<'tcx> for Option<T> {
697697
(Some)(a),
698698
(None),
699699
} where T: TypeFoldable<'tcx>
700700
}
701+
EnumTypeTraversalImpl! {
702+
impl<'tcx, T> TypeVisitable<'tcx> for Option<T> {
703+
(Some)(a),
704+
(None),
705+
} where T: TypeVisitable<'tcx>
706+
}
701707

702-
EnumTypeFoldableImpl! {
708+
EnumTypeTraversalImpl! {
703709
impl<'tcx, T, E> TypeFoldable<'tcx> for Result<T, E> {
704710
(Ok)(a),
705711
(Err)(a),
706712
} where T: TypeFoldable<'tcx>, E: TypeFoldable<'tcx>,
707713
}
714+
EnumTypeTraversalImpl! {
715+
impl<'tcx, T, E> TypeVisitable<'tcx> for Result<T, E> {
716+
(Ok)(a),
717+
(Err)(a),
718+
} where T: TypeVisitable<'tcx>, E: TypeVisitable<'tcx>,
719+
}
708720

709721
impl<'tcx, T: TypeFoldable<'tcx>> TypeFoldable<'tcx> for Rc<T> {
710722
fn try_fold_with<F: FallibleTypeFolder<'tcx>>(

0 commit comments

Comments
 (0)