Repository: astral-sh/ruff
File: crates/ruff_linter/src/checkers/ast/mod.rs (Rust)

Code before:
            Expr::TString(_) => {
                self.semantic.flags |= SemanticModelFlags::T_STRING;
                visitor::walk_expr(self, expr);
            }
            Expr::Named(ast::ExprNamed {
                target,
                value,
                range: _,
                node_index: _,
            }) => {
                self.visit_expr(value);

                self.semantic.flags |= SemanticModelFlags::NAMED_EXPRESSION_ASSIGNMENT;
                self.visit_expr(target);
            }
            _ => visitor::walk_expr(self, expr),
        }

        // Unlike most comprehension checks (which run in `analyze::expression`, after scope pop),
        // PERF102 needs `is_unused()` which requires the generator scope to still be active.
        if self.is_rule_enabled(Rule::IncorrectDictIterator) {
            let generators = match expr {
                Expr::ListComp(comp) => comp.generators.as_slice(),
                Expr::SetComp(comp) => comp.generators.as_slice(),
                Expr::Generator(comp) => comp.generators.as_slice(),
                Expr::DictComp(comp) => comp.generators.as_slice(),
                _ => &[],
            };
            for generator in generators {
                perflint::rules::incorrect_dict_iterator_comprehension(self, generator);
            }
        }

        // Step 3: Clean-up
        match expr {
            Expr::Lambda(_)
            | Expr::Generator(_)
            | Expr::ListComp(_)
            | Expr::DictComp(_)
            | Expr::SetComp(_) => {
                self.analyze.scopes.push(self.semantic.scope_id);
                self.semantic.pop_scope(); // Lambda/Generator/Comprehension scope
            }
            _ => {}
        }

        // Step 4: Analysis
        match expr {
            Expr::StringLiteral(string_literal) => {
                analyze::string_like(string_literal.into(), self);
            }

Review comment (bug):
I'd typically reach for something more like this, but it doesn't seem any less verbose really, so I think what you have is also fine.

https://github.com/astral-sh/ruff/blob/f14edd8661e2803254f89265548c7487f47a09f6/crates/ruff_linter/src/rules/flake8_bugbear/rules/loop_variable_overrides_iterator.rs#L89-L92

Code after:
                visitor::walk_expr(self, expr);
            }
            Expr::TString(_) => {
                self.semantic.flags |= SemanticModelFlags::T_STRING;
                visitor::walk_expr(self, expr);
            }
            Expr::Named(ast::ExprNamed {
                target,
                value,
                range: _,
                node_index: _,
            }) => {
                self.visit_expr(value);

                self.semantic.flags |= SemanticModelFlags::NAMED_EXPRESSION_ASSIGNMENT;
                self.visit_expr(target);
            }
            _ => visitor::walk_expr(self, expr),
        }

        // Step 3: Clean-up
        match expr {
            Expr::Lambda(_)
            | Expr::Generator(_)
            | Expr::ListComp(_)
            | Expr::DictComp(_)
            | Expr::SetComp(_) => {
                self.analyze.scopes.push(self.semantic.scope_id);
                self.semantic.pop_scope(); // Lambda/Generator/Comprehension scope
            }
            _ => {}
        }

        // Step 4: Analysis
        match expr {
            Expr::StringLiteral(string_literal) => {
                analyze::string_like(string_literal.into(), self);
            }
            Expr::BytesLiteral(bytes_literal) => analyze::string_like(bytes_literal.into(), self),
            Expr::FString(f_string) => analyze::string_like(f_string.into(), self),
            Expr::TString(t_string) => analyze::string_like(t_string.into(), self),
            _ => {}
        }

        self.semantic.flags = flags_snapshot;
        analyze::expression(expr, self);
        self.semantic.pop_node();
    }

    fn visit_except_handler(&mut self, except_handler: &'a ExceptHandler) {
        let flags_snapshot = self.semantic.flags;