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 { gens, target, body } = i;
160        Impl {
161            gens: self.fold_generics(gens),
162            target: self.fold_impl_kind(target),
163            body: self.fold_file(body),
164        }
165    }
166    fn fold_impl_kind(&mut self, kind: ImplKind) -> ImplKind {
167        or_fold_impl_kind(self, kind)
168    }
169    fn fold_use(&mut self, u: Use) -> Use {
170        let Use { absolute, tree } = u;
171        Use { absolute, tree: self.fold_use_tree(tree) }
172    }
173    fn fold_use_tree(&mut self, tree: UseTree) -> UseTree {
174        or_fold_use_tree(self, tree)
175    }
176    fn fold_ty(&mut self, t: Ty) -> Ty {
177        let Ty { span, kind, gens } = t;
178        Ty {
179            span: self.fold_span(span),
180            kind: self.fold_ty_kind(kind),
181            gens: self.fold_generics(gens),
182        }
183    }
184    fn fold_ty_kind(&mut self, kind: TyKind) -> TyKind {
185        or_fold_ty_kind(self, kind)
186    }
187    fn fold_ty_array(&mut self, a: TyArray) -> TyArray {
188        let TyArray { ty, count } = a;
189        TyArray { ty: Box::new(self.fold_ty(*ty)), count }
190    }
191    fn fold_ty_slice(&mut self, s: TySlice) -> TySlice {
192        let TySlice { ty } = s;
193        TySlice { ty: Box::new(self.fold_ty(*ty)) }
194    }
195    fn fold_ty_tuple(&mut self, t: TyTuple) -> TyTuple {
196        let TyTuple { types } = t;
197        TyTuple { types: types.into_iter().map(|kind| self.fold_ty(kind)).collect() }
198    }
199    fn fold_ty_ref(&mut self, t: TyRef) -> TyRef {
200        let TyRef { mutable, count, to } = t;
201        TyRef { mutable: self.fold_mutability(mutable), count, to: Box::new(self.fold_ty(*to)) }
202    }
203    fn fold_ty_ptr(&mut self, t: TyPtr) -> TyPtr {
204        let TyPtr { to } = t;
205        TyPtr { to: Box::new(self.fold_ty(*to)) }
206    }
207    fn fold_ty_fn(&mut self, t: TyFn) -> TyFn {
208        let TyFn { args, rety } = t;
209        TyFn { args: Box::new(self.fold_ty(*args)), rety: Box::new(self.fold_ty(*rety)) }
210    }
211    fn fold_path(&mut self, p: Path) -> Path {
212        let Path { absolute, parts } = p;
213        Path { absolute, parts: parts.into_iter().map(|p| self.fold_path_part(p)).collect() }
214    }
215    fn fold_path_part(&mut self, p: PathPart) -> PathPart {
216        match p {
217            PathPart::SuperKw => PathPart::SuperKw,
218            PathPart::SelfTy => PathPart::SelfTy,
219            PathPart::Ident(i) => PathPart::Ident(self.fold_sym(i)),
220        }
221    }
222    fn fold_stmt(&mut self, s: Stmt) -> Stmt {
223        let Stmt { span, kind, semi } = s;
224        Stmt {
225            span: self.fold_span(span),
226            kind: self.fold_stmt_kind(kind),
227            semi: self.fold_semi(semi),
228        }
229    }
230    fn fold_stmt_kind(&mut self, kind: StmtKind) -> StmtKind {
231        or_fold_stmt_kind(self, kind)
232    }
233    fn fold_semi(&mut self, s: Semi) -> Semi {
234        s
235    }
236    fn fold_expr(&mut self, e: Expr) -> Expr {
237        let Expr { span, kind } = e;
238        Expr { span: self.fold_span(span), kind: self.fold_expr_kind(kind) }
239    }
240    fn fold_expr_kind(&mut self, kind: ExprKind) -> ExprKind {
241        or_fold_expr_kind(self, kind)
242    }
243    fn fold_closure(&mut self, value: Closure) -> Closure {
244        let Closure { arg, body } = value;
245        Closure { arg: Box::new(self.fold_pattern(*arg)), body: Box::new(self.fold_expr(*body)) }
246    }
247    fn fold_let(&mut self, l: Let) -> Let {
248        let Let { mutable, name, ty, init } = l;
249        Let {
250            mutable: self.fold_mutability(mutable),
251            name: self.fold_pattern(name),
252            ty: ty.map(|t| Box::new(self.fold_ty(*t))),
253            init: init.map(|e| Box::new(self.fold_expr(*e))),
254        }
255    }
256
257    fn fold_pattern(&mut self, p: Pattern) -> Pattern {
258        match p {
259            Pattern::Name(sym) => Pattern::Name(self.fold_sym(sym)),
260            Pattern::Path(path) => Pattern::Path(self.fold_path(path)),
261            Pattern::Literal(literal) => Pattern::Literal(self.fold_literal(literal)),
262            Pattern::Rest(Some(name)) => Pattern::Rest(Some(self.fold_pattern(*name).into())),
263            Pattern::Rest(None) => Pattern::Rest(None),
264            Pattern::Ref(mutability, pattern) => Pattern::Ref(
265                self.fold_mutability(mutability),
266                Box::new(self.fold_pattern(*pattern)),
267            ),
268            Pattern::RangeExc(head, tail) => Pattern::RangeInc(
269                Box::new(self.fold_pattern(*head)),
270                Box::new(self.fold_pattern(*tail)),
271            ),
272            Pattern::RangeInc(head, tail) => Pattern::RangeInc(
273                Box::new(self.fold_pattern(*head)),
274                Box::new(self.fold_pattern(*tail)),
275            ),
276            Pattern::Tuple(patterns) => {
277                Pattern::Tuple(patterns.into_iter().map(|p| self.fold_pattern(p)).collect())
278            }
279            Pattern::Array(patterns) => {
280                Pattern::Array(patterns.into_iter().map(|p| self.fold_pattern(p)).collect())
281            }
282            Pattern::Struct(path, items) => Pattern::Struct(
283                self.fold_path(path),
284                items
285                    .into_iter()
286                    .map(|(name, bind)| (name, bind.map(|p| self.fold_pattern(p))))
287                    .collect(),
288            ),
289            Pattern::TupleStruct(path, items) => Pattern::TupleStruct(
290                self.fold_path(path),
291                items
292                    .into_iter()
293                    .map(|bind| self.fold_pattern(bind))
294                    .collect(),
295            ),
296        }
297    }
298
299    fn fold_match(&mut self, m: Match) -> Match {
300        let Match { scrutinee, arms } = m;
301        Match {
302            scrutinee: self.fold_expr(*scrutinee).into(),
303            arms: arms
304                .into_iter()
305                .map(|arm| self.fold_match_arm(arm))
306                .collect(),
307        }
308    }
309
310    fn fold_match_arm(&mut self, a: MatchArm) -> MatchArm {
311        let MatchArm(pat, expr) = a;
312        MatchArm(self.fold_pattern(pat), self.fold_expr(expr))
313    }
314
315    fn fold_assign(&mut self, a: Assign) -> Assign {
316        let Assign { parts } = a;
317        let (head, tail) = *parts;
318        Assign { parts: Box::new((self.fold_expr(head), self.fold_expr(tail))) }
319    }
320    fn fold_modify(&mut self, m: Modify) -> Modify {
321        let Modify { kind, parts } = m;
322        let (head, tail) = *parts;
323        Modify {
324            kind: self.fold_modify_kind(kind),
325            parts: Box::new((self.fold_expr(head), self.fold_expr(tail))),
326        }
327    }
328    fn fold_modify_kind(&mut self, kind: ModifyKind) -> ModifyKind {
329        kind
330    }
331    fn fold_binary(&mut self, b: Binary) -> Binary {
332        let Binary { kind, parts } = b;
333        let (head, tail) = *parts;
334        Binary {
335            kind: self.fold_binary_kind(kind),
336            parts: Box::new((self.fold_expr(head), self.fold_expr(tail))),
337        }
338    }
339    fn fold_binary_kind(&mut self, kind: BinaryKind) -> BinaryKind {
340        kind
341    }
342    fn fold_unary(&mut self, u: Unary) -> Unary {
343        let Unary { kind, tail } = u;
344        Unary { kind: self.fold_unary_kind(kind), tail: Box::new(self.fold_expr(*tail)) }
345    }
346    fn fold_unary_kind(&mut self, kind: UnaryKind) -> UnaryKind {
347        kind
348    }
349    fn fold_cast(&mut self, cast: Cast) -> Cast {
350        let Cast { head, ty } = cast;
351        Cast { head: Box::new(self.fold_expr(*head)), ty: self.fold_ty(ty) }
352    }
353    fn fold_member(&mut self, m: Member) -> Member {
354        let Member { head, kind } = m;
355        Member { head: Box::new(self.fold_expr(*head)), kind: self.fold_member_kind(kind) }
356    }
357    fn fold_member_kind(&mut self, kind: MemberKind) -> MemberKind {
358        or_fold_member_kind(self, kind)
359    }
360    fn fold_index(&mut self, i: Index) -> Index {
361        let Index { head, indices } = i;
362        Index {
363            head: Box::new(self.fold_expr(*head)),
364            indices: indices.into_iter().map(|e| self.fold_expr(e)).collect(),
365        }
366    }
367
368    fn fold_structor(&mut self, s: Structor) -> Structor {
369        let Structor { to, init } = s;
370        Structor {
371            to: self.fold_path(to),
372            init: init.into_iter().map(|f| self.fold_fielder(f)).collect(),
373        }
374    }
375
376    fn fold_fielder(&mut self, f: Fielder) -> Fielder {
377        let Fielder { name, init } = f;
378        Fielder { name: self.fold_sym(name), init: init.map(|e| Box::new(self.fold_expr(*e))) }
379    }
380    fn fold_array(&mut self, a: Array) -> Array {
381        let Array { values } = a;
382        Array { values: values.into_iter().map(|e| self.fold_expr(e)).collect() }
383    }
384    fn fold_array_rep(&mut self, a: ArrayRep) -> ArrayRep {
385        let ArrayRep { value, repeat } = a;
386        ArrayRep { value: Box::new(self.fold_expr(*value)), repeat }
387    }
388    fn fold_addrof(&mut self, a: AddrOf) -> AddrOf {
389        let AddrOf { mutable, expr } = a;
390        AddrOf { mutable: self.fold_mutability(mutable), expr: Box::new(self.fold_expr(*expr)) }
391    }
392    fn fold_block(&mut self, b: Block) -> Block {
393        let Block { stmts } = b;
394        Block { stmts: stmts.into_iter().map(|s| self.fold_stmt(s)).collect() }
395    }
396    fn fold_group(&mut self, g: Group) -> Group {
397        let Group { expr } = g;
398        Group { expr: Box::new(self.fold_expr(*expr)) }
399    }
400    fn fold_tuple(&mut self, t: Tuple) -> Tuple {
401        let Tuple { exprs } = t;
402        Tuple { exprs: exprs.into_iter().map(|e| self.fold_expr(e)).collect() }
403    }
404    fn fold_while(&mut self, w: While) -> While {
405        let While { cond, pass, fail } = w;
406        While {
407            cond: Box::new(self.fold_expr(*cond)),
408            pass: Box::new(self.fold_block(*pass)),
409            fail: self.fold_else(fail),
410        }
411    }
412    fn fold_if(&mut self, i: If) -> If {
413        let If { cond, pass, fail } = i;
414        If {
415            cond: Box::new(self.fold_expr(*cond)),
416            pass: Box::new(self.fold_block(*pass)),
417            fail: self.fold_else(fail),
418        }
419    }
420    fn fold_for(&mut self, f: For) -> For {
421        let For { bind, cond, pass, fail } = f;
422        For {
423            bind: self.fold_pattern(bind),
424            cond: Box::new(self.fold_expr(*cond)),
425            pass: Box::new(self.fold_block(*pass)),
426            fail: self.fold_else(fail),
427        }
428    }
429    fn fold_else(&mut self, e: Else) -> Else {
430        let Else { body } = e;
431        Else { body: body.map(|e| Box::new(self.fold_expr(*e))) }
432    }
433    fn fold_break(&mut self, b: Break) -> Break {
434        let Break { body } = b;
435        Break { body: body.map(|e| Box::new(self.fold_expr(*e))) }
436    }
437    fn fold_return(&mut self, r: Return) -> Return {
438        let Return { body } = r;
439        Return { body: body.map(|e| Box::new(self.fold_expr(*e))) }
440    }
441}
442
443#[inline]
444/// Folds a [Literal] in the default way
445pub fn or_fold_literal<F: Fold + ?Sized>(folder: &mut F, lit: Literal) -> Literal {
446    match lit {
447        Literal::Bool(b) => Literal::Bool(folder.fold_bool(b)),
448        Literal::Char(c) => Literal::Char(folder.fold_char(c)),
449        Literal::Int(i) => Literal::Int(folder.fold_int(i)),
450        Literal::Float(f) => Literal::Float(folder.fold_smuggled_float(f)),
451        Literal::String(s) => Literal::String(folder.fold_string(s)),
452    }
453}
454
455#[inline]
456/// Folds a [MetaKind] in the default way
457pub fn or_fold_meta_kind<F: Fold + ?Sized>(folder: &mut F, kind: MetaKind) -> MetaKind {
458    match kind {
459        MetaKind::Plain => MetaKind::Plain,
460        MetaKind::Equals(l) => MetaKind::Equals(folder.fold_literal(l)),
461        MetaKind::Func(lits) => {
462            MetaKind::Func(lits.into_iter().map(|l| folder.fold_literal(l)).collect())
463        }
464    }
465}
466
467#[inline]
468/// Folds an [ItemKind] in the default way
469pub fn or_fold_item_kind<F: Fold + ?Sized>(folder: &mut F, kind: ItemKind) -> ItemKind {
470    match kind {
471        ItemKind::Module(m) => ItemKind::Module(folder.fold_module(m)),
472        ItemKind::Alias(a) => ItemKind::Alias(folder.fold_alias(a)),
473        ItemKind::Enum(e) => ItemKind::Enum(folder.fold_enum(e)),
474        ItemKind::Struct(s) => ItemKind::Struct(folder.fold_struct(s)),
475        ItemKind::Const(c) => ItemKind::Const(folder.fold_const(c)),
476        ItemKind::Static(s) => ItemKind::Static(folder.fold_static(s)),
477        ItemKind::Function(f) => ItemKind::Function(folder.fold_function(f)),
478        ItemKind::Impl(i) => ItemKind::Impl(folder.fold_impl(i)),
479        ItemKind::Use(u) => ItemKind::Use(folder.fold_use(u)),
480    }
481}
482
483#[inline]
484/// Folds a [StructKind] in the default way
485pub fn or_fold_struct_kind<F: Fold + ?Sized>(folder: &mut F, kind: StructKind) -> StructKind {
486    match kind {
487        StructKind::Empty => StructKind::Empty,
488        StructKind::Tuple(tys) => {
489            StructKind::Tuple(tys.into_iter().map(|t| folder.fold_ty(t)).collect())
490        }
491        StructKind::Struct(mem) => StructKind::Struct(
492            mem.into_iter()
493                .map(|m| folder.fold_struct_member(m))
494                .collect(),
495        ),
496    }
497}
498
499#[inline]
500/// Folds an [ImplKind] in the default way
501pub fn or_fold_impl_kind<F: Fold + ?Sized>(folder: &mut F, kind: ImplKind) -> ImplKind {
502    match kind {
503        ImplKind::Type(t) => ImplKind::Type(folder.fold_ty(t)),
504        ImplKind::Trait { impl_trait, for_type } => ImplKind::Trait {
505            impl_trait: folder.fold_path(impl_trait),
506            for_type: Box::new(folder.fold_ty(*for_type)),
507        },
508    }
509}
510
511#[inline]
512pub fn or_fold_use_tree<F: Fold + ?Sized>(folder: &mut F, tree: UseTree) -> UseTree {
513    match tree {
514        UseTree::Tree(tree) => UseTree::Tree(
515            tree.into_iter()
516                .map(|tree| folder.fold_use_tree(tree))
517                .collect(),
518        ),
519        UseTree::Path(path, rest) => UseTree::Path(
520            folder.fold_path_part(path),
521            Box::new(folder.fold_use_tree(*rest)),
522        ),
523        UseTree::Alias(path, name) => UseTree::Alias(folder.fold_sym(path), folder.fold_sym(name)),
524        UseTree::Name(name) => UseTree::Name(folder.fold_sym(name)),
525        UseTree::Glob => UseTree::Glob,
526    }
527}
528
529#[inline]
530/// Folds a [TyKind] in the default way
531pub fn or_fold_ty_kind<F: Fold + ?Sized>(folder: &mut F, kind: TyKind) -> TyKind {
532    match kind {
533        TyKind::Never => TyKind::Never,
534        TyKind::Infer => TyKind::Infer,
535        TyKind::Path(p) => TyKind::Path(folder.fold_path(p)),
536        TyKind::Array(a) => TyKind::Array(folder.fold_ty_array(a)),
537        TyKind::Slice(s) => TyKind::Slice(folder.fold_ty_slice(s)),
538        TyKind::Tuple(t) => TyKind::Tuple(folder.fold_ty_tuple(t)),
539        TyKind::Ref(t) => TyKind::Ref(folder.fold_ty_ref(t)),
540        TyKind::Ptr(t) => TyKind::Ptr(folder.fold_ty_ptr(t)),
541        TyKind::Fn(t) => TyKind::Fn(folder.fold_ty_fn(t)),
542    }
543}
544
545#[inline]
546/// Folds a [StmtKind] in the default way
547pub fn or_fold_stmt_kind<F: Fold + ?Sized>(folder: &mut F, kind: StmtKind) -> StmtKind {
548    match kind {
549        StmtKind::Empty => StmtKind::Empty,
550        StmtKind::Item(i) => StmtKind::Item(Box::new(folder.fold_item(*i))),
551        StmtKind::Expr(e) => StmtKind::Expr(Box::new(folder.fold_expr(*e))),
552    }
553}
554#[inline]
555/// Folds an [ExprKind] in the default way
556pub fn or_fold_expr_kind<F: Fold + ?Sized>(folder: &mut F, kind: ExprKind) -> ExprKind {
557    match kind {
558        ExprKind::Empty => ExprKind::Empty,
559        ExprKind::Closure(c) => ExprKind::Closure(folder.fold_closure(c)),
560        ExprKind::Quote(q) => ExprKind::Quote(q), // quoted expressions are left unmodified
561        ExprKind::Let(l) => ExprKind::Let(folder.fold_let(l)),
562        ExprKind::Match(m) => ExprKind::Match(folder.fold_match(m)),
563        ExprKind::Assign(a) => ExprKind::Assign(folder.fold_assign(a)),
564        ExprKind::Modify(m) => ExprKind::Modify(folder.fold_modify(m)),
565        ExprKind::Binary(b) => ExprKind::Binary(folder.fold_binary(b)),
566        ExprKind::Unary(u) => ExprKind::Unary(folder.fold_unary(u)),
567        ExprKind::Cast(c) => ExprKind::Cast(folder.fold_cast(c)),
568        ExprKind::Member(m) => ExprKind::Member(folder.fold_member(m)),
569        ExprKind::Index(i) => ExprKind::Index(folder.fold_index(i)),
570        ExprKind::Structor(s) => ExprKind::Structor(folder.fold_structor(s)),
571        ExprKind::Path(p) => ExprKind::Path(folder.fold_path(p)),
572        ExprKind::Literal(l) => ExprKind::Literal(folder.fold_literal(l)),
573        ExprKind::Array(a) => ExprKind::Array(folder.fold_array(a)),
574        ExprKind::ArrayRep(a) => ExprKind::ArrayRep(folder.fold_array_rep(a)),
575        ExprKind::AddrOf(a) => ExprKind::AddrOf(folder.fold_addrof(a)),
576        ExprKind::Block(b) => ExprKind::Block(folder.fold_block(b)),
577        ExprKind::Group(g) => ExprKind::Group(folder.fold_group(g)),
578        ExprKind::Tuple(t) => ExprKind::Tuple(folder.fold_tuple(t)),
579        ExprKind::While(w) => ExprKind::While(folder.fold_while(w)),
580        ExprKind::If(i) => ExprKind::If(folder.fold_if(i)),
581        ExprKind::For(f) => ExprKind::For(folder.fold_for(f)),
582        ExprKind::Break(b) => ExprKind::Break(folder.fold_break(b)),
583        ExprKind::Return(r) => ExprKind::Return(folder.fold_return(r)),
584        ExprKind::Continue => ExprKind::Continue,
585    }
586}
587pub fn or_fold_member_kind<F: Fold + ?Sized>(folder: &mut F, kind: MemberKind) -> MemberKind {
588    match kind {
589        MemberKind::Call(name, args) => {
590            MemberKind::Call(folder.fold_sym(name), folder.fold_tuple(args))
591        }
592        MemberKind::Struct(name) => MemberKind::Struct(folder.fold_sym(name)),
593        MemberKind::Tuple(name) => MemberKind::Tuple(folder.fold_literal(name)),
594    }
595}