@@ -561,11 +561,21 @@ impl<'a> CompletionContext<'a> {
561
561
} ) ( ) . unwrap_or( ( None , None ) )
562
562
} ,
563
563
ast:: RecordExprField ( it) => {
564
- cov_mark:: hit!( expected_type_struct_field_with_leading_char) ;
565
- (
566
- it. expr( ) . as_ref( ) . and_then( |e| self . sema. type_of_expr( e) ) . map( TypeInfo :: original) ,
567
- it. field_name( ) . map( NameOrNameRef :: NameRef ) ,
568
- )
564
+ if let Some ( expr) = it. expr( ) {
565
+ cov_mark:: hit!( expected_type_struct_field_with_leading_char) ;
566
+ (
567
+ self . sema. type_of_expr( & expr) . map( TypeInfo :: original) ,
568
+ it. field_name( ) . map( NameOrNameRef :: NameRef ) ,
569
+ )
570
+ } else {
571
+ cov_mark:: hit!( expected_type_struct_field_followed_by_comma) ;
572
+ let ty = self . sema. resolve_record_field( & it)
573
+ . map( |( _, _, ty) | ty) ;
574
+ (
575
+ ty,
576
+ it. field_name( ) . map( NameOrNameRef :: NameRef ) ,
577
+ )
578
+ }
569
579
} ,
570
580
ast:: MatchExpr ( it) => {
571
581
cov_mark:: hit!( expected_type_match_arm_without_leading_char) ;
@@ -1008,6 +1018,20 @@ fn foo() {
1008
1018
)
1009
1019
}
1010
1020
1021
+ #[ test]
1022
+ fn expected_type_struct_field_followed_by_comma ( ) {
1023
+ cov_mark:: check!( expected_type_struct_field_followed_by_comma) ;
1024
+ check_expected_type_and_name (
1025
+ r#"
1026
+ struct Foo { a: u32 }
1027
+ fn foo() {
1028
+ Foo { a: $0, };
1029
+ }
1030
+ "# ,
1031
+ expect ! [ [ r#"ty: u32, name: a"# ] ] ,
1032
+ )
1033
+ }
1034
+
1011
1035
#[ test]
1012
1036
fn expected_type_generic_struct_field ( ) {
1013
1037
check_expected_type_and_name (
0 commit comments