Unnamed repository; edit this file 'description' to name the repository.
fix: uses bool instead pat ty in guard
Example
---
```rust
enum E { V }
fn foo() {
match E::V { _ if a$0 => {} }
}
```
**Before this PR**
```rust
ty: E, name: ?
```
**After this PR**
```rust
ty: bool, name: ?
```
| -rw-r--r-- | crates/ide-completion/src/context/analysis.rs | 4 | ||||
| -rw-r--r-- | crates/ide-completion/src/context/tests.rs | 15 |
2 files changed, 19 insertions, 0 deletions
diff --git a/crates/ide-completion/src/context/analysis.rs b/crates/ide-completion/src/context/analysis.rs index b2ee94d49c..b06f52c113 100644 --- a/crates/ide-completion/src/context/analysis.rs +++ b/crates/ide-completion/src/context/analysis.rs @@ -794,6 +794,10 @@ fn expected_type_and_name<'db>( }.map(TypeInfo::original); (ty, None) }, + ast::MatchGuard(it) => { + let ty = it.condition().and_then(|e| sema.type_of_expr(&e)).map(TypeInfo::original); + (ty, None) + }, ast::IdentPat(it) => { cov_mark::hit!(expected_type_if_let_with_leading_char); cov_mark::hit!(expected_type_match_arm_with_leading_char); diff --git a/crates/ide-completion/src/context/tests.rs b/crates/ide-completion/src/context/tests.rs index 1d1a55c6fe..c5fba82de4 100644 --- a/crates/ide-completion/src/context/tests.rs +++ b/crates/ide-completion/src/context/tests.rs @@ -410,6 +410,21 @@ fn foo() { } #[test] +fn expected_type_guard_condition() { + check_expected_type_and_name( + r#" +enum E { V } +fn foo() { + match E::V { + _ if a$0 => {} + } +} +"#, + expect![[r#"ty: bool, name: ?"#]], + ); +} + +#[test] fn expected_type_if_body() { check_expected_type_and_name( r#" |