cl_ast/ast_visitor/
fold.rs

1//! A folder (implementer of the [Fold] trait) maps ASTs to ASTs
2
3use crate::ast::*;
4use cl_structures::span::Span;
5
6/// Deconstructs the entire AST, and reconstructs it from scratch.
7///
8/// Each method acts as a customization point.
9///
10/// There are a set of default implementations for enums
11/// under the name [`or_fold_`*](or_fold_expr_kind),
12/// provided for ease of use.
13///
14/// For all other nodes, traversal is *explicit*.
15pub trait Fold {
16    fn fold_span(&mut self, span: Span) -> Span {
17        span
18    }
19    fn fold_mutability(&mut self, mutability: Mutability) -> Mutability {
20        mutability
21    }
22    fn fold_visibility(&mut self, visibility: Visibility) -> Visibility {
23        visibility
24    }
25    fn fold_sym(&mut self, ident: Sym) -> Sym {
26        ident
27    }
28    fn fold_literal(&mut self, lit: Literal) -> Literal {
29        or_fold_literal(self, lit)
30    }
31    fn fold_bool(&mut self, b: bool) -> bool {
32        b
33    }
34    fn fold_char(&mut self, c: char) -> char {
35        c
36    }
37    fn fold_int(&mut self, i: u128) -> u128 {
38        i
39    }
40    fn fold_smuggled_float(&mut self, f: u64) -> u64 {
41        f
42    }
43    fn fold_string(&mut self, s: String) -> String {
44        s
45    }
46    fn fold_file(&mut self, f: File) -> File {
47        let File { name, items } = f;
48        File { name, items: items.into_iter().map(|i| self.fold_item(i)).collect() }
49    }
50    fn fold_attrs(&mut self, a: Attrs) -> Attrs {
51        let Attrs { meta } = a;
52        Attrs { meta: meta.into_iter().map(|m| self.fold_meta(m)).collect() }
53    }
54    fn fold_meta(&mut self, m: Meta) -> Meta {
55        let Meta { name, kind } = m;
56        Meta { name: self.fold_sym(name), kind: self.fold_meta_kind(kind) }
57    }
58    fn fold_meta_kind(&mut self, kind: MetaKind) -> MetaKind {
59        or_fold_meta_kind(self, kind)
60    }
61    fn fold_item(&mut self, i: Item) -> Item {
62        let Item { span, attrs, vis, kind } = i;
63        Item {
64            span: self.fold_span(span),
65            attrs: self.fold_attrs(attrs),
66            vis: self.fold_visibility(vis),
67            kind: self.fold_item_kind(kind),
68        }
69    }
70    fn fold_item_kind(&mut self, kind: ItemKind) -> ItemKind {
71        or_fold_item_kind(self, kind)
72    }
73    fn fold_generics(&mut self, gens: Generics) -> Generics {
74        let Generics { vars } = gens;
75        Generics { vars: vars.into_iter().map(|sym| self.fold_sym(sym)).collect() }
76    }
77    fn fold_alias(&mut self, a: Alias) -> Alias {
78        let Alias { name, from } = a;
79        Alias { name: self.fold_sym(name), from: from.map(|from| Box::new(self.fold_ty(*from))) }
80    }
81    fn fold_const(&mut self, c: Const) -> Const {
82        let Const { name, ty, init } = c;
83        Const {
84            name: self.fold_sym(name),
85            ty: Box::new(self.fold_ty(*ty)),
86            init: Box::new(self.fold_expr(*init)),
87        }
88    }
89    fn fold_static(&mut self, s: Static) -> Static {
90        let Static { mutable, name, ty, init } = s;
91        Static {
92            mutable: self.fold_mutability(mutable),
93            name: self.fold_sym(name),
94            ty: Box::new(self.fold_ty(*ty)),
95            init: Box::new(self.fold_expr(*init)),
96        }
97    }
98    fn fold_module(&mut self, m: Module) -> Module {
99        let Module { name, file } = m;
100        Module { name: self.fold_sym(name), file: file.map(|v| self.fold_file(v)) }
101    }
102    fn fold_function(&mut self, f: Function) -> Function {
103        let Function { name, gens, sign, bind, body } = f;
104        Function {
105            name: self.fold_sym(name),
106            gens: self.fold_generics(gens),
107            sign: self.fold_ty_fn(sign),
108            bind: self.fold_pattern(bind),
109            body: body.map(|b| self.fold_expr(b)),
110        }
111    }
112    fn fold_struct(&mut self, s: Struct) -> Struct {
113        let Struct { name, gens, kind } = s;
114        Struct {
115            name: self.fold_sym(name),
116            gens: self.fold_generics(gens),
117            kind: self.fold_struct_kind(kind),
118        }
119    }
120    fn fold_struct_kind(&mut self, kind: StructKind) -> StructKind {
121        match kind {
122            StructKind::Empty => StructKind::Empty,
123            StructKind::Tuple(tys) => {
124                StructKind::Tuple(tys.into_iter().map(|t| self.fold_ty(t)).collect())
125            }
126            StructKind::Struct(mem) => StructKind::Struct(
127                mem.into_iter()
128                    .map(|m| self.fold_struct_member(m))
129                    .collect(),
130            ),
131        }
132    }
133    fn fold_struct_member(&mut self, m: StructMember) -> StructMember {
134        let StructMember { vis, name, ty } = m;
135        StructMember {
136            vis: self.fold_visibility(vis),
137            name: self.fold_sym(name),
138            ty: self.fold_ty(ty),
139        }
140    }
141    fn fold_enum(&mut self, e: Enum) -> Enum {
142        let Enum { name, gens, variants: kind } = e;
143        Enum {
144            name: self.fold_sym(name),
145            gens: self.fold_generics(gens),
146            variants: kind.into_iter().map(|v| self.fold_variant(v)).collect(),
147        }
148    }
149    fn fold_variant(&mut self, v: Variant) -> Variant {
150        let Variant { name, kind, body } = v;
151
152        Variant {
153            name: self.fold_sym(name),
154            kind: self.fold_struct_kind(kind),
155            body: body.map(|e| Box::new(self.fold_expr(*e))),
156        }
157    }
158    fn fold_impl(&mut self, i: Impl) -> Impl {
159        let Impl { target, body } = i;
160        Impl { target: self.fold_impl_kind(target), body: self.fold_file(body) }
161    }
162    fn fold_impl_kind(&mut self, kind: ImplKind) -> ImplKind {
163        or_fold_impl_kind(self, kind)
164    }
165    fn fold_use(&mut self, u: Use) -> Use {
166        let Use { absolute, tree } = u;
167        Use { absolute, tree: self.fold_use_tree(tree) }
168    }
169    fn fold_use_tree(&mut self, tree: UseTree) -> UseTree {
170        or_fold_use_tree(self, tree)
171    }
172    fn fold_ty(&mut self, t: Ty) -> Ty {
173        let Ty { span, kind } = t;
174        Ty { span: self.fold_span(span), kind: self.fold_ty_kind(kind) }
175    }
176    fn fold_ty_kind(&mut self, kind: TyKind) -> TyKind {
177        or_fold_ty_kind(self, kind)
178    }
179    fn fold_ty_array(&mut self, a: TyArray) -> TyArray {
180        let TyArray { ty, count } = a;
181        TyArray { ty: Box::new(self.fold_ty_kind(*ty)), count }
182    }
183    fn fold_ty_slice(&mut self, s: TySlice) -> TySlice {
184        let TySlice { ty } = s;
185        TySlice { ty: Box::new(self.fold_ty_kind(*ty)) }
186    }
187    fn fold_ty_tuple(&mut self, t: TyTuple) -> TyTuple {
188        let TyTuple { types } = t;
189        TyTuple {
190            types: types
191                .into_iter()
192                .map(|kind| self.fold_ty_kind(kind))
193                .collect(),
194        }
195    }
196    fn fold_ty_ref(&mut self, t: TyRef) -> TyRef {
197        let TyRef { mutable, count, to } = t;
198        TyRef { mutable: self.fold_mutability(mutable), count, to: Box::new(self.fold_ty(*to)) }
199    }
200    fn fold_ty_fn(&mut self, t: TyFn) -> TyFn {
201        let TyFn { args, rety } = t;
202        TyFn {
203            args: Box::new(self.fold_ty_kind(*args)),
204            rety: rety.map(|t| Box::new(self.fold_ty(*t))),
205        }
206    }
207    fn fold_path(&mut self, p: Path) -> Path {
208        let Path { absolute, parts } = p;
209        Path { absolute, parts: parts.into_iter().map(|p| self.fold_path_part(p)).collect() }
210    }
211    fn fold_path_part(&mut self, p: PathPart) -> PathPart {
212        match p {
213            PathPart::SuperKw => PathPart::SuperKw,
214            PathPart::SelfTy => PathPart::SelfTy,
215            PathPart::Ident(i) => PathPart::Ident(self.fold_sym(i)),
216        }
217    }
218    fn fold_stmt(&mut self, s: Stmt) -> Stmt {
219        let Stmt { span, kind, semi } = s;
220        Stmt {
221            span: self.fold_span(span),
222            kind: self.fold_stmt_kind(kind),
223            semi: self.fold_semi(semi),
224        }
225    }
226    fn fold_stmt_kind(&mut self, kind: StmtKind) -> StmtKind {
227        or_fold_stmt_kind(self, kind)
228    }
229    fn fold_semi(&mut self, s: Semi) -> Semi {
230        s
231    }
232    fn fold_expr(&mut self, e: Expr) -> Expr {
233        let Expr { span, kind } = e;
234        Expr { span: self.fold_span(span), kind: self.fold_expr_kind(kind) }
235    }
236    fn fold_expr_kind(&mut self, kind: ExprKind) -> ExprKind {
237        or_fold_expr_kind(self, kind)
238    }
239    fn fold_closure(&mut self, value: Closure) -> Closure {
240        let Closure { arg, body } = value;
241        Closure { arg: Box::new(self.fold_pattern(*arg)), body: Box::new(self.fold_expr(*body)) }
242    }
243    fn fold_let(&mut self, l: Let) -> Let {
244        let Let { mutable, name, ty, init } = l;
245        Let {
246            mutable: self.fold_mutability(mutable),
247            name: self.fold_pattern(name),
248            ty: ty.map(|t| Box::new(self.fold_ty(*t))),
249            init: init.map(|e| Box::new(self.fold_expr(*e))),
250        }
251    }
252
253    fn fold_pattern(&mut self, p: Pattern) -> Pattern {
254        match p {
255            Pattern::Name(sym) => Pattern::Name(self.fold_sym(sym)),
256            Pattern::Path(path) => Pattern::Path(self.fold_path(path)),
257            Pattern::Literal(literal) => Pattern::Literal(self.fold_literal(literal)),
258            Pattern::Rest(Some(name)) => Pattern::Rest(Some(self.fold_pattern(*name).into())),
259            Pattern::Rest(None) => Pattern::Rest(None),
260            Pattern::Ref(mutability, pattern) => Pattern::Ref(
261                self.fold_mutability(mutability),
262                Box::new(self.fold_pattern(*pattern)),
263            ),
264            Pattern::RangeExc(head, tail) => Pattern::RangeInc(
265                Box::new(self.fold_pattern(*head)),
266                Box::new(self.fold_pattern(*tail)),
267            ),
268            Pattern::RangeInc(head, tail) => Pattern::RangeInc(
269                Box::new(self.fold_pattern(*head)),
270                Box::new(self.fold_pattern(*tail)),
271            ),
272            Pattern::Tuple(patterns) => {
273                Pattern::Tuple(patterns.into_iter().map(|p| self.fold_pattern(p)).collect())
274            }
275            Pattern::Array(patterns) => {
276                Pattern::Array(patterns.into_iter().map(|p| self.fold_pattern(p)).collect())
277            }
278            Pattern::Struct(path, items) => Pattern::Struct(
279                self.fold_path(path),
280                items
281                    .into_iter()
282                    .map(|(name, bind)| (name, bind.map(|p| self.fold_pattern(p))))
283                    .collect(),
284            ),
285            Pattern::TupleStruct(path, items) => Pattern::TupleStruct(
286                self.fold_path(path),
287                items
288                    .into_iter()
289                    .map(|bind| self.fold_pattern(bind))
290                    .collect(),
291            ),
292        }
293    }
294
295    fn fold_match(&mut self, m: Match) -> Match {
296        let Match { scrutinee, arms } = m;
297        Match {
298            scrutinee: self.fold_expr(*scrutinee).into(),
299            arms: arms
300                .into_iter()
301                .map(|arm| self.fold_match_arm(arm))
302                .collect(),
303        }
304    }
305
306    fn fold_match_arm(&mut self, a: MatchArm) -> MatchArm {
307        let MatchArm(pat, expr) = a;
308        MatchArm(self.fold_pattern(pat), self.fold_expr(expr))
309    }
310
311    fn fold_assign(&mut self, a: Assign) -> Assign {
312        let Assign { parts } = a;
313        let (head, tail) = *parts;
314        Assign { parts: Box::new((self.fold_expr(head), self.fold_expr(tail))) }
315    }
316    fn fold_modify(&mut self, m: Modify) -> Modify {
317        let Modify { kind, parts } = m;
318        let (head, tail) = *parts;
319        Modify {
320            kind: self.fold_modify_kind(kind),
321            parts: Box::new((self.fold_expr(head), self.fold_expr(tail))),
322        }
323    }
324    fn fold_modify_kind(&mut self, kind: ModifyKind) -> ModifyKind {
325        kind
326    }
327    fn fold_binary(&mut self, b: Binary) -> Binary {
328        let Binary { kind, parts } = b;
329        let (head, tail) = *parts;
330        Binary {
331            kind: self.fold_binary_kind(kind),
332            parts: Box::new((self.fold_expr(head), self.fold_expr(tail))),
333        }
334    }
335    fn fold_binary_kind(&mut self, kind: BinaryKind) -> BinaryKind {
336        kind
337    }
338    fn fold_unary(&mut self, u: Unary) -> Unary {
339        let Unary { kind, tail } = u;
340        Unary { kind: self.fold_unary_kind(kind), tail: Box::new(self.fold_expr(*tail)) }
341    }
342    fn fold_unary_kind(&mut self, kind: UnaryKind) -> UnaryKind {
343        kind
344    }
345    fn fold_cast(&mut self, cast: Cast) -> Cast {
346        let Cast { head, ty } = cast;
347        Cast { head: Box::new(self.fold_expr(*head)), ty: self.fold_ty(ty) }
348    }
349    fn fold_member(&mut self, m: Member) -> Member {
350        let Member { head, kind } = m;
351        Member { head: Box::new(self.fold_expr(*head)), kind: self.fold_member_kind(kind) }
352    }
353    fn fold_member_kind(&mut self, kind: MemberKind) -> MemberKind {
354        or_fold_member_kind(self, kind)
355    }
356    fn fold_index(&mut self, i: Index) -> Index {
357        let Index { head, indices } = i;
358        Index {
359            head: Box::new(self.fold_expr(*head)),
360            indices: indices.into_iter().map(|e| self.fold_expr(e)).collect(),
361        }
362    }
363
364    fn fold_structor(&mut self, s: Structor) -> Structor {
365        let Structor { to, init } = s;
366        Structor {
367            to: self.fold_path(to),
368            init: init.into_iter().map(|f| self.fold_fielder(f)).collect(),
369        }
370    }
371
372    fn fold_fielder(&mut self, f: Fielder) -> Fielder {
373        let Fielder { name, init } = f;
374        Fielder { name: self.fold_sym(name), init: init.map(|e| Box::new(self.fold_expr(*e))) }
375    }
376    fn fold_array(&mut self, a: Array) -> Array {
377        let Array { values } = a;
378        Array { values: values.into_iter().map(|e| self.fold_expr(e)).collect() }
379    }
380    fn fold_array_rep(&mut self, a: ArrayRep) -> ArrayRep {
381        let ArrayRep { value, repeat } = a;
382        ArrayRep { value: Box::new(self.fold_expr(*value)), repeat }
383    }
384    fn fold_addrof(&mut self, a: AddrOf) -> AddrOf {
385        let AddrOf { mutable, expr } = a;
386        AddrOf { mutable: self.fold_mutability(mutable), expr: Box::new(self.fold_expr(*expr)) }
387    }
388    fn fold_block(&mut self, b: Block) -> Block {
389        let Block { stmts } = b;
390        Block { stmts: stmts.into_iter().map(|s| self.fold_stmt(s)).collect() }
391    }
392    fn fold_group(&mut self, g: Group) -> Group {
393        let Group { expr } = g;
394        Group { expr: Box::new(self.fold_expr(*expr)) }
395    }
396    fn fold_tuple(&mut self, t: Tuple) -> Tuple {
397        let Tuple { exprs } = t;
398        Tuple { exprs: exprs.into_iter().map(|e| self.fold_expr(e)).collect() }
399    }
400    fn fold_while(&mut self, w: While) -> While {
401        let While { cond, pass, fail } = w;
402        While {
403            cond: Box::new(self.fold_expr(*cond)),
404            pass: Box::new(self.fold_block(*pass)),
405            fail: self.fold_else(fail),
406        }
407    }
408    fn fold_if(&mut self, i: If) -> If {
409        let If { cond, pass, fail } = i;
410        If {
411            cond: Box::new(self.fold_expr(*cond)),
412            pass: Box::new(self.fold_block(*pass)),
413            fail: self.fold_else(fail),
414        }
415    }
416    fn fold_for(&mut self, f: For) -> For {
417        let For { bind, cond, pass, fail } = f;
418        For {
419            bind: self.fold_pattern(bind),
420            cond: Box::new(self.fold_expr(*cond)),
421            pass: Box::new(self.fold_block(*pass)),
422            fail: self.fold_else(fail),
423        }
424    }
425    fn fold_else(&mut self, e: Else) -> Else {
426        let Else { body } = e;
427        Else { body: body.map(|e| Box::new(self.fold_expr(*e))) }
428    }
429    fn fold_break(&mut self, b: Break) -> Break {
430        let Break { body } = b;
431        Break { body: body.map(|e| Box::new(self.fold_expr(*e))) }
432    }
433    fn fold_return(&mut self, r: Return) -> Return {
434        let Return { body } = r;
435        Return { body: body.map(|e| Box::new(self.fold_expr(*e))) }
436    }
437}
438
439#[inline]
440/// Folds a [Literal] in the default way
441pub fn or_fold_literal<F: Fold + ?Sized>(folder: &mut F, lit: Literal) -> Literal {
442    match lit {
443        Literal::Bool(b) => Literal::Bool(folder.fold_bool(b)),
444        Literal::Char(c) => Literal::Char(folder.fold_char(c)),
445        Literal::Int(i) => Literal::Int(folder.fold_int(i)),
446        Literal::Float(f) => Literal::Float(folder.fold_smuggled_float(f)),
447        Literal::String(s) => Literal::String(folder.fold_string(s)),
448    }
449}
450
451#[inline]
452/// Folds a [MetaKind] in the default way
453pub fn or_fold_meta_kind<F: Fold + ?Sized>(folder: &mut F, kind: MetaKind) -> MetaKind {
454    match kind {
455        MetaKind::Plain => MetaKind::Plain,
456        MetaKind::Equals(l) => MetaKind::Equals(folder.fold_literal(l)),
457        MetaKind::Func(lits) => {
458            MetaKind::Func(lits.into_iter().map(|l| folder.fold_literal(l)).collect())
459        }
460    }
461}
462
463#[inline]
464/// Folds an [ItemKind] in the default way
465pub fn or_fold_item_kind<F: Fold + ?Sized>(folder: &mut F, kind: ItemKind) -> ItemKind {
466    match kind {
467        ItemKind::Module(m) => ItemKind::Module(folder.fold_module(m)),
468        ItemKind::Alias(a) => ItemKind::Alias(folder.fold_alias(a)),
469        ItemKind::Enum(e) => ItemKind::Enum(folder.fold_enum(e)),
470        ItemKind::Struct(s) => ItemKind::Struct(folder.fold_struct(s)),
471        ItemKind::Const(c) => ItemKind::Const(folder.fold_const(c)),
472        ItemKind::Static(s) => ItemKind::Static(folder.fold_static(s)),
473        ItemKind::Function(f) => ItemKind::Function(folder.fold_function(f)),
474        ItemKind::Impl(i) => ItemKind::Impl(folder.fold_impl(i)),
475        ItemKind::Use(u) => ItemKind::Use(folder.fold_use(u)),
476    }
477}
478
479#[inline]
480/// Folds a [StructKind] in the default way
481pub fn or_fold_struct_kind<F: Fold + ?Sized>(folder: &mut F, kind: StructKind) -> StructKind {
482    match kind {
483        StructKind::Empty => StructKind::Empty,
484        StructKind::Tuple(tys) => {
485            StructKind::Tuple(tys.into_iter().map(|t| folder.fold_ty(t)).collect())
486        }
487        StructKind::Struct(mem) => StructKind::Struct(
488            mem.into_iter()
489                .map(|m| folder.fold_struct_member(m))
490                .collect(),
491        ),
492    }
493}
494
495#[inline]
496/// Folds an [ImplKind] in the default way
497pub fn or_fold_impl_kind<F: Fold + ?Sized>(folder: &mut F, kind: ImplKind) -> ImplKind {
498    match kind {
499        ImplKind::Type(t) => ImplKind::Type(folder.fold_ty(t)),
500        ImplKind::Trait { impl_trait, for_type } => ImplKind::Trait {
501            impl_trait: folder.fold_path(impl_trait),
502            for_type: Box::new(folder.fold_ty(*for_type)),
503        },
504    }
505}
506
507#[inline]
508pub fn or_fold_use_tree<F: Fold + ?Sized>(folder: &mut F, tree: UseTree) -> UseTree {
509    match tree {
510        UseTree::Tree(tree) => UseTree::Tree(
511            tree.into_iter()
512                .map(|tree| folder.fold_use_tree(tree))
513                .collect(),
514        ),
515        UseTree::Path(path, rest) => UseTree::Path(
516            folder.fold_path_part(path),
517            Box::new(folder.fold_use_tree(*rest)),
518        ),
519        UseTree::Alias(path, name) => UseTree::Alias(folder.fold_sym(path), folder.fold_sym(name)),
520        UseTree::Name(name) => UseTree::Name(folder.fold_sym(name)),
521        UseTree::Glob => UseTree::Glob,
522    }
523}
524
525#[inline]
526/// Folds a [TyKind] in the default way
527pub fn or_fold_ty_kind<F: Fold + ?Sized>(folder: &mut F, kind: TyKind) -> TyKind {
528    match kind {
529        TyKind::Never => TyKind::Never,
530        TyKind::Empty => TyKind::Empty,
531        TyKind::Infer => TyKind::Infer,
532        TyKind::Path(p) => TyKind::Path(folder.fold_path(p)),
533        TyKind::Array(a) => TyKind::Array(folder.fold_ty_array(a)),
534        TyKind::Slice(s) => TyKind::Slice(folder.fold_ty_slice(s)),
535        TyKind::Tuple(t) => TyKind::Tuple(folder.fold_ty_tuple(t)),
536        TyKind::Ref(t) => TyKind::Ref(folder.fold_ty_ref(t)),
537        TyKind::Fn(t) => TyKind::Fn(folder.fold_ty_fn(t)),
538    }
539}
540
541#[inline]
542/// Folds a [StmtKind] in the default way
543pub fn or_fold_stmt_kind<F: Fold + ?Sized>(folder: &mut F, kind: StmtKind) -> StmtKind {
544    match kind {
545        StmtKind::Empty => StmtKind::Empty,
546        StmtKind::Item(i) => StmtKind::Item(Box::new(folder.fold_item(*i))),
547        StmtKind::Expr(e) => StmtKind::Expr(Box::new(folder.fold_expr(*e))),
548    }
549}
550#[inline]
551/// Folds an [ExprKind] in the default way
552pub fn or_fold_expr_kind<F: Fold + ?Sized>(folder: &mut F, kind: ExprKind) -> ExprKind {
553    match kind {
554        ExprKind::Empty => ExprKind::Empty,
555        ExprKind::Closure(c) => ExprKind::Closure(folder.fold_closure(c)),
556        ExprKind::Quote(q) => ExprKind::Quote(q), // quoted expressions are left unmodified
557        ExprKind::Let(l) => ExprKind::Let(folder.fold_let(l)),
558        ExprKind::Match(m) => ExprKind::Match(folder.fold_match(m)),
559        ExprKind::Assign(a) => ExprKind::Assign(folder.fold_assign(a)),
560        ExprKind::Modify(m) => ExprKind::Modify(folder.fold_modify(m)),
561        ExprKind::Binary(b) => ExprKind::Binary(folder.fold_binary(b)),
562        ExprKind::Unary(u) => ExprKind::Unary(folder.fold_unary(u)),
563        ExprKind::Cast(c) => ExprKind::Cast(folder.fold_cast(c)),
564        ExprKind::Member(m) => ExprKind::Member(folder.fold_member(m)),
565        ExprKind::Index(i) => ExprKind::Index(folder.fold_index(i)),
566        ExprKind::Structor(s) => ExprKind::Structor(folder.fold_structor(s)),
567        ExprKind::Path(p) => ExprKind::Path(folder.fold_path(p)),
568        ExprKind::Literal(l) => ExprKind::Literal(folder.fold_literal(l)),
569        ExprKind::Array(a) => ExprKind::Array(folder.fold_array(a)),
570        ExprKind::ArrayRep(a) => ExprKind::ArrayRep(folder.fold_array_rep(a)),
571        ExprKind::AddrOf(a) => ExprKind::AddrOf(folder.fold_addrof(a)),
572        ExprKind::Block(b) => ExprKind::Block(folder.fold_block(b)),
573        ExprKind::Group(g) => ExprKind::Group(folder.fold_group(g)),
574        ExprKind::Tuple(t) => ExprKind::Tuple(folder.fold_tuple(t)),
575        ExprKind::While(w) => ExprKind::While(folder.fold_while(w)),
576        ExprKind::If(i) => ExprKind::If(folder.fold_if(i)),
577        ExprKind::For(f) => ExprKind::For(folder.fold_for(f)),
578        ExprKind::Break(b) => ExprKind::Break(folder.fold_break(b)),
579        ExprKind::Return(r) => ExprKind::Return(folder.fold_return(r)),
580        ExprKind::Continue => ExprKind::Continue,
581    }
582}
583pub fn or_fold_member_kind<F: Fold + ?Sized>(folder: &mut F, kind: MemberKind) -> MemberKind {
584    match kind {
585        MemberKind::Call(name, args) => {
586            MemberKind::Call(folder.fold_sym(name), folder.fold_tuple(args))
587        }
588        MemberKind::Struct(name) => MemberKind::Struct(folder.fold_sym(name)),
589        MemberKind::Tuple(name) => MemberKind::Tuple(folder.fold_literal(name)),
590    }
591}