Skip to main content

rustc_middle/
macros.rs

1///////////////////////////////////////////////////////////////////////////
2// Lift and TypeFoldable/TypeVisitable macros
3//
4// When possible, use one of these (relatively) convenient macros to write
5// the impls for you.
6
7macro_rules! TrivialLiftImpls {
8    ($($ty:ty),+ $(,)?) => {
9        $(
10            impl<'tcx> $crate::ty::Lift<$crate::ty::TyCtxt<'tcx>> for $ty {
11                type Lifted = Self;
12                fn lift_to_interner(self, _: $crate::ty::TyCtxt<'tcx>) -> Self {
13                    self
14                }
15            }
16        )+
17    };
18}
19
20/// Used for types that are `Copy` and which **do not care about arena
21/// allocated data** (i.e., don't need to be folded).
22macro_rules! TrivialTypeTraversalImpls {
23    ($($ty:ty),+ $(,)?) => {
24        $(
25            impl<'tcx> $crate::ty::TypeFoldable<$crate::ty::TyCtxt<'tcx>> for $ty {
26                fn try_fold_with<F: $crate::ty::FallibleTypeFolder<$crate::ty::TyCtxt<'tcx>>>(
27                    self,
28                    _: &mut F,
29                ) -> ::std::result::Result<Self, F::Error> {
30                    Ok(self)
31                }
32
33                #[inline]
34                fn fold_with<F: $crate::ty::TypeFolder<$crate::ty::TyCtxt<'tcx>>>(
35                    self,
36                    _: &mut F,
37                ) -> Self {
38                    self
39                }
40            }
41
42            impl<'tcx> $crate::ty::TypeVisitable<$crate::ty::TyCtxt<'tcx>> for $ty {
43                #[inline]
44                fn visit_with<F: $crate::ty::TypeVisitor<$crate::ty::TyCtxt<'tcx>>>(
45                    &self,
46                    _: &mut F)
47                    -> F::Result
48                {
49                    <F::Result as ::rustc_middle::ty::VisitorResult>::output()
50                }
51            }
52        )+
53    };
54}
55
56macro_rules! TrivialTypeTraversalAndLiftImpls {
57    ($($t:tt)*) => {
58        TrivialTypeTraversalImpls! { $($t)* }
59        TrivialLiftImpls! { $($t)* }
60    }
61}