Skip to content

Commit 78c18c8

Browse files
committed
Remove TrivialTypeTraversal macros
1 parent 699c6e4 commit 78c18c8

File tree

4 files changed

+20
-95
lines changed

4 files changed

+20
-95
lines changed

compiler/rustc_middle/src/macros.rs

-49
Original file line numberDiff line numberDiff line change
@@ -54,52 +54,3 @@ macro_rules! TrivialLiftImpls {
5454
)+
5555
};
5656
}
57-
58-
/// Used for types that are `Copy` and which **do not care arena
59-
/// allocated data** (i.e., don't need to be folded).
60-
#[macro_export]
61-
macro_rules! TrivialTypeTraversalImpls {
62-
($(for { $($generic:tt)+ } { $interner:ty } { $ty:ty })+) => {
63-
$(
64-
impl<$($generic)+> $crate::ty::fold::TypeFoldable<$interner> for $ty {
65-
fn try_fold_with<F: $crate::ty::fold::FallibleTypeFolder<$interner>>(
66-
self,
67-
_: &mut F,
68-
) -> ::std::result::Result<Self, F::Error> {
69-
Ok(self)
70-
}
71-
72-
#[inline]
73-
fn fold_with<F: $crate::ty::fold::TypeFolder<$interner>>(
74-
self,
75-
_: &mut F,
76-
) -> Self {
77-
self
78-
}
79-
}
80-
81-
impl<$($generic)+> $crate::ty::visit::TypeVisitable<$interner> for $ty {
82-
#[inline]
83-
fn visit_with<F: $crate::ty::visit::TypeVisitor<$interner>>(
84-
&self,
85-
_: &mut F)
86-
-> ::std::ops::ControlFlow<F::BreakTy>
87-
{
88-
::std::ops::ControlFlow::Continue(())
89-
}
90-
}
91-
)+
92-
};
93-
94-
(for <$tcx:lifetime> { $($ty:ty),+ $(,)? }) => {
95-
TrivialTypeTraversalImpls! {
96-
$(for { $tcx } { $crate::ty::TyCtxt<$tcx> } { $ty })+
97-
}
98-
};
99-
100-
($($ty:ty),+ $(,)?) => {
101-
TrivialTypeTraversalImpls! {
102-
$(for { I: $crate::ty::Interner } { I } { $ty })+
103-
}
104-
};
105-
}

compiler/rustc_type_ir/src/fold.rs

+10
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,16 @@ impl<I: TriviallyTraverses<T>, T> SpecTypeFoldable for &PhantomData<(I, T)> {
290290
///////////////////////////////////////////////////////////////////////////
291291
// Traversable implementations for upstream types.
292292

293+
// `()` is (obviously) a no-op traversal and therefore the auto-deref specialisation normally
294+
// negates any need for explicit implementation, however there are implementations of
295+
// `QueryTypeOp` that have have unit `QueryResponse` -- and that associated type must be
296+
// traversable for some generic operations to work upon it.
297+
impl<I: Interner> TypeFoldable<I> for () {
298+
fn try_fold_with<F: FallibleTypeFolder<I>>(self, _: &mut F) -> Result<(), F::Error> {
299+
Ok(())
300+
}
301+
}
302+
293303
// We provide implementations for 2- and 3-element tuples, however (absent specialisation)
294304
// we can only provide for one case: we choose our implementations to be where all elements
295305
// themselves implement the respective traits; thus if an element is a no-op traversal, it

compiler/rustc_type_ir/src/macros.rs

-46
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,3 @@
1-
/// Used for types that are `Copy` and which **do not care arena
2-
/// allocated data** (i.e., don't need to be folded).
3-
macro_rules! TrivialTypeTraversalImpls {
4-
($($ty:ty,)+) => {
5-
$(
6-
impl<I: $crate::Interner> $crate::fold::TypeFoldable<I> for $ty {
7-
fn try_fold_with<F: $crate::fold::FallibleTypeFolder<I>>(
8-
self,
9-
_: &mut F,
10-
) -> ::std::result::Result<Self, F::Error> {
11-
Ok(self)
12-
}
13-
14-
#[inline]
15-
fn fold_with<F: $crate::fold::TypeFolder<I>>(
16-
self,
17-
_: &mut F,
18-
) -> Self {
19-
self
20-
}
21-
}
22-
23-
impl<I: $crate::Interner> $crate::visit::TypeVisitable<I> for $ty {
24-
#[inline]
25-
fn visit_with<F: $crate::visit::TypeVisitor<I>>(
26-
&self,
27-
_: &mut F)
28-
-> ::std::ops::ControlFlow<F::BreakTy>
29-
{
30-
::std::ops::ControlFlow::Continue(())
31-
}
32-
}
33-
)+
34-
};
35-
}
36-
37-
///////////////////////////////////////////////////////////////////////////
38-
// Atomic structs
39-
//
40-
// For things that don't carry any arena-allocated data (and are
41-
// copy...), just add them to this list.
42-
43-
TrivialTypeTraversalImpls! {
44-
(),
45-
}
46-
471
#[macro_export]
482
macro_rules! noop_if_trivially_traversable {
493
($val:tt.try_fold_with::<$interner:ty>($folder:expr)) => {{

compiler/rustc_type_ir/src/visit.rs

+10
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,16 @@ impl<I: TriviallyTraverses<T>, T: ?Sized> SpecTypeVisitable for &PhantomData<(I,
158158
///////////////////////////////////////////////////////////////////////////
159159
// Traversable implementations for upstream types.
160160

161+
// `()` is (obviously) a no-op traversal and therefore the auto-deref specialisation normally
162+
// negates any need for explicit implementation, however there are implementations of
163+
// `QueryTypeOp` that have have unit `QueryResponse` -- and that associated type must be
164+
// traversable for some generic operations to work upon it.
165+
impl<I: Interner> TypeVisitable<I> for () {
166+
fn visit_with<V: TypeVisitor<I>>(&self, _: &mut V) -> ControlFlow<V::BreakTy> {
167+
ControlFlow::Continue(())
168+
}
169+
}
170+
161171
// We provide implementations for 2- and 3-element tuples, however (absent specialisation)
162172
// we can only provide for one case: we choose our implementations to be where all elements
163173
// themselves implement the respective traits; thus if an element is a no-op traversal, it

0 commit comments

Comments
 (0)