mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-26 11:59:49 +00:00
fix: Fix incorrect expected type in completions for match arms
This commit is contained in:
parent
b6b17c7a59
commit
018975b041
1 changed files with 42 additions and 2 deletions
|
@ -802,9 +802,19 @@ impl<'a> CompletionContext<'a> {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
// match foo { $0 }
|
||||||
|
// match foo { ..., pat => $0 }
|
||||||
ast::MatchExpr(it) => {
|
ast::MatchExpr(it) => {
|
||||||
|
let ty = if self.previous_token_is(T![=>]) {
|
||||||
|
// match foo { ..., pat => $0 }
|
||||||
|
cov_mark::hit!(expected_type_match_arm_body_without_leading_char);
|
||||||
|
cov_mark::hit!(expected_type_match_arm_body_with_leading_char);
|
||||||
|
self.sema.type_of_expr(&it.into())
|
||||||
|
} else {
|
||||||
|
// match foo { $0 }
|
||||||
cov_mark::hit!(expected_type_match_arm_without_leading_char);
|
cov_mark::hit!(expected_type_match_arm_without_leading_char);
|
||||||
let ty = it.expr().and_then(|e| self.sema.type_of_expr(&e)).map(TypeInfo::original);
|
it.expr().and_then(|e| self.sema.type_of_expr(&e))
|
||||||
|
}.map(TypeInfo::original);
|
||||||
(ty, None)
|
(ty, None)
|
||||||
},
|
},
|
||||||
ast::IfExpr(it) => {
|
ast::IfExpr(it) => {
|
||||||
|
@ -1589,6 +1599,36 @@ fn foo() {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn expected_type_match_arm_body_without_leading_char() {
|
||||||
|
cov_mark::check!(expected_type_match_arm_body_without_leading_char);
|
||||||
|
check_expected_type_and_name(
|
||||||
|
r#"
|
||||||
|
struct Foo;
|
||||||
|
enum E { X }
|
||||||
|
fn foo() -> Foo {
|
||||||
|
match E::X { E::X => $0 }
|
||||||
|
}
|
||||||
|
"#,
|
||||||
|
expect![[r#"ty: Foo, name: ?"#]],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn expected_type_match_body_arm_with_leading_char() {
|
||||||
|
cov_mark::check!(expected_type_match_arm_body_with_leading_char);
|
||||||
|
check_expected_type_and_name(
|
||||||
|
r#"
|
||||||
|
struct Foo;
|
||||||
|
enum E { X }
|
||||||
|
fn foo() -> Foo {
|
||||||
|
match E::X { E::X => c$0 }
|
||||||
|
}
|
||||||
|
"#,
|
||||||
|
expect![[r#"ty: Foo, name: ?"#]],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn expected_type_if_let_without_leading_char() {
|
fn expected_type_if_let_without_leading_char() {
|
||||||
cov_mark::check!(expected_type_if_let_without_leading_char);
|
cov_mark::check!(expected_type_if_let_without_leading_char);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue