Skip to main content

ruff_python_ast/
visitor.rs

1//! AST visitor trait and walk functions.
2
3pub mod source_order;
4pub mod transformer;
5
6use crate::{
7    self as ast, Alias, AnyParameterRef, Arguments, BoolOp, BytesLiteral, CmpOp, Comprehension,
8    Decorator, ElifElseClause, ExceptHandler, Expr, ExprContext, FString, FStringPart,
9    InterpolatedStringElement, Keyword, MatchCase, Operator, Parameter, Parameters, Pattern,
10    PatternArguments, PatternKeyword, Stmt, StringLiteral, TString, TypeParam, TypeParamParamSpec,
11    TypeParamTypeVar, TypeParamTypeVarTuple, TypeParams, UnaryOp, WithItem,
12};
13
14/// A trait for AST visitors. Visits all nodes in the AST recursively in evaluation-order.
15///
16/// Prefer [`crate::statement_visitor::StatementVisitor`] for visitors that only need to visit
17/// statements.
18///
19/// Use the [`PreorderVisitor`](source_order::SourceOrderVisitor) if you want to visit the nodes
20/// in source-order rather than evaluation order.
21///
22/// Use the [`Transformer`](transformer::Transformer) if you want to modify the nodes.
23pub trait Visitor<'a> {
24    fn visit_stmt(&mut self, stmt: &'a Stmt) {
25        walk_stmt(self, stmt);
26    }
27    fn visit_annotation(&mut self, expr: &'a Expr) {
28        walk_annotation(self, expr);
29    }
30    fn visit_decorator(&mut self, decorator: &'a Decorator) {
31        walk_decorator(self, decorator);
32    }
33    fn visit_expr(&mut self, expr: &'a Expr) {
34        walk_expr(self, expr);
35    }
36    fn visit_expr_context(&mut self, expr_context: &'a ExprContext) {
37        walk_expr_context(self, expr_context);
38    }
39    fn visit_bool_op(&mut self, bool_op: &'a BoolOp) {
40        walk_bool_op(self, bool_op);
41    }
42    fn visit_operator(&mut self, operator: &'a Operator) {
43        walk_operator(self, operator);
44    }
45    fn visit_unary_op(&mut self, unary_op: &'a UnaryOp) {
46        walk_unary_op(self, unary_op);
47    }
48    fn visit_cmp_op(&mut self, cmp_op: &'a CmpOp) {
49        walk_cmp_op(self, cmp_op);
50    }
51    fn visit_comprehension(&mut self, comprehension: &'a Comprehension) {
52        walk_comprehension(self, comprehension);
53    }
54    fn visit_except_handler(&mut self, except_handler: &'a ExceptHandler) {
55        walk_except_handler(self, except_handler);
56    }
57    fn visit_arguments(&mut self, arguments: &'a Arguments) {
58        walk_arguments(self, arguments);
59    }
60    fn visit_parameters(&mut self, parameters: &'a Parameters) {
61        walk_parameters(self, parameters);
62    }
63    fn visit_parameter(&mut self, parameter: &'a Parameter) {
64        walk_parameter(self, parameter);
65    }
66    fn visit_keyword(&mut self, keyword: &'a Keyword) {
67        walk_keyword(self, keyword);
68    }
69    fn visit_alias(&mut self, alias: &'a Alias) {
70        walk_alias(self, alias);
71    }
72    fn visit_with_item(&mut self, with_item: &'a WithItem) {
73        walk_with_item(self, with_item);
74    }
75    fn visit_type_params(&mut self, type_params: &'a TypeParams) {
76        walk_type_params(self, type_params);
77    }
78    fn visit_type_param(&mut self, type_param: &'a TypeParam) {
79        walk_type_param(self, type_param);
80    }
81    fn visit_match_case(&mut self, match_case: &'a MatchCase) {
82        walk_match_case(self, match_case);
83    }
84    fn visit_pattern(&mut self, pattern: &'a Pattern) {
85        walk_pattern(self, pattern);
86    }
87    fn visit_pattern_arguments(&mut self, pattern_arguments: &'a PatternArguments) {
88        walk_pattern_arguments(self, pattern_arguments);
89    }
90    fn visit_pattern_keyword(&mut self, pattern_keyword: &'a PatternKeyword) {
91        walk_pattern_keyword(self, pattern_keyword);
92    }
93    fn visit_body(&mut self, body: &'a [Stmt]) {
94        walk_body(self, body);
95    }
96    fn visit_elif_else_clause(&mut self, elif_else_clause: &'a ElifElseClause) {
97        walk_elif_else_clause(self, elif_else_clause);
98    }
99    fn visit_f_string(&mut self, f_string: &'a FString) {
100        walk_f_string(self, f_string);
101    }
102    fn visit_interpolated_string_element(
103        &mut self,
104        interpolated_string_element: &'a InterpolatedStringElement,
105    ) {
106        walk_interpolated_string_element(self, interpolated_string_element);
107    }
108    fn visit_t_string(&mut self, t_string: &'a TString) {
109        walk_t_string(self, t_string);
110    }
111    fn visit_string_literal(&mut self, string_literal: &'a StringLiteral) {
112        walk_string_literal(self, string_literal);
113    }
114    fn visit_bytes_literal(&mut self, bytes_literal: &'a BytesLiteral) {
115        walk_bytes_literal(self, bytes_literal);
116    }
117}
118
119pub fn walk_body<'a, V: Visitor<'a> + ?Sized>(visitor: &mut V, body: &'a [Stmt]) {
120    for stmt in body {
121        visitor.visit_stmt(stmt);
122    }
123}
124
125pub fn walk_elif_else_clause<'a, V: Visitor<'a> + ?Sized>(
126    visitor: &mut V,
127    elif_else_clause: &'a ElifElseClause,
128) {
129    if let Some(test) = &elif_else_clause.test {
130        visitor.visit_expr(test);
131    }
132    visitor.visit_body(&elif_else_clause.body);
133}
134
135pub fn walk_stmt<'a, V: Visitor<'a> + ?Sized>(visitor: &mut V, stmt: &'a Stmt) {
136    match stmt {
137        Stmt::FunctionDef(ast::StmtFunctionDef {
138            parameters,
139            body,
140            decorator_list,
141            returns,
142            type_params,
143            ..
144        }) => {
145            for decorator in decorator_list {
146                visitor.visit_decorator(decorator);
147            }
148            if let Some(type_params) = type_params {
149                visitor.visit_type_params(type_params);
150            }
151            visitor.visit_parameters(parameters);
152            if let Some(expr) = returns {
153                visitor.visit_annotation(expr);
154            }
155            visitor.visit_body(body);
156        }
157        Stmt::ClassDef(ast::StmtClassDef {
158            arguments,
159            body,
160            decorator_list,
161            type_params,
162            ..
163        }) => {
164            for decorator in decorator_list {
165                visitor.visit_decorator(decorator);
166            }
167            if let Some(type_params) = type_params {
168                visitor.visit_type_params(type_params);
169            }
170            if let Some(arguments) = arguments {
171                visitor.visit_arguments(arguments);
172            }
173            visitor.visit_body(body);
174        }
175        Stmt::Return(ast::StmtReturn { value, .. }) => {
176            if let Some(expr) = value {
177                visitor.visit_expr(expr);
178            }
179        }
180        Stmt::Delete(ast::StmtDelete { targets, .. }) => {
181            for expr in targets {
182                visitor.visit_expr(expr);
183            }
184        }
185        Stmt::TypeAlias(ast::StmtTypeAlias {
186            range: _,
187            node_index: _,
188            name,
189            type_params,
190            value,
191        }) => {
192            visitor.visit_expr(value);
193            if let Some(type_params) = type_params {
194                visitor.visit_type_params(type_params);
195            }
196            visitor.visit_expr(name);
197        }
198        Stmt::Assign(ast::StmtAssign { targets, value, .. }) => {
199            visitor.visit_expr(value);
200            for expr in targets {
201                visitor.visit_expr(expr);
202            }
203        }
204        Stmt::AugAssign(ast::StmtAugAssign {
205            target, op, value, ..
206        }) => {
207            visitor.visit_expr(value);
208            visitor.visit_operator(op);
209            visitor.visit_expr(target);
210        }
211        Stmt::AnnAssign(ast::StmtAnnAssign {
212            target,
213            annotation,
214            value,
215            ..
216        }) => {
217            if let Some(expr) = value {
218                visitor.visit_expr(expr);
219            }
220            visitor.visit_annotation(annotation);
221            visitor.visit_expr(target);
222        }
223        Stmt::For(ast::StmtFor {
224            target,
225            iter,
226            body,
227            orelse,
228            ..
229        }) => {
230            visitor.visit_expr(iter);
231            visitor.visit_expr(target);
232            visitor.visit_body(body);
233            visitor.visit_body(orelse);
234        }
235        Stmt::While(ast::StmtWhile {
236            test, body, orelse, ..
237        }) => {
238            visitor.visit_expr(test);
239            visitor.visit_body(body);
240            visitor.visit_body(orelse);
241        }
242        Stmt::If(ast::StmtIf {
243            test,
244            body,
245            elif_else_clauses,
246            ..
247        }) => {
248            visitor.visit_expr(test);
249            visitor.visit_body(body);
250            for clause in elif_else_clauses {
251                visitor.visit_elif_else_clause(clause);
252            }
253        }
254        Stmt::With(ast::StmtWith { items, body, .. }) => {
255            for with_item in items {
256                visitor.visit_with_item(with_item);
257            }
258            visitor.visit_body(body);
259        }
260        Stmt::Match(ast::StmtMatch { subject, cases, .. }) => {
261            visitor.visit_expr(subject);
262            for match_case in cases {
263                visitor.visit_match_case(match_case);
264            }
265        }
266        Stmt::Raise(ast::StmtRaise { exc, cause, .. }) => {
267            if let Some(expr) = exc {
268                visitor.visit_expr(expr);
269            }
270            if let Some(expr) = cause {
271                visitor.visit_expr(expr);
272            }
273        }
274        Stmt::Try(ast::StmtTry {
275            body,
276            handlers,
277            orelse,
278            finalbody,
279            ..
280        }) => {
281            visitor.visit_body(body);
282            for except_handler in handlers {
283                visitor.visit_except_handler(except_handler);
284            }
285            visitor.visit_body(orelse);
286            visitor.visit_body(finalbody);
287        }
288        Stmt::Assert(ast::StmtAssert { test, msg, .. }) => {
289            visitor.visit_expr(test);
290            if let Some(expr) = msg {
291                visitor.visit_expr(expr);
292            }
293        }
294        Stmt::Import(ast::StmtImport { names, .. }) => {
295            for alias in names {
296                visitor.visit_alias(alias);
297            }
298        }
299        Stmt::ImportFrom(ast::StmtImportFrom { names, .. }) => {
300            for alias in names {
301                visitor.visit_alias(alias);
302            }
303        }
304        Stmt::Global(_) => {}
305        Stmt::Nonlocal(_) => {}
306        Stmt::Expr(ast::StmtExpr { value, .. }) => visitor.visit_expr(value),
307        Stmt::Pass(_) | Stmt::Break(_) | Stmt::Continue(_) | Stmt::IpyEscapeCommand(_) => {}
308    }
309}
310
311pub fn walk_annotation<'a, V: Visitor<'a> + ?Sized>(visitor: &mut V, expr: &'a Expr) {
312    visitor.visit_expr(expr);
313}
314
315pub fn walk_decorator<'a, V: Visitor<'a> + ?Sized>(visitor: &mut V, decorator: &'a Decorator) {
316    visitor.visit_expr(&decorator.expression);
317}
318
319pub fn walk_expr<'a, V: Visitor<'a> + ?Sized>(visitor: &mut V, expr: &'a Expr) {
320    match expr {
321        Expr::BoolOp(ast::ExprBoolOp { op, values, .. }) => {
322            visitor.visit_bool_op(op);
323            for expr in values {
324                visitor.visit_expr(expr);
325            }
326        }
327        Expr::Named(ast::ExprNamed { target, value, .. }) => {
328            visitor.visit_expr(value);
329            visitor.visit_expr(target);
330        }
331        Expr::BinOp(ast::ExprBinOp {
332            left, op, right, ..
333        }) => {
334            visitor.visit_expr(left);
335            visitor.visit_operator(op);
336            visitor.visit_expr(right);
337        }
338        Expr::UnaryOp(ast::ExprUnaryOp { op, operand, .. }) => {
339            visitor.visit_unary_op(op);
340            visitor.visit_expr(operand);
341        }
342        Expr::Lambda(ast::ExprLambda {
343            parameters, body, ..
344        }) => {
345            if let Some(parameters) = parameters {
346                visitor.visit_parameters(parameters);
347            }
348            visitor.visit_expr(body);
349        }
350        Expr::If(ast::ExprIf {
351            test, body, orelse, ..
352        }) => {
353            visitor.visit_expr(test);
354            visitor.visit_expr(body);
355            visitor.visit_expr(orelse);
356        }
357        Expr::Dict(ast::ExprDict { items, .. }) => {
358            for ast::DictItem { key, value } in items {
359                if let Some(key) = key {
360                    visitor.visit_expr(key);
361                }
362                visitor.visit_expr(value);
363            }
364        }
365        Expr::Set(ast::ExprSet { elts, .. }) => {
366            for expr in elts {
367                visitor.visit_expr(expr);
368            }
369        }
370        Expr::ListComp(ast::ExprListComp {
371            elt, generators, ..
372        }) => {
373            for comprehension in generators {
374                visitor.visit_comprehension(comprehension);
375            }
376            visitor.visit_expr(elt);
377        }
378        Expr::SetComp(ast::ExprSetComp {
379            elt, generators, ..
380        }) => {
381            for comprehension in generators {
382                visitor.visit_comprehension(comprehension);
383            }
384            visitor.visit_expr(elt);
385        }
386        Expr::DictComp(ast::ExprDictComp {
387            key,
388            value,
389            generators,
390            ..
391        }) => {
392            for comprehension in generators {
393                visitor.visit_comprehension(comprehension);
394            }
395            if let Some(key) = key {
396                visitor.visit_expr(key);
397            }
398            visitor.visit_expr(value);
399        }
400        Expr::Generator(ast::ExprGenerator {
401            elt, generators, ..
402        }) => {
403            for comprehension in generators {
404                visitor.visit_comprehension(comprehension);
405            }
406            visitor.visit_expr(elt);
407        }
408        Expr::Await(ast::ExprAwait { value, .. }) => visitor.visit_expr(value),
409        Expr::Yield(ast::ExprYield { value, .. }) => {
410            if let Some(expr) = value {
411                visitor.visit_expr(expr);
412            }
413        }
414        Expr::YieldFrom(ast::ExprYieldFrom { value, .. }) => visitor.visit_expr(value),
415        Expr::Compare(ast::ExprCompare {
416            left,
417            ops,
418            comparators,
419            ..
420        }) => {
421            visitor.visit_expr(left);
422            for cmp_op in ops {
423                visitor.visit_cmp_op(cmp_op);
424            }
425            for expr in comparators {
426                visitor.visit_expr(expr);
427            }
428        }
429        Expr::Call(ast::ExprCall {
430            func, arguments, ..
431        }) => {
432            visitor.visit_expr(func);
433            visitor.visit_arguments(arguments);
434        }
435        Expr::FString(ast::ExprFString { value, .. }) => {
436            for part in value {
437                match part {
438                    FStringPart::Literal(string_literal) => {
439                        visitor.visit_string_literal(string_literal);
440                    }
441                    FStringPart::FString(f_string) => visitor.visit_f_string(f_string),
442                }
443            }
444        }
445        Expr::TString(ast::ExprTString { value, .. }) => {
446            for t_string in value {
447                visitor.visit_t_string(t_string);
448            }
449        }
450        Expr::StringLiteral(ast::ExprStringLiteral { value, .. }) => {
451            for string_literal in value {
452                visitor.visit_string_literal(string_literal);
453            }
454        }
455        Expr::BytesLiteral(ast::ExprBytesLiteral { value, .. }) => {
456            for bytes_literal in value {
457                visitor.visit_bytes_literal(bytes_literal);
458            }
459        }
460        Expr::NumberLiteral(_)
461        | Expr::Constant(_)
462        | Expr::BooleanLiteral(_)
463        | Expr::NoneLiteral(_)
464        | Expr::EllipsisLiteral(_) => {}
465        Expr::Attribute(ast::ExprAttribute { value, ctx, .. }) => {
466            visitor.visit_expr(value);
467            visitor.visit_expr_context(ctx);
468        }
469        Expr::Subscript(ast::ExprSubscript {
470            value, slice, ctx, ..
471        }) => {
472            visitor.visit_expr(value);
473            visitor.visit_expr(slice);
474            visitor.visit_expr_context(ctx);
475        }
476        Expr::Starred(ast::ExprStarred { value, ctx, .. }) => {
477            visitor.visit_expr(value);
478            visitor.visit_expr_context(ctx);
479        }
480        Expr::Name(ast::ExprName { ctx, .. }) => {
481            visitor.visit_expr_context(ctx);
482        }
483        Expr::List(ast::ExprList { elts, ctx, .. }) => {
484            for expr in elts {
485                visitor.visit_expr(expr);
486            }
487            visitor.visit_expr_context(ctx);
488        }
489        Expr::Tuple(ast::ExprTuple { elts, ctx, .. }) => {
490            for expr in elts {
491                visitor.visit_expr(expr);
492            }
493            visitor.visit_expr_context(ctx);
494        }
495        Expr::Slice(ast::ExprSlice {
496            lower, upper, step, ..
497        }) => {
498            if let Some(expr) = lower {
499                visitor.visit_expr(expr);
500            }
501            if let Some(expr) = upper {
502                visitor.visit_expr(expr);
503            }
504            if let Some(expr) = step {
505                visitor.visit_expr(expr);
506            }
507        }
508        Expr::IpyEscapeCommand(_) => {}
509    }
510}
511
512pub fn walk_comprehension<'a, V: Visitor<'a> + ?Sized>(
513    visitor: &mut V,
514    comprehension: &'a Comprehension,
515) {
516    visitor.visit_expr(&comprehension.iter);
517    visitor.visit_expr(&comprehension.target);
518    for expr in &comprehension.ifs {
519        visitor.visit_expr(expr);
520    }
521}
522
523pub fn walk_except_handler<'a, V: Visitor<'a> + ?Sized>(
524    visitor: &mut V,
525    except_handler: &'a ExceptHandler,
526) {
527    match except_handler {
528        ExceptHandler::ExceptHandler(ast::ExceptHandlerExceptHandler { type_, body, .. }) => {
529            if let Some(expr) = type_ {
530                visitor.visit_expr(expr);
531            }
532            visitor.visit_body(body);
533        }
534    }
535}
536
537pub fn walk_arguments<'a, V: Visitor<'a> + ?Sized>(visitor: &mut V, arguments: &'a Arguments) {
538    // Note that there might be keywords before the last arg, e.g. in
539    // f(*args, a=2, *args2, **kwargs)`, but we follow Python in evaluating first `args` and then
540    // `keywords`. See also [Arguments::arguments_source_order`].
541    for arg in &*arguments.args {
542        visitor.visit_expr(arg);
543    }
544    for keyword in &*arguments.keywords {
545        visitor.visit_keyword(keyword);
546    }
547}
548
549pub fn walk_parameters<'a, V: Visitor<'a> + ?Sized>(visitor: &mut V, parameters: &'a Parameters) {
550    // Defaults are evaluated before annotations.
551    for default in parameters
552        .iter_non_variadic_params()
553        .filter_map(|param| param.default.as_deref())
554    {
555        visitor.visit_expr(default);
556    }
557
558    for parameter in parameters.iter().map(AnyParameterRef::as_parameter) {
559        visitor.visit_parameter(parameter);
560    }
561}
562
563pub fn walk_parameter<'a, V: Visitor<'a> + ?Sized>(visitor: &mut V, parameter: &'a Parameter) {
564    if let Some(expr) = &parameter.annotation {
565        visitor.visit_annotation(expr);
566    }
567}
568
569pub fn walk_keyword<'a, V: Visitor<'a> + ?Sized>(visitor: &mut V, keyword: &'a Keyword) {
570    visitor.visit_expr(&keyword.value);
571}
572
573pub fn walk_with_item<'a, V: Visitor<'a> + ?Sized>(visitor: &mut V, with_item: &'a WithItem) {
574    visitor.visit_expr(&with_item.context_expr);
575    if let Some(expr) = &with_item.optional_vars {
576        visitor.visit_expr(expr);
577    }
578}
579
580pub fn walk_type_params<'a, V: Visitor<'a> + ?Sized>(visitor: &mut V, type_params: &'a TypeParams) {
581    for type_param in &type_params.type_params {
582        visitor.visit_type_param(type_param);
583    }
584}
585
586pub fn walk_type_param<'a, V: Visitor<'a> + ?Sized>(visitor: &mut V, type_param: &'a TypeParam) {
587    match type_param {
588        TypeParam::TypeVar(TypeParamTypeVar { bound, default, .. }) => {
589            if let Some(expr) = bound {
590                visitor.visit_expr(expr);
591            }
592            if let Some(expr) = default {
593                visitor.visit_expr(expr);
594            }
595        }
596        TypeParam::TypeVarTuple(TypeParamTypeVarTuple { default, .. }) => {
597            if let Some(expr) = default {
598                visitor.visit_expr(expr);
599            }
600        }
601        TypeParam::ParamSpec(TypeParamParamSpec { default, .. }) => {
602            if let Some(expr) = default {
603                visitor.visit_expr(expr);
604            }
605        }
606    }
607}
608
609pub fn walk_match_case<'a, V: Visitor<'a> + ?Sized>(visitor: &mut V, match_case: &'a MatchCase) {
610    visitor.visit_pattern(&match_case.pattern);
611    if let Some(expr) = &match_case.guard {
612        visitor.visit_expr(expr);
613    }
614    visitor.visit_body(&match_case.body);
615}
616
617pub fn walk_pattern<'a, V: Visitor<'a> + ?Sized>(visitor: &mut V, pattern: &'a Pattern) {
618    match pattern {
619        Pattern::MatchValue(ast::PatternMatchValue { value, .. }) => {
620            visitor.visit_expr(value);
621        }
622        Pattern::MatchSingleton(_) => {}
623        Pattern::MatchSequence(ast::PatternMatchSequence { patterns, .. }) => {
624            for pattern in patterns {
625                visitor.visit_pattern(pattern);
626            }
627        }
628        Pattern::MatchMapping(ast::PatternMatchMapping { keys, patterns, .. }) => {
629            for expr in keys {
630                visitor.visit_expr(expr);
631            }
632            for pattern in patterns {
633                visitor.visit_pattern(pattern);
634            }
635        }
636        Pattern::MatchClass(ast::PatternMatchClass { cls, arguments, .. }) => {
637            visitor.visit_expr(cls);
638            visitor.visit_pattern_arguments(arguments);
639        }
640        Pattern::MatchStar(_) => {}
641        Pattern::MatchAs(ast::PatternMatchAs { pattern, .. }) => {
642            if let Some(pattern) = pattern {
643                visitor.visit_pattern(pattern);
644            }
645        }
646        Pattern::MatchOr(ast::PatternMatchOr { patterns, .. }) => {
647            for pattern in patterns {
648                visitor.visit_pattern(pattern);
649            }
650        }
651    }
652}
653
654pub fn walk_pattern_arguments<'a, V: Visitor<'a> + ?Sized>(
655    visitor: &mut V,
656    pattern_arguments: &'a PatternArguments,
657) {
658    for pattern in &pattern_arguments.patterns {
659        visitor.visit_pattern(pattern);
660    }
661    for keyword in &pattern_arguments.keywords {
662        visitor.visit_pattern_keyword(keyword);
663    }
664}
665
666pub fn walk_pattern_keyword<'a, V: Visitor<'a> + ?Sized>(
667    visitor: &mut V,
668    pattern_keyword: &'a PatternKeyword,
669) {
670    visitor.visit_pattern(&pattern_keyword.pattern);
671}
672
673pub fn walk_f_string<'a, V: Visitor<'a> + ?Sized>(visitor: &mut V, f_string: &'a FString) {
674    for interpolated_string_element in &f_string.elements {
675        visitor.visit_interpolated_string_element(interpolated_string_element);
676    }
677}
678
679pub fn walk_interpolated_string_element<'a, V: Visitor<'a> + ?Sized>(
680    visitor: &mut V,
681    interpolated_string_element: &'a InterpolatedStringElement,
682) {
683    if let ast::InterpolatedStringElement::Interpolation(ast::InterpolatedElement {
684        expression,
685        format_spec,
686        ..
687    }) = interpolated_string_element
688    {
689        visitor.visit_expr(expression);
690        if let Some(format_spec) = format_spec {
691            for spec_element in &format_spec.elements {
692                visitor.visit_interpolated_string_element(spec_element);
693            }
694        }
695    }
696}
697
698pub fn walk_t_string<'a, V: Visitor<'a> + ?Sized>(visitor: &mut V, t_string: &'a TString) {
699    for t_string_element in &t_string.elements {
700        visitor.visit_interpolated_string_element(t_string_element);
701    }
702}
703
704pub fn walk_expr_context<'a, V: Visitor<'a> + ?Sized>(
705    _visitor: &V,
706    _expr_context: &'a ExprContext,
707) {
708}
709
710pub fn walk_bool_op<'a, V: Visitor<'a> + ?Sized>(_visitor: &V, _bool_op: &'a BoolOp) {}
711
712pub fn walk_operator<'a, V: Visitor<'a> + ?Sized>(_visitor: &V, _operator: &'a Operator) {}
713
714pub fn walk_unary_op<'a, V: Visitor<'a> + ?Sized>(_visitor: &V, _unary_op: &'a UnaryOp) {}
715
716pub fn walk_cmp_op<'a, V: Visitor<'a> + ?Sized>(_visitor: &V, _cmp_op: &'a CmpOp) {}
717
718pub fn walk_alias<'a, V: Visitor<'a> + ?Sized>(_visitor: &V, _alias: &'a Alias) {}
719
720pub fn walk_string_literal<'a, V: Visitor<'a> + ?Sized>(
721    _visitor: &V,
722    _string_literal: &'a StringLiteral,
723) {
724}
725
726pub fn walk_bytes_literal<'a, V: Visitor<'a> + ?Sized>(
727    _visitor: &V,
728    _bytes_literal: &'a BytesLiteral,
729) {
730}