expect(clippy::collapsible_else_if) falsely reports "this lint expectation is unfulfilled" when used inside the else block:
Lint Name
clippy::collapsible_else_if
Reproducer
fn main() {
// Correctly detected as collapsible:
if true {
} else {
if false {}
}
// Allowing the lint silences it both inside the `else` block:
if true {
} else {
#[allow(clippy::collapsible_else_if)]
if false {}
}
// ... and before the entire `if`:
#[allow(clippy::collapsible_else_if)]
if true {
} else {
if false {}
}
// Using `expect` inside the `else` block says "this lint expectation is unfulfilled":
if true {
} else {
#[expect(clippy::collapsible_else_if)]
if false {}
}
// This works correctly, however:
#[expect(clippy::collapsible_else_if)]
if true {
} else {
if false {}
}
}
This will require the same workaround as needless_return. The lint doesn't fire if the inner if has an attribute on it which the causes the lint expectation to be unfulfilled.
Summary
expect(clippy::collapsible_else_if)
falsely reports "this lint expectation is unfulfilled" when used inside theelse
block:Lint Name
clippy::collapsible_else_if
Reproducer
Version
Additional Labels
No response