5 pub fn type_foldable_derive(mut s: synstructure::Structure<'_>) -> proc_macro2::TokenStream {
6 if let syn::Data::Union(_) = s.ast().data {
7 panic!("cannot derive on union")
10 s.add_bounds(synstructure::AddBounds::Generics);
11 let body_fold = s.each_variant(|vi| {
12 let bindings = vi.bindings();
13 vi.construct(|_, index| {
14 let bind = &bindings[index];
16 ::rustc::ty::fold::TypeFoldable::fold_with(#bind, __folder)
20 let body_visit = s.fold(false, |acc, bind| {
21 quote!{ #acc || ::rustc::ty::fold::TypeFoldable::visit_with(#bind, __folder) }
24 s.bound_impl(quote!(::rustc::ty::fold::TypeFoldable<'tcx>), quote!{
25 fn super_fold_with<__F: ::rustc::ty::fold::TypeFolder<'tcx>>(
29 match *self { #body_fold }
32 fn super_visit_with<__F: ::rustc::ty::fold::TypeVisitor<'tcx>>(
36 match *self { #body_visit }