Skip to content

Commit c3702a6

Browse files
committed
disable invert if assist for if-let to fix #3281
1 parent 1086733 commit c3702a6

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

crates/ra_assists/src/handlers/invert_if.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ pub(crate) fn invert_if(ctx: AssistCtx) -> Option<Assist> {
3333
return None;
3434
}
3535

36+
// This assist should not apply for if-let.
37+
if expr.condition()?.pat().is_some() {
38+
return None;
39+
}
40+
3641
let cond = expr.condition()?.expr()?;
3742
let then_node = expr.then_branch()?.syntax().clone();
3843

@@ -90,4 +95,12 @@ mod tests {
9095
fn invert_if_doesnt_apply_with_cursor_not_on_if() {
9196
check_assist_not_applicable(invert_if, "fn f() { if !<|>cond { 3 * 2 } else { 1 } }")
9297
}
98+
99+
#[test]
100+
fn invert_if_doesnt_apply_with_if_let() {
101+
check_assist_not_applicable(
102+
invert_if,
103+
"fn f() { i<|>f let Some(_) = Some(1) { 1 } else { 0 } }",
104+
)
105+
}
93106
}

0 commit comments

Comments
 (0)