mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-30 13:51:31 +00:00
Merge #10988
10988: Fix expected type calculation in struct literal if followed by comma r=flodiebold a=flodiebold Co-authored-by: Florian Diebold <flodiebold@gmail.com>
This commit is contained in:
commit
36a7c0e009
1 changed files with 29 additions and 5 deletions
|
@ -561,11 +561,21 @@ impl<'a> CompletionContext<'a> {
|
||||||
})().unwrap_or((None, None))
|
})().unwrap_or((None, None))
|
||||||
},
|
},
|
||||||
ast::RecordExprField(it) => {
|
ast::RecordExprField(it) => {
|
||||||
cov_mark::hit!(expected_type_struct_field_with_leading_char);
|
if let Some(expr) = it.expr() {
|
||||||
(
|
cov_mark::hit!(expected_type_struct_field_with_leading_char);
|
||||||
it.expr().as_ref().and_then(|e| self.sema.type_of_expr(e)).map(TypeInfo::original),
|
(
|
||||||
it.field_name().map(NameOrNameRef::NameRef),
|
self.sema.type_of_expr(&expr).map(TypeInfo::original),
|
||||||
)
|
it.field_name().map(NameOrNameRef::NameRef),
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
cov_mark::hit!(expected_type_struct_field_followed_by_comma);
|
||||||
|
let ty = self.sema.resolve_record_field(&it)
|
||||||
|
.map(|(_, _, ty)| ty);
|
||||||
|
(
|
||||||
|
ty,
|
||||||
|
it.field_name().map(NameOrNameRef::NameRef),
|
||||||
|
)
|
||||||
|
}
|
||||||
},
|
},
|
||||||
ast::MatchExpr(it) => {
|
ast::MatchExpr(it) => {
|
||||||
cov_mark::hit!(expected_type_match_arm_without_leading_char);
|
cov_mark::hit!(expected_type_match_arm_without_leading_char);
|
||||||
|
@ -1008,6 +1018,20 @@ fn foo() {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn expected_type_struct_field_followed_by_comma() {
|
||||||
|
cov_mark::check!(expected_type_struct_field_followed_by_comma);
|
||||||
|
check_expected_type_and_name(
|
||||||
|
r#"
|
||||||
|
struct Foo { a: u32 }
|
||||||
|
fn foo() {
|
||||||
|
Foo { a: $0, };
|
||||||
|
}
|
||||||
|
"#,
|
||||||
|
expect![[r#"ty: u32, name: a"#]],
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn expected_type_generic_struct_field() {
|
fn expected_type_generic_struct_field() {
|
||||||
check_expected_type_and_name(
|
check_expected_type_and_name(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue