diff --git a/compiler/rustc_middle/src/infer/canonical.rs b/compiler/rustc_middle/src/infer/canonical.rs index 77b43576af72c..c6fe3e721032f 100644 --- a/compiler/rustc_middle/src/infer/canonical.rs +++ b/compiler/rustc_middle/src/infer/canonical.rs @@ -293,7 +293,7 @@ impl<'tcx, V> Canonical<'tcx, V> { pub type QueryOutlivesConstraint<'tcx> = ty::Binder<'tcx, ty::OutlivesPredicate, Region<'tcx>>>; -TrivialTypeFoldableAndLiftImpls! { +TrivialTypeTraversalAndLiftImpls! { for <'tcx> { crate::infer::canonical::Certainty, crate::infer::canonical::CanonicalVarInfo<'tcx>, @@ -301,7 +301,7 @@ TrivialTypeFoldableAndLiftImpls! { } } -TrivialTypeFoldableImpls! { +TrivialTypeTraversalImpls! { for <'tcx> { crate::infer::canonical::CanonicalVarInfos<'tcx>, } diff --git a/compiler/rustc_middle/src/macros.rs b/compiler/rustc_middle/src/macros.rs index 33b4dff977eb0..0e85c60a36302 100644 --- a/compiler/rustc_middle/src/macros.rs +++ b/compiler/rustc_middle/src/macros.rs @@ -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>( + impl<$tcx> $crate::ty::visit::TypeVisitable<$tcx> for $ty { + fn visit_with>( &self, _: &mut F) -> ::std::ops::ControlFlow @@ -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 { - EnumTypeFoldableImpl!(@FoldVariants(self, folder) input($($variants)*) output()) + EnumTypeTraversalImpl!(@FoldVariants(self, folder) input($($variants)*) output()) } + } + }; - fn visit_with>( + (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>( &self, visitor: &mut V, ) -> ::std::ops::ControlFlow { - 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( diff --git a/compiler/rustc_middle/src/mir/graph_cyclic_cache.rs b/compiler/rustc_middle/src/mir/graph_cyclic_cache.rs index 1279f5aee3691..f97bf2883b369 100644 --- a/compiler/rustc_middle/src/mir/graph_cyclic_cache.rs +++ b/compiler/rustc_middle/src/mir/graph_cyclic_cache.rs @@ -58,6 +58,6 @@ impl HashStable for GraphIsCyclicCache { } } -TrivialTypeFoldableAndLiftImpls! { +TrivialTypeTraversalAndLiftImpls! { GraphIsCyclicCache, } diff --git a/compiler/rustc_middle/src/mir/interpret/error.rs b/compiler/rustc_middle/src/mir/interpret/error.rs index f30769248c074..c979627409c42 100644 --- a/compiler/rustc_middle/src/mir/interpret/error.rs +++ b/compiler/rustc_middle/src/mir/interpret/error.rs @@ -29,7 +29,7 @@ impl From for ErrorHandled { } } -TrivialTypeFoldableAndLiftImpls! { +TrivialTypeTraversalAndLiftImpls! { ErrorHandled, } diff --git a/compiler/rustc_middle/src/mir/mod.rs b/compiler/rustc_middle/src/mir/mod.rs index 7e9393e5e7476..b068b27156400 100644 --- a/compiler/rustc_middle/src/mir/mod.rs +++ b/compiler/rustc_middle/src/mir/mod.rs @@ -762,7 +762,7 @@ pub enum ImplicitSelfKind { None, } -TrivialTypeFoldableAndLiftImpls! { BindingForm<'tcx>, } +TrivialTypeTraversalAndLiftImpls! { BindingForm<'tcx>, } mod binding_form_impl { use rustc_data_structures::stable_hasher::{HashStable, StableHasher}; @@ -2641,7 +2641,7 @@ impl UserTypeProjection { } } -TrivialTypeFoldableAndLiftImpls! { ProjectionKind, } +TrivialTypeTraversalAndLiftImpls! { ProjectionKind, } impl<'tcx> TypeFoldable<'tcx> for UserTypeProjection { fn try_fold_with>(self, folder: &mut F) -> Result { diff --git a/compiler/rustc_middle/src/mir/predecessors.rs b/compiler/rustc_middle/src/mir/predecessors.rs index 620cf7e336ba4..5f1fadaf3bc4c 100644 --- a/compiler/rustc_middle/src/mir/predecessors.rs +++ b/compiler/rustc_middle/src/mir/predecessors.rs @@ -73,6 +73,6 @@ impl HashStable for PredecessorCache { } } -TrivialTypeFoldableAndLiftImpls! { +TrivialTypeTraversalAndLiftImpls! { PredecessorCache, } diff --git a/compiler/rustc_middle/src/mir/switch_sources.rs b/compiler/rustc_middle/src/mir/switch_sources.rs index 99d13fcfef43e..d1f3e6b6fe6bd 100644 --- a/compiler/rustc_middle/src/mir/switch_sources.rs +++ b/compiler/rustc_middle/src/mir/switch_sources.rs @@ -73,6 +73,6 @@ impl HashStable for SwitchSourceCache { } } -TrivialTypeFoldableAndLiftImpls! { +TrivialTypeTraversalAndLiftImpls! { SwitchSourceCache, } diff --git a/compiler/rustc_middle/src/mir/traversal.rs b/compiler/rustc_middle/src/mir/traversal.rs index 7228e3f33b126..30648679daebf 100644 --- a/compiler/rustc_middle/src/mir/traversal.rs +++ b/compiler/rustc_middle/src/mir/traversal.rs @@ -384,6 +384,6 @@ impl HashStable for PostorderCache { } } -TrivialTypeFoldableAndLiftImpls! { +TrivialTypeTraversalAndLiftImpls! { PostorderCache, } diff --git a/compiler/rustc_middle/src/mir/type_foldable.rs b/compiler/rustc_middle/src/mir/type_foldable.rs index 4201b2d11ce2a..e1d50460f82bd 100644 --- a/compiler/rustc_middle/src/mir/type_foldable.rs +++ b/compiler/rustc_middle/src/mir/type_foldable.rs @@ -4,7 +4,7 @@ use super::*; use crate::ty; use rustc_data_structures::functor::IdFunctor; -TrivialTypeFoldableAndLiftImpls! { +TrivialTypeTraversalAndLiftImpls! { BlockTailInfo, MirPhase, SourceInfo, diff --git a/compiler/rustc_middle/src/thir/abstract_const.rs b/compiler/rustc_middle/src/thir/abstract_const.rs index e02ed414574b4..527dbd1cd090a 100644 --- a/compiler/rustc_middle/src/thir/abstract_const.rs +++ b/compiler/rustc_middle/src/thir/abstract_const.rs @@ -42,7 +42,7 @@ impl From for NotConstEvaluatable { } } -TrivialTypeFoldableAndLiftImpls! { +TrivialTypeTraversalAndLiftImpls! { NotConstEvaluatable, } diff --git a/compiler/rustc_middle/src/traits/select.rs b/compiler/rustc_middle/src/traits/select.rs index e5eaf960a99ff..34703b6282042 100644 --- a/compiler/rustc_middle/src/traits/select.rs +++ b/compiler/rustc_middle/src/traits/select.rs @@ -283,7 +283,7 @@ impl From for OverflowError { } } -TrivialTypeFoldableAndLiftImpls! { +TrivialTypeTraversalAndLiftImpls! { OverflowError, } diff --git a/compiler/rustc_middle/src/traits/structural_impls.rs b/compiler/rustc_middle/src/traits/structural_impls.rs index ea706053231f8..8f1a1564fc8e8 100644 --- a/compiler/rustc_middle/src/traits/structural_impls.rs +++ b/compiler/rustc_middle/src/traits/structural_impls.rs @@ -129,7 +129,7 @@ impl fmt::Debug for traits::ImplSourceConstDestructData { /////////////////////////////////////////////////////////////////////////// // Lift implementations -TrivialTypeFoldableAndLiftImpls! { +TrivialTypeTraversalAndLiftImpls! { super::IfExpressionCause, super::ImplSourceDiscriminantKindData, super::ImplSourcePointeeData, diff --git a/compiler/rustc_middle/src/ty/binding.rs b/compiler/rustc_middle/src/ty/binding.rs index 7ab192daf4b1d..3d65429f2e53c 100644 --- a/compiler/rustc_middle/src/ty/binding.rs +++ b/compiler/rustc_middle/src/ty/binding.rs @@ -8,7 +8,7 @@ pub enum BindingMode { BindByValue(Mutability), } -TrivialTypeFoldableAndLiftImpls! { BindingMode, } +TrivialTypeTraversalAndLiftImpls! { BindingMode, } impl BindingMode { pub fn convert(ba: BindingAnnotation) -> BindingMode { diff --git a/compiler/rustc_middle/src/ty/structural_impls.rs b/compiler/rustc_middle/src/ty/structural_impls.rs index 8ba5b882fdd57..4ec3f30600afb 100644 --- a/compiler/rustc_middle/src/ty/structural_impls.rs +++ b/compiler/rustc_middle/src/ty/structural_impls.rs @@ -183,7 +183,7 @@ impl<'tcx> fmt::Debug for ty::PredicateKind<'tcx> { // For things that don't carry any arena-allocated data (and are // copy...), just add them to this list. -TrivialTypeFoldableAndLiftImpls! { +TrivialTypeTraversalAndLiftImpls! { (), bool, usize, @@ -692,19 +692,31 @@ impl<'tcx, A: TypeFoldable<'tcx>, B: TypeFoldable<'tcx>, C: TypeFoldable<'tcx>> } } -EnumTypeFoldableImpl! { +EnumTypeTraversalImpl! { impl<'tcx, T> TypeFoldable<'tcx> for Option { (Some)(a), (None), } where T: TypeFoldable<'tcx> } +EnumTypeTraversalImpl! { + impl<'tcx, T> TypeVisitable<'tcx> for Option { + (Some)(a), + (None), + } where T: TypeVisitable<'tcx> +} -EnumTypeFoldableImpl! { +EnumTypeTraversalImpl! { impl<'tcx, T, E> TypeFoldable<'tcx> for Result { (Ok)(a), (Err)(a), } where T: TypeFoldable<'tcx>, E: TypeFoldable<'tcx>, } +EnumTypeTraversalImpl! { + impl<'tcx, T, E> TypeVisitable<'tcx> for Result { + (Ok)(a), + (Err)(a), + } where T: TypeVisitable<'tcx>, E: TypeVisitable<'tcx>, +} impl<'tcx, T: TypeFoldable<'tcx>> TypeFoldable<'tcx> for Rc { fn try_fold_with>(