diff --git a/crates/ruff_linter/src/checkers/ast/analyze/deferred_lambdas.rs b/crates/ruff_linter/src/checkers/ast/analyze/deferred_lambdas.rs index d1ccf9f055a2a..e3dffc3ad3874 100644 --- a/crates/ruff_linter/src/checkers/ast/analyze/deferred_lambdas.rs +++ b/crates/ruff_linter/src/checkers/ast/analyze/deferred_lambdas.rs @@ -2,7 +2,7 @@ use ruff_python_ast::Expr; use crate::checkers::ast::Checker; use crate::codes::Rule; -use crate::rules::pylint; +use crate::rules::{flake8_pie, pylint}; /// Run lint rules over all deferred lambdas in the [`SemanticModel`]. pub(crate) fn deferred_lambdas(checker: &mut Checker) { @@ -18,6 +18,9 @@ pub(crate) fn deferred_lambdas(checker: &mut Checker) { if checker.enabled(Rule::UnnecessaryLambda) { pylint::rules::unnecessary_lambda(checker, lambda); } + if checker.enabled(Rule::ReimplementedListBuiltin) { + flake8_pie::rules::reimplemented_list_builtin(checker, lambda); + } } } } diff --git a/crates/ruff_linter/src/checkers/ast/analyze/expression.rs b/crates/ruff_linter/src/checkers/ast/analyze/expression.rs index a686c2c1b6678..81cf642aee29a 100644 --- a/crates/ruff_linter/src/checkers/ast/analyze/expression.rs +++ b/crates/ruff_linter/src/checkers/ast/analyze/expression.rs @@ -1267,17 +1267,6 @@ pub(crate) fn expression(expr: &Expr, checker: &mut Checker) { } } } - Expr::Lambda( - lambda @ ast::ExprLambda { - parameters: _, - body: _, - range: _, - }, - ) => { - if checker.enabled(Rule::ReimplementedListBuiltin) { - flake8_pie::rules::reimplemented_list_builtin(checker, lambda); - } - } Expr::IfExp(ast::ExprIfExp { test, body, diff --git a/crates/ruff_linter/src/checkers/ast/mod.rs b/crates/ruff_linter/src/checkers/ast/mod.rs index 2ff7bad73c09e..2905820fa6590 100644 --- a/crates/ruff_linter/src/checkers/ast/mod.rs +++ b/crates/ruff_linter/src/checkers/ast/mod.rs @@ -1834,15 +1834,15 @@ impl<'a> Checker<'a> { for snapshot in deferred_functions { self.semantic.restore(snapshot); - if let Stmt::FunctionDef(ast::StmtFunctionDef { + let Stmt::FunctionDef(ast::StmtFunctionDef { body, parameters, .. }) = self.semantic.current_statement() - { - self.visit_parameters(parameters); - self.visit_body(body); - } else { + else { unreachable!("Expected Stmt::FunctionDef") - } + }; + + self.visit_parameters(parameters); + self.visit_body(body); } } self.semantic.restore(snapshot); @@ -1856,19 +1856,19 @@ impl<'a> Checker<'a> { for snapshot in lambdas { self.semantic.restore(snapshot); - if let Some(Expr::Lambda(ast::ExprLambda { + let Some(Expr::Lambda(ast::ExprLambda { parameters, body, range: _, })) = self.semantic.current_expression() - { - if let Some(parameters) = parameters { - self.visit_parameters(parameters); - } - self.visit_expr(body); - } else { + else { unreachable!("Expected Expr::Lambda"); + }; + + if let Some(parameters) = parameters { + self.visit_parameters(parameters); } + self.visit_expr(body); deferred.push(snapshot); }