Skip to content

Commit 5e827bd

Browse files
Merge #3668
3668: disable invert-if assist for if-let r=matklad a=JoshMcguigan Fixes #3281 This disables the invert-if assist for if-let expressions, fixing the bug reported in #3281. While in the exact case reported in #3281, `if let Some(_) = foo { ...`, it would be possible to invert the if-let pattern, in most cases it will not be possible, so disabling this assist for if-let expressions seems reasonable. Co-authored-by: Josh Mcguigan <joshmcg88@gmail.com>
2 parents 1086733 + c3702a6 commit 5e827bd

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)