@@ -802,9 +802,19 @@ impl<'a> CompletionContext<'a> {
802
802
)
803
803
}
804
804
} ,
805
+ // match foo { $0 }
806
+ // match foo { ..., pat => $0 }
805
807
ast:: MatchExpr ( it) => {
806
- cov_mark:: hit!( expected_type_match_arm_without_leading_char) ;
807
- let ty = it. expr( ) . and_then( |e| self . sema. type_of_expr( & e) ) . map( TypeInfo :: original) ;
808
+ let ty = if self . previous_token_is( T ![ =>] ) {
809
+ // match foo { ..., pat => $0 }
810
+ cov_mark:: hit!( expected_type_match_arm_body_without_leading_char) ;
811
+ cov_mark:: hit!( expected_type_match_arm_body_with_leading_char) ;
812
+ self . sema. type_of_expr( & it. into( ) )
813
+ } else {
814
+ // match foo { $0 }
815
+ cov_mark:: hit!( expected_type_match_arm_without_leading_char) ;
816
+ it. expr( ) . and_then( |e| self . sema. type_of_expr( & e) )
817
+ } . map( TypeInfo :: original) ;
808
818
( ty, None )
809
819
} ,
810
820
ast:: IfExpr ( it) => {
@@ -1589,6 +1599,36 @@ fn foo() {
1589
1599
) ;
1590
1600
}
1591
1601
1602
+ #[ test]
1603
+ fn expected_type_match_arm_body_without_leading_char ( ) {
1604
+ cov_mark:: check!( expected_type_match_arm_body_without_leading_char) ;
1605
+ check_expected_type_and_name (
1606
+ r#"
1607
+ struct Foo;
1608
+ enum E { X }
1609
+ fn foo() -> Foo {
1610
+ match E::X { E::X => $0 }
1611
+ }
1612
+ "# ,
1613
+ expect ! [ [ r#"ty: Foo, name: ?"# ] ] ,
1614
+ ) ;
1615
+ }
1616
+
1617
+ #[ test]
1618
+ fn expected_type_match_body_arm_with_leading_char ( ) {
1619
+ cov_mark:: check!( expected_type_match_arm_body_with_leading_char) ;
1620
+ check_expected_type_and_name (
1621
+ r#"
1622
+ struct Foo;
1623
+ enum E { X }
1624
+ fn foo() -> Foo {
1625
+ match E::X { E::X => c$0 }
1626
+ }
1627
+ "# ,
1628
+ expect ! [ [ r#"ty: Foo, name: ?"# ] ] ,
1629
+ ) ;
1630
+ }
1631
+
1592
1632
#[ test]
1593
1633
fn expected_type_if_let_without_leading_char ( ) {
1594
1634
cov_mark:: check!( expected_type_if_let_without_leading_char) ;
0 commit comments