diff --git a/crates/ra_assists/src/handlers/invert_if.rs b/crates/ra_assists/src/handlers/invert_if.rs index 3a2665d172..4c57168687 100644 --- a/crates/ra_assists/src/handlers/invert_if.rs +++ b/crates/ra_assists/src/handlers/invert_if.rs @@ -33,6 +33,11 @@ pub(crate) fn invert_if(ctx: AssistCtx) -> Option { return None; } + // This assist should not apply for if-let. + if expr.condition()?.pat().is_some() { + return None; + } + let cond = expr.condition()?.expr()?; let then_node = expr.then_branch()?.syntax().clone(); @@ -90,4 +95,12 @@ mod tests { fn invert_if_doesnt_apply_with_cursor_not_on_if() { check_assist_not_applicable(invert_if, "fn f() { if !<|>cond { 3 * 2 } else { 1 } }") } + + #[test] + fn invert_if_doesnt_apply_with_if_let() { + check_assist_not_applicable( + invert_if, + "fn f() { i<|>f let Some(_) = Some(1) { 1 } else { 0 } }", + ) + } }