mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-11-15 17:28:09 +00:00
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>
This commit is contained in:
commit
5e827bd948
1 changed files with 13 additions and 0 deletions
|
@ -33,6 +33,11 @@ pub(crate) fn invert_if(ctx: AssistCtx) -> Option<Assist> {
|
|||
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 } }",
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue