{"record":{"id":"d44c134a4dea6975","repo":"astral-sh/ruff","slug":"redefined-loop-name-called-on-statement-that-is-no","errorCode":null,"errorMessage":"redefined_loop_name called on Statement that is not a `With` or `For`","messagePattern":"redefined_loop_name called on Statement that is not a `With` or `For`","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/ruff_linter/src/rules/pylint/rules/redefined_loop_name.rs","lineNumber":408,"sourceCode":"        Stmt::For(ast::StmtFor { target, body, .. }) => {\n            let outer_assignment_targets: Vec<ExprWithOuterBindingKind> =\n                assignment_targets_from_expr(target, &checker.settings().dummy_variable_rgx)\n                    .map(|expr| ExprWithOuterBindingKind {\n                        expr,\n                        binding_kind: OuterBindingKind::For,\n                    })\n                    .collect();\n            let mut visitor = InnerForWithAssignTargetsVisitor {\n                context: checker.semantic(),\n                dummy_variable_rgx: &checker.settings().dummy_variable_rgx,\n                assignment_targets: vec![],\n            };\n            for stmt in body {\n                visitor.visit_stmt(stmt);\n            }\n            (outer_assignment_targets, visitor.assignment_targets)\n        }\n        _ => panic!(\"redefined_loop_name called on Statement that is not a `With` or `For`\"),\n    };\n\n    for outer_assignment_target in &outer_assignment_targets {\n        for inner_assignment_target in &inner_assignment_targets {\n            // Compare the targets structurally.\n            if ComparableExpr::from(outer_assignment_target.expr)\n                .eq(&(ComparableExpr::from(inner_assignment_target.expr)))\n            {\n                checker.report_diagnostic(\n                    RedefinedLoopName {\n                        name: checker.generator().expr(outer_assignment_target.expr),\n                        outer_kind: outer_assignment_target.binding_kind,\n                        inner_kind: inner_assignment_target.binding_kind,\n                    },\n                    inner_assignment_target.expr.range(),\n                );\n            }\n        }","sourceCodeStart":390,"sourceCodeEnd":426,"githubUrl":"https://github.com/astral-sh/ruff/blob/26f38c119cac42e4d320ba08f09224fdec74af2c/crates/ruff_linter/src/rules/pylint/rules/redefined_loop_name.rs#L390-L426","documentation":"An unreachable! in the redefined-loop-name rule: the function was invoked with a statement that is neither a For nor a With, but the rule only registers the visitor for those statement kinds. Firing it means the statement dispatch in the rule's visitor is out of sync with this handler.","triggerScenarios":"Thrown at crates/ruff_linter/src/rules/pylint/rules/redefined_loop_name.rs:408 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Ensure the visitor only calls the handler for Stmt::For and Stmt::With","Replace unreachable! with an early return for other statement kinds"],"exampleFix":null,"handlingStrategy":"type-guard","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"26f38c119cac42e4d320ba08f09224fdec74af2c","analyzedAt":"2026-09-05T10:32:37.492Z","contentChangedAt":"2026-09-05T10:32:37.492Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}