@@ -58,6 +58,7 @@ pub(crate) struct PathCompletionContext {
58
58
pub ( super ) struct PatternContext {
59
59
pub ( super ) refutability : PatternRefutability ,
60
60
pub ( super ) is_param : Option < ParamKind > ,
61
+ pub ( super ) has_type_ascription : bool ,
61
62
}
62
63
63
64
#[ derive( Debug ) ]
@@ -597,7 +598,8 @@ impl<'a> CompletionContext<'a> {
597
598
. map( |c| ( Some ( c. return_type( ) ) , None ) )
598
599
. unwrap_or( ( None , None ) )
599
600
} ,
600
- ast:: Stmt ( _it) => ( None , None ) ,
601
+ ast:: ParamList ( __) => ( None , None ) ,
602
+ ast:: Stmt ( __) => ( None , None ) ,
601
603
ast:: Item ( __) => ( None , None ) ,
602
604
_ => {
603
605
match node. parent( ) {
@@ -708,15 +710,15 @@ impl<'a> CompletionContext<'a> {
708
710
return None ;
709
711
}
710
712
let mut is_param = None ;
711
- let refutability = bind_pat
713
+ let ( refutability, has_type_ascription ) = bind_pat
712
714
. syntax ( )
713
715
. ancestors ( )
714
716
. skip_while ( |it| ast:: Pat :: can_cast ( it. kind ( ) ) )
715
717
. next ( )
716
- . map_or ( PatternRefutability :: Irrefutable , |node| {
717
- match_ast ! {
718
+ . map_or ( ( PatternRefutability :: Irrefutable , false ) , |node| {
719
+ let refutability = match_ast ! {
718
720
match node {
719
- ast:: LetStmt ( __ ) => PatternRefutability :: Irrefutable ,
721
+ ast:: LetStmt ( let_ ) => return ( PatternRefutability :: Irrefutable , let_ . ty ( ) . is_some ( ) ) ,
720
722
ast:: Param ( param) => {
721
723
let is_closure_param = param
722
724
. syntax( )
@@ -729,16 +731,17 @@ impl<'a> CompletionContext<'a> {
729
731
} else {
730
732
ParamKind :: Function
731
733
} ) ;
732
- PatternRefutability :: Irrefutable
734
+ return ( PatternRefutability :: Irrefutable , param . ty ( ) . is_some ( ) )
733
735
} ,
734
736
ast:: MatchArm ( __) => PatternRefutability :: Refutable ,
735
737
ast:: Condition ( __) => PatternRefutability :: Refutable ,
736
738
ast:: ForExpr ( __) => PatternRefutability :: Irrefutable ,
737
739
_ => PatternRefutability :: Irrefutable ,
738
740
}
739
- }
741
+ } ;
742
+ ( refutability, false )
740
743
} ) ;
741
- Some ( PatternContext { refutability, is_param } )
744
+ Some ( PatternContext { refutability, is_param, has_type_ascription } )
742
745
}
743
746
744
747
fn classify_name_ref (
@@ -1172,4 +1175,23 @@ fn foo() {
1172
1175
expect ! [ [ r#"ty: Foo, name: ?"# ] ] ,
1173
1176
) ;
1174
1177
}
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
+ }
1175
1197
}
0 commit comments