{"record":{"id":"cab6f7eb6b399a3d","repo":"astral-sh/ruff","slug":"expected-expression-listcomp-expression-setcom","errorCode":null,"errorMessage":"Expected Expression::ListComp | Expression::SetComp","messagePattern":"Expected Expression::ListComp \\| Expression::SetComp","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/ruff_linter/src/rules/flake8_comprehensions/fixes.rs","lineNumber":849,"sourceCode":"    let (whitespace_after, whitespace_before, elt, for_in, lpar, rpar) = match &call.args[0].value {\n        Expression::ListComp(list_comp) => (\n            &list_comp.lbracket.whitespace_after,\n            &list_comp.rbracket.whitespace_before,\n            &list_comp.elt,\n            &list_comp.for_in,\n            &list_comp.lpar,\n            &list_comp.rpar,\n        ),\n        Expression::SetComp(set_comp) => (\n            &set_comp.lbrace.whitespace_after,\n            &set_comp.rbrace.whitespace_before,\n            &set_comp.elt,\n            &set_comp.for_in,\n            &set_comp.lpar,\n            &set_comp.rpar,\n        ),\n        _ => {\n            bail!(\"Expected Expression::ListComp | Expression::SetComp\");\n        }\n    };\n\n    let mut new_empty_lines = vec![];\n\n    if let ParenthesizableWhitespace::ParenthesizedWhitespace(ParenthesizedWhitespace {\n        first_line,\n        empty_lines,\n        ..\n    }) = &whitespace_after\n    {\n        // If there's a comment on the line after the opening bracket, we need\n        // to preserve it. The way we do this is by adding a new empty line\n        // with the same comment.\n        //\n        // Example:\n        // ```python\n        // any(","sourceCodeStart":831,"sourceCodeEnd":867,"githubUrl":"https://github.com/astral-sh/ruff/blob/26f38c119cac42e4d320ba08f09224fdec74af2c/crates/ruff_linter/src/rules/flake8_comprehensions/fixes.rs#L831-L867","documentation":"An unreachable!/bail guard in fix_unnecessary_comprehension_in_call: the first argument of the call matched by the rule is neither a list comprehension nor a set comprehension, so there is nothing to unwrap. The rule trigger and the fixer disagree on the expression shape.","triggerScenarios":"Thrown at crates/ruff_linter/src/rules/flake8_comprehensions/fixes.rs:849 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Align the rule's detection with the fixer so only list/set comprehensions are fixed","Bail without a fix when the argument shape is unexpected"],"exampleFix":null,"handlingStrategy":"try-catch","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"}