diff --git a/crates/ruff/src/checkers/ast/mod.rs b/crates/ruff/src/checkers/ast/mod.rs index 631744bb29..23ceea36b5 100644 --- a/crates/ruff/src/checkers/ast/mod.rs +++ b/crates/ruff/src/checkers/ast/mod.rs @@ -1571,14 +1571,14 @@ where test, body, orelse, - self.ctx.current_stmt_parent().map(Into::into), + self.ctx.current_stmt_parent(), ); } if self.settings.rules.enabled(Rule::IfWithSameArms) { flake8_simplify::rules::if_with_same_arms( self, stmt, - self.ctx.current_stmt_parent().map(Into::into), + self.ctx.current_stmt_parent(), ); } if self.settings.rules.enabled(Rule::NeedlessBool) { @@ -1595,14 +1595,14 @@ where test, body, orelse, - self.ctx.current_stmt_parent().map(Into::into), + self.ctx.current_stmt_parent(), ); } if self.settings.rules.enabled(Rule::IfElseBlockInsteadOfIfExp) { flake8_simplify::rules::use_ternary_operator( self, stmt, - self.ctx.current_stmt_parent().map(Into::into), + self.ctx.current_stmt_parent(), ); } if self @@ -1616,7 +1616,7 @@ where test, body, orelse, - self.ctx.current_stmt_parent().map(Into::into), + self.ctx.current_stmt_parent(), ); } if self.settings.rules.enabled(Rule::TypeCheckWithoutTypeError) { @@ -1625,7 +1625,7 @@ where body, test, orelse, - self.ctx.current_stmt_parent().map(Into::into), + self.ctx.current_stmt_parent(), ); } if self.settings.rules.enabled(Rule::OutdatedVersionBlock) { @@ -1683,7 +1683,7 @@ where self, stmt, body, - self.ctx.current_stmt_parent().map(Into::into), + self.ctx.current_stmt_parent(), ); } if self.settings.rules.enabled(Rule::RedefinedLoopName) { @@ -2734,7 +2734,7 @@ where flake8_comprehensions::rules::unnecessary_generator_set( self, expr, - self.ctx.current_expr_parent().map(Into::into), + self.ctx.current_expr_parent(), func, args, keywords, @@ -2744,7 +2744,7 @@ where flake8_comprehensions::rules::unnecessary_generator_dict( self, expr, - self.ctx.current_expr_parent().map(Into::into), + self.ctx.current_expr_parent(), func, args, keywords, @@ -2849,7 +2849,7 @@ where flake8_comprehensions::rules::unnecessary_map( self, expr, - self.ctx.current_expr_parent().map(Into::into), + self.ctx.current_expr_parent(), func, args, ); diff --git a/crates/ruff_python_semantic/src/context.rs b/crates/ruff_python_semantic/src/context.rs index 912de79e43..9212dcbd68 100644 --- a/crates/ruff_python_semantic/src/context.rs +++ b/crates/ruff_python_semantic/src/context.rs @@ -6,7 +6,6 @@ use smallvec::smallvec; use ruff_python_ast::call_path::{collect_call_path, from_unqualified_name, CallPath}; use ruff_python_ast::helpers::from_relative_import; -use ruff_python_ast::types::RefEquality; use ruff_python_ast::typing::AnnotationKind; use ruff_python_stdlib::path::is_python_stub_file; use ruff_python_stdlib::typing::TYPING_EXTENSIONS; @@ -35,7 +34,7 @@ pub struct Context<'a> { // Map from binding index to indexes of bindings that shadow it in other scopes. pub shadowed_bindings: std::collections::HashMap, BuildNoHashHasher>, - pub exprs: Vec>, + pub exprs: Vec<&'a Expr>, // Body iteration; used to peek at siblings. pub body: &'a [Stmt], pub body_index: usize, @@ -313,7 +312,7 @@ impl<'a> Context<'a> { } pub fn push_expr(&mut self, expr: &'a Expr) { - self.exprs.push(RefEquality(expr)); + self.exprs.push(expr); } pub fn pop_expr(&mut self) { @@ -350,17 +349,17 @@ impl<'a> Context<'a> { } /// Return the parent `Expr` of the current `Expr`. - pub fn current_expr_parent(&self) -> Option<&RefEquality<'a, Expr>> { - self.exprs.iter().rev().nth(1) + pub fn current_expr_parent(&self) -> Option<&'a Expr> { + self.exprs.iter().rev().nth(1).copied() } /// Return the grandparent `Expr` of the current `Expr`. - pub fn current_expr_grandparent(&self) -> Option<&RefEquality<'a, Expr>> { - self.exprs.iter().rev().nth(2) + pub fn current_expr_grandparent(&self) -> Option<&'a Expr> { + self.exprs.iter().rev().nth(2).copied() } /// Return an [`Iterator`] over the current `Expr` parents. - pub fn expr_ancestors(&self) -> impl Iterator> { + pub fn expr_ancestors(&self) -> impl Iterator { self.exprs.iter().rev().skip(1) }