@@ -58,6 +58,7 @@ pub(crate) struct PathCompletionContext {
5858pub ( super ) struct PatternContext {
5959 pub ( super ) refutability : PatternRefutability ,
6060 pub ( super ) is_param : Option < ParamKind > ,
61+ pub ( super ) has_type_ascription : bool ,
6162}
6263
6364#[ derive( Debug ) ]
@@ -597,7 +598,8 @@ impl<'a> CompletionContext<'a> {
597598 . map( |c| ( Some ( c. return_type( ) ) , None ) )
598599 . unwrap_or( ( None , None ) )
599600 } ,
600- ast:: Stmt ( _it) => ( None , None ) ,
601+ ast:: ParamList ( __) => ( None , None ) ,
602+ ast:: Stmt ( __) => ( None , None ) ,
601603 ast:: Item ( __) => ( None , None ) ,
602604 _ => {
603605 match node. parent( ) {
@@ -708,15 +710,15 @@ impl<'a> CompletionContext<'a> {
708710 return None ;
709711 }
710712 let mut is_param = None ;
711- let refutability = bind_pat
713+ let ( refutability, has_type_ascription ) = bind_pat
712714 . syntax ( )
713715 . ancestors ( )
714716 . skip_while ( |it| ast:: Pat :: can_cast ( it. kind ( ) ) )
715717 . next ( )
716- . map_or ( PatternRefutability :: Irrefutable , |node| {
717- match_ast ! {
718+ . map_or ( ( PatternRefutability :: Irrefutable , false ) , |node| {
719+ let refutability = match_ast ! {
718720 match node {
719- ast:: LetStmt ( __ ) => PatternRefutability :: Irrefutable ,
721+ ast:: LetStmt ( let_ ) => return ( PatternRefutability :: Irrefutable , let_ . ty ( ) . is_some ( ) ) ,
720722 ast:: Param ( param) => {
721723 let is_closure_param = param
722724 . syntax( )
@@ -729,16 +731,17 @@ impl<'a> CompletionContext<'a> {
729731 } else {
730732 ParamKind :: Function
731733 } ) ;
732- PatternRefutability :: Irrefutable
734+ return ( PatternRefutability :: Irrefutable , param . ty ( ) . is_some ( ) )
733735 } ,
734736 ast:: MatchArm ( __) => PatternRefutability :: Refutable ,
735737 ast:: Condition ( __) => PatternRefutability :: Refutable ,
736738 ast:: ForExpr ( __) => PatternRefutability :: Irrefutable ,
737739 _ => PatternRefutability :: Irrefutable ,
738740 }
739- }
741+ } ;
742+ ( refutability, false )
740743 } ) ;
741- Some ( PatternContext { refutability, is_param } )
744+ Some ( PatternContext { refutability, is_param, has_type_ascription } )
742745 }
743746
744747 fn classify_name_ref (
@@ -1172,4 +1175,23 @@ fn foo() {
11721175 expect ! [ [ r#"ty: Foo, name: ?"# ] ] ,
11731176 ) ;
11741177 }
1178+
1179+ #[ test]
1180+ fn expected_type_param_pat ( ) {
1181+ check_expected_type_and_name (
1182+ r#"
1183+ struct Foo { field: u32 }
1184+ fn foo(a$0: Foo) {}
1185+ "# ,
1186+ expect ! [ [ r#"ty: Foo, name: ?"# ] ] ,
1187+ ) ;
1188+ check_expected_type_and_name (
1189+ r#"
1190+ struct Foo { field: u32 }
1191+ fn foo($0: Foo) {}
1192+ "# ,
1193+ // FIXME make this work, currently fails due to pattern recovery eating the `:`
1194+ expect ! [ [ r#"ty: ?, name: ?"# ] ] ,
1195+ ) ;
1196+ }
11751197}
0 commit comments