aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2020-03-21 13:59:03 +0000
committerGitHub <[email protected]>2020-03-21 13:59:03 +0000
commit5e827bd948ea206328b126345ab8e909978b3b9b (patch)
treea1a078720ff5a1f3fef051e97ad016f572e9e01a
parent10867336e627f84a4886592c0a2764f5105bd0ce (diff)
parentc3702a6b7143ca6e6186f3c0c07589ddd71b20fb (diff)
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 <[email protected]>
-rw-r--r--crates/ra_assists/src/handlers/invert_if.rs13
1 files changed, 13 insertions, 0 deletions
diff --git a/crates/ra_assists/src/handlers/invert_if.rs b/crates/ra_assists/src/handlers/invert_if.rs
index 3a2665d17..4c5716868 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<Assist> {
33 return None; 33 return None;
34 } 34 }
35 35
36 // This assist should not apply for if-let.
37 if expr.condition()?.pat().is_some() {
38 return None;
39 }
40
36 let cond = expr.condition()?.expr()?; 41 let cond = expr.condition()?.expr()?;
37 let then_node = expr.then_branch()?.syntax().clone(); 42 let then_node = expr.then_branch()?.syntax().clone();
38 43
@@ -90,4 +95,12 @@ mod tests {
90 fn invert_if_doesnt_apply_with_cursor_not_on_if() { 95 fn invert_if_doesnt_apply_with_cursor_not_on_if() {
91 check_assist_not_applicable(invert_if, "fn f() { if !<|>cond { 3 * 2 } else { 1 } }") 96 check_assist_not_applicable(invert_if, "fn f() { if !<|>cond { 3 * 2 } else { 1 } }")
92 } 97 }
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 }
93} 106}