3 pub fn type_foldable_derive(mut s: synstructure::Structure<'_>) -> proc_macro2::TokenStream {
4 if let syn::Data::Union(_) = s.ast().data {
5 panic!("cannot derive on union")
8 s.add_bounds(synstructure::AddBounds::Generics);
9 let body_visit = s.each(|bind| {
11 ::rustc_middle::ty::fold::TypeFoldable::visit_with(#bind, __folder)?;
14 s.bind_with(|_| synstructure::BindStyle::Move);
15 let body_fold = s.each_variant(|vi| {
16 let bindings = vi.bindings();
17 vi.construct(|_, index| {
18 let bind = &bindings[index];
20 ::rustc_middle::ty::fold::TypeFoldable::try_fold_with(#bind, __folder)?
26 quote!(::rustc_middle::ty::fold::TypeFoldable<'tcx>),
28 fn try_super_fold_with<__F: ::rustc_middle::ty::fold::FallibleTypeFolder<'tcx>>(
31 ) -> Result<Self, __F::Error> {
32 Ok(match self { #body_fold })
35 fn super_visit_with<__F: ::rustc_middle::ty::fold::TypeVisitor<'tcx>>(
38 ) -> ::std::ops::ControlFlow<__F::BreakTy> {
39 match *self { #body_visit }
40 ::std::ops::ControlFlow::CONTINUE