impl TypeVisitable in type traversal macros
This commit is contained in:
parent
e4b9625b87
commit
9ffdc2de8c
14 changed files with 57 additions and 35 deletions
|
@ -18,7 +18,7 @@ macro_rules! span_bug {
|
|||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// Lift and TypeFoldable macros
|
||||
// Lift and TypeFoldable/TypeVisitable macros
|
||||
//
|
||||
// When possible, use one of these (relatively) convenient macros to write
|
||||
// the impls for you.
|
||||
|
@ -48,7 +48,7 @@ macro_rules! CloneLiftImpls {
|
|||
/// Used for types that are `Copy` and which **do not care arena
|
||||
/// allocated data** (i.e., don't need to be folded).
|
||||
#[macro_export]
|
||||
macro_rules! TrivialTypeFoldableImpls {
|
||||
macro_rules! TrivialTypeTraversalImpls {
|
||||
(for <$tcx:lifetime> { $($ty:ty,)+ }) => {
|
||||
$(
|
||||
impl<$tcx> $crate::ty::fold::TypeFoldable<$tcx> for $ty {
|
||||
|
@ -58,8 +58,10 @@ macro_rules! TrivialTypeFoldableImpls {
|
|||
) -> ::std::result::Result<$ty, F::Error> {
|
||||
Ok(self)
|
||||
}
|
||||
}
|
||||
|
||||
fn visit_with<F: $crate::ty::fold::TypeVisitor<$tcx>>(
|
||||
impl<$tcx> $crate::ty::visit::TypeVisitable<$tcx> for $ty {
|
||||
fn visit_with<F: $crate::ty::visit::TypeVisitor<$tcx>>(
|
||||
&self,
|
||||
_: &mut F)
|
||||
-> ::std::ops::ControlFlow<F::BreakTy>
|
||||
|
@ -71,7 +73,7 @@ macro_rules! TrivialTypeFoldableImpls {
|
|||
};
|
||||
|
||||
($($ty:ty,)+) => {
|
||||
TrivialTypeFoldableImpls! {
|
||||
TrivialTypeTraversalImpls! {
|
||||
for <'tcx> {
|
||||
$($ty,)+
|
||||
}
|
||||
|
@ -80,15 +82,15 @@ macro_rules! TrivialTypeFoldableImpls {
|
|||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! TrivialTypeFoldableAndLiftImpls {
|
||||
macro_rules! TrivialTypeTraversalAndLiftImpls {
|
||||
($($t:tt)*) => {
|
||||
TrivialTypeFoldableImpls! { $($t)* }
|
||||
TrivialTypeTraversalImpls! { $($t)* }
|
||||
CloneLiftImpls! { $($t)* }
|
||||
}
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! EnumTypeFoldableImpl {
|
||||
macro_rules! EnumTypeTraversalImpl {
|
||||
(impl<$($p:tt),*> TypeFoldable<$tcx:tt> for $s:path {
|
||||
$($variants:tt)*
|
||||
} $(where $($wc:tt)*)*) => {
|
||||
|
@ -99,14 +101,22 @@ macro_rules! EnumTypeFoldableImpl {
|
|||
self,
|
||||
folder: &mut V,
|
||||
) -> ::std::result::Result<Self, V::Error> {
|
||||
EnumTypeFoldableImpl!(@FoldVariants(self, folder) input($($variants)*) output())
|
||||
EnumTypeTraversalImpl!(@FoldVariants(self, folder) input($($variants)*) output())
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
fn visit_with<V: $crate::ty::fold::TypeVisitor<$tcx>>(
|
||||
(impl<$($p:tt),*> TypeVisitable<$tcx:tt> for $s:path {
|
||||
$($variants:tt)*
|
||||
} $(where $($wc:tt)*)*) => {
|
||||
impl<$($p),*> $crate::ty::visit::TypeVisitable<$tcx> for $s
|
||||
$(where $($wc)*)*
|
||||
{
|
||||
fn visit_with<V: $crate::ty::visit::TypeVisitor<$tcx>>(
|
||||
&self,
|
||||
visitor: &mut V,
|
||||
) -> ::std::ops::ControlFlow<V::BreakTy> {
|
||||
EnumTypeFoldableImpl!(@VisitVariants(self, visitor) input($($variants)*) output())
|
||||
EnumTypeTraversalImpl!(@VisitVariants(self, visitor) input($($variants)*) output())
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -120,7 +130,7 @@ macro_rules! EnumTypeFoldableImpl {
|
|||
(@FoldVariants($this:expr, $folder:expr)
|
||||
input( ($variant:path) ( $($variant_arg:ident),* ) , $($input:tt)*)
|
||||
output( $($output:tt)*) ) => {
|
||||
EnumTypeFoldableImpl!(
|
||||
EnumTypeTraversalImpl!(
|
||||
@FoldVariants($this, $folder)
|
||||
input($($input)*)
|
||||
output(
|
||||
|
@ -137,7 +147,7 @@ macro_rules! EnumTypeFoldableImpl {
|
|||
(@FoldVariants($this:expr, $folder:expr)
|
||||
input( ($variant:path) { $($variant_arg:ident),* $(,)? } , $($input:tt)*)
|
||||
output( $($output:tt)*) ) => {
|
||||
EnumTypeFoldableImpl!(
|
||||
EnumTypeTraversalImpl!(
|
||||
@FoldVariants($this, $folder)
|
||||
input($($input)*)
|
||||
output(
|
||||
|
@ -155,7 +165,7 @@ macro_rules! EnumTypeFoldableImpl {
|
|||
(@FoldVariants($this:expr, $folder:expr)
|
||||
input( ($variant:path), $($input:tt)*)
|
||||
output( $($output:tt)*) ) => {
|
||||
EnumTypeFoldableImpl!(
|
||||
EnumTypeTraversalImpl!(
|
||||
@FoldVariants($this, $folder)
|
||||
input($($input)*)
|
||||
output(
|
||||
|
@ -174,12 +184,12 @@ macro_rules! EnumTypeFoldableImpl {
|
|||
(@VisitVariants($this:expr, $visitor:expr)
|
||||
input( ($variant:path) ( $($variant_arg:ident),* ) , $($input:tt)*)
|
||||
output( $($output:tt)*) ) => {
|
||||
EnumTypeFoldableImpl!(
|
||||
EnumTypeTraversalImpl!(
|
||||
@VisitVariants($this, $visitor)
|
||||
input($($input)*)
|
||||
output(
|
||||
$variant ( $($variant_arg),* ) => {
|
||||
$($crate::ty::fold::TypeFoldable::visit_with(
|
||||
$($crate::ty::visit::TypeVisitable::visit_with(
|
||||
$variant_arg, $visitor
|
||||
)?;)*
|
||||
::std::ops::ControlFlow::CONTINUE
|
||||
|
@ -192,12 +202,12 @@ macro_rules! EnumTypeFoldableImpl {
|
|||
(@VisitVariants($this:expr, $visitor:expr)
|
||||
input( ($variant:path) { $($variant_arg:ident),* $(,)? } , $($input:tt)*)
|
||||
output( $($output:tt)*) ) => {
|
||||
EnumTypeFoldableImpl!(
|
||||
EnumTypeTraversalImpl!(
|
||||
@VisitVariants($this, $visitor)
|
||||
input($($input)*)
|
||||
output(
|
||||
$variant { $($variant_arg),* } => {
|
||||
$($crate::ty::fold::TypeFoldable::visit_with(
|
||||
$($crate::ty::visit::TypeVisitable::visit_with(
|
||||
$variant_arg, $visitor
|
||||
)?;)*
|
||||
::std::ops::ControlFlow::CONTINUE
|
||||
|
@ -210,7 +220,7 @@ macro_rules! EnumTypeFoldableImpl {
|
|||
(@VisitVariants($this:expr, $visitor:expr)
|
||||
input( ($variant:path), $($input:tt)*)
|
||||
output( $($output:tt)*) ) => {
|
||||
EnumTypeFoldableImpl!(
|
||||
EnumTypeTraversalImpl!(
|
||||
@VisitVariants($this, $visitor)
|
||||
input($($input)*)
|
||||
output(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue