Skip to content

Commit 85f0500

Browse files
committed
Replace TrivialTypeTraversal macros with derives
1 parent 9b8fcc5 commit 85f0500

File tree

5 files changed

+16
-110
lines changed

5 files changed

+16
-110
lines changed

compiler/rustc_middle/src/macros.rs

Lines changed: 0 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -62,60 +62,3 @@ macro_rules! CloneLiftImpls {
6262
}
6363
};
6464
}
65-
66-
/// Used for types that are `Copy` and which **do not care arena
67-
/// allocated data** (i.e., don't need to be folded).
68-
#[macro_export]
69-
macro_rules! TrivialTypeTraversalImpls {
70-
($(for { $($generic:tt)+ } { $interner:ty } { $ty:ty })+) => {
71-
$(
72-
impl<$($generic)+> $crate::ty::fold::TypeFoldable<$interner> for $ty {
73-
fn try_fold_with<F: $crate::ty::fold::FallibleTypeFolder<$interner>>(
74-
self,
75-
_: &mut F,
76-
) -> ::std::result::Result<Self, F::Error> {
77-
Ok(self)
78-
}
79-
80-
#[inline]
81-
fn fold_with<F: $crate::ty::fold::TypeFolder<$interner>>(
82-
self,
83-
_: &mut F,
84-
) -> Self {
85-
self
86-
}
87-
}
88-
89-
impl<$($generic)+> $crate::ty::visit::TypeVisitable<$interner> for $ty {
90-
#[inline]
91-
fn visit_with<F: $crate::ty::visit::TypeVisitor<$interner>>(
92-
&self,
93-
_: &mut F)
94-
-> ::std::ops::ControlFlow<F::BreakTy>
95-
{
96-
::std::ops::ControlFlow::Continue(())
97-
}
98-
}
99-
)+
100-
};
101-
102-
(for <$tcx:lifetime> { $($ty:ty,)+ }) => {
103-
TrivialTypeTraversalImpls! {
104-
$(for { $tcx } { $crate::ty::TyCtxt<$tcx> } { $ty })+
105-
}
106-
};
107-
108-
($($ty:ty,)+) => {
109-
TrivialTypeTraversalImpls! {
110-
$(for { I: $crate::ty::Interner } { I } { $ty })+
111-
}
112-
};
113-
}
114-
115-
#[macro_export]
116-
macro_rules! TrivialTypeTraversalAndLiftImpls {
117-
($($t:tt)*) => {
118-
TrivialTypeTraversalImpls! { $($t)* }
119-
CloneLiftImpls! { $($t)* }
120-
}
121-
}

compiler/rustc_middle/src/ty/mod.rs

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

293293
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, HashStable, TyEncodable, TyDecodable)]
294+
#[derive(TypeFoldable, TypeVisitable)]
294295
pub enum BoundConstness {
295296
/// `T: Trait`
296297
NotConst,

compiler/rustc_middle/src/ty/structural_impls.rs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,7 @@ CloneLiftImpls! {
235235
crate::traits::Reveal,
236236
crate::ty::adjustment::AutoBorrowMutability,
237237
crate::ty::AdtKind,
238+
crate::ty::BoundConstness,
238239
crate::ty::BoundRegionKind,
239240
crate::ty::AssocItem,
240241
crate::ty::AssocKind,
@@ -261,14 +262,6 @@ CloneLiftImpls! {
261262
ty::Placeholder<ty::BoundVar>,
262263
}
263264

264-
// For things about which the type library does not know, or does not
265-
// provide any traversal implementations, we need to provide both a Lift
266-
// implementation and traversal implementations (the latter only for
267-
// TyCtxt<'_> interners).
268-
TrivialTypeTraversalAndLiftImpls! {
269-
crate::ty::BoundConstness,
270-
}
271-
272265
CloneLiftImpls! {
273266
for<'tcx> {
274267
ty::ValTree<'tcx>,

compiler/rustc_type_ir/src/macros.rs

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +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-
371
macro_rules! EnumTypeTraversalImpl {
382
(impl<$($p:tt),*> TypeFoldable<$tcx:tt> for $s:path {
393
$($variants:tt)*

compiler/rustc_type_ir/src/structural_impls.rs

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,22 @@ use std::rc::Rc;
1313
use std::sync::Arc;
1414

1515
///////////////////////////////////////////////////////////////////////////
16-
// Atomic structs
17-
//
18-
// For things that don't carry any arena-allocated data (and are
19-
// copy...), just add them to this list.
16+
// Traversable implementations for upstream types.
2017

21-
TrivialTypeTraversalImpls! {
22-
(),
18+
// `()` is (obviously) a no-op traversal and therefore the auto-deref specialisation normally
19+
// negates any need for explicit implementation, however `ProjectionElem`'s implementation
20+
// requires its second type parameter to implement these traits and (annoyingly)
21+
// `ProjectionKind` (currently) uses unit type for that parameter.
22+
impl<I: Interner> TypeFoldable<I> for () {
23+
fn try_fold_with<F: FallibleTypeFolder<I>>(self, _: &mut F) -> Result<(), F::Error> {
24+
Ok(())
25+
}
26+
}
27+
impl<I: Interner> TypeVisitable<I> for () {
28+
fn visit_with<V: TypeVisitor<I>>(&self, _: &mut V) -> ControlFlow<V::BreakTy> {
29+
ControlFlow::Continue(())
30+
}
2331
}
24-
25-
///////////////////////////////////////////////////////////////////////////
26-
// Traversable implementations for upstream types.
2732

2833
// We provide implementations for 2- and 3-element tuples, however (absent specialisation)
2934
// we can only provide for one case: we choose our implementations to be where all elements

0 commit comments

Comments
 (0)