Skip to content

Commit 21f6afc

Browse files
committed
Remove TrivialTypeTraversal macros
1 parent 8a17195 commit 21f6afc

File tree

6 files changed

+21
-102
lines changed

6 files changed

+21
-102
lines changed

compiler/rustc_middle/src/macros.rs

Lines changed: 0 additions & 49 deletions
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_middle/src/ty/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,7 @@ pub enum Visibility<Id = LocalDefId> {
304304
}
305305

306306
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, HashStable, TyEncodable, TyDecodable)]
307+
#[derive(TypeFoldable, TypeVisitable)]
307308
pub enum BoundConstness {
308309
/// `T: Trait`
309310
NotConst,

compiler/rustc_middle/src/ty/structural_impls.rs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -418,13 +418,6 @@ TrivialLiftImpls! {
418418
rustc_target::abi::Size,
419419
}
420420

421-
// For some things about which the type library does not know, or does not
422-
// provide any traversal implementations, we need to provide a traversal
423-
// implementation (only for TyCtxt<'_> interners).
424-
TrivialTypeTraversalImpls! {
425-
crate::ty::BoundConstness,
426-
}
427-
428421
///////////////////////////////////////////////////////////////////////////
429422
// Lift implementations
430423

compiler/rustc_type_ir/src/fold.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,16 @@ impl<I: Interner, T: BoringTraversable> SpecTypeFoldable<I> for &PhantomData<T>
287287
///////////////////////////////////////////////////////////////////////////
288288
// Traversable implementations for upstream types.
289289

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

compiler/rustc_type_ir/src/macros.rs

Lines changed: 0 additions & 46 deletions
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_traversal_if_boring {
493
($val:tt.try_fold_with($folder:expr)) => {{

compiler/rustc_type_ir/src/visit.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,16 @@ impl<I: Interner, T: ?Sized + BoringTraversable> SpecTypeVisitable<I> for &Phant
155155
///////////////////////////////////////////////////////////////////////////
156156
// Traversable implementations for upstream types.
157157

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

0 commit comments

Comments
 (0)