Skip to content

Commit 9c7db53

Browse files
authored
Merge pull request rust-lang#20912 from A4-Tacks/left-side-in-cond
Fix not complete `let` before expr in condition
2 parents ad63c71 + 5fda166 commit 9c7db53

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

src/tools/rust-analyzer/crates/ide-completion/src/completions/postfix.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -460,6 +460,8 @@ pub(crate) fn is_in_condition(it: &ast::Expr) -> bool {
460460
ast::MatchGuard(guard) => guard.condition()? == *it,
461461
ast::BinExpr(bin_expr) => (bin_expr.op_token()?.kind() == T![&&])
462462
.then(|| is_in_condition(&bin_expr.into()))?,
463+
ast::Expr(expr) => (expr.syntax().text_range().start() == it.syntax().text_range().start())
464+
.then(|| is_in_condition(&expr))?,
463465
_ => return None,
464466
} })
465467
})

src/tools/rust-analyzer/crates/ide-completion/src/tests/expression.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3268,6 +3268,12 @@ fn foo() -> (i32, i32) {
32683268
#[test]
32693269
fn let_in_condition() {
32703270
check_edit("let", r#"fn f() { if $0 {} }"#, r#"fn f() { if let $1 = $0 {} }"#);
3271+
check_edit("let", r#"fn f() { if $0x {} }"#, r#"fn f() { if let $1 = $0x {} }"#);
3272+
check_edit(
3273+
"let",
3274+
r#"fn f() { if $0foo.bar() {} }"#,
3275+
r#"fn f() { if let $1 = $0foo.bar() {} }"#,
3276+
);
32713277
}
32723278

32733279
#[test]

0 commit comments

Comments
 (0)