diff --git a/crates/ruff/src/checkers/ast/mod.rs b/crates/ruff/src/checkers/ast/mod.rs index 5df7e9ae876a35..4cc48804c0fbb7 100644 --- a/crates/ruff/src/checkers/ast/mod.rs +++ b/crates/ruff/src/checkers/ast/mod.rs @@ -1584,7 +1584,9 @@ where } } if self.settings.rules.enabled(Rule::SelfAssigningVariable) { - pylint::rules::self_assigning_variable(self, targets, value); + if let [target] = targets.as_slice() { + pylint::rules::self_assigning_variable(self, target, value); + } } if self.settings.rules.enabled(Rule::TypeParamNameMismatch) { pylint::rules::type_param_name_mismatch(self, value, targets); @@ -1649,11 +1651,7 @@ where ); } if self.enabled(Rule::SelfAssigningVariable) { - pylint::rules::self_assigning_variable( - self, - &[target.as_ref().clone()], - value, - ); + pylint::rules::self_assigning_variable(self, target, value); } } if self.enabled(Rule::UnintentionalTypeAnnotation) { diff --git a/crates/ruff/src/rules/pylint/rules/self_assigning_variable.rs b/crates/ruff/src/rules/pylint/rules/self_assigning_variable.rs index 59427f20d94cf9..0bc7de1c811311 100644 --- a/crates/ruff/src/rules/pylint/rules/self_assigning_variable.rs +++ b/crates/ruff/src/rules/pylint/rules/self_assigning_variable.rs @@ -35,17 +35,13 @@ impl Violation for SelfAssigningVariable { } /// PLW0127 -pub(crate) fn self_assigning_variable(checker: &mut Checker, targets: &[Expr], value: &Expr) { +pub(crate) fn self_assigning_variable(checker: &mut Checker, target: &Expr, value: &Expr) { // Assignments in class bodies are attributes (e.g., `x = x` assigns `x` to `self.x`, and thus // is not a self-assignment). if checker.semantic().scope().kind.is_class() { return; } - let [target] = targets else { - return; - }; - fn inner(left: &Expr, right: &Expr, diagnostics: &mut Vec) { match (left, right) { (