@@ -27,6 +27,8 @@ pub(crate) fn complete_dot(
2727 }
2828
2929 let is_field_access = matches ! ( dot_access. kind, DotAccessKind :: Field { .. } ) ;
30+ let is_method_acces_with_parens =
31+ matches ! ( dot_access. kind, DotAccessKind :: Method { has_parens: true } ) ;
3032
3133 complete_fields (
3234 acc,
@@ -35,6 +37,7 @@ pub(crate) fn complete_dot(
3537 |acc, field, ty| acc. add_field ( ctx, dot_access, None , field, & ty) ,
3638 |acc, field, ty| acc. add_tuple_field ( ctx, None , field, & ty) ,
3739 is_field_access,
40+ is_method_acces_with_parens,
3841 ) ;
3942
4043 complete_methods ( ctx, receiver_ty, |func| acc. add_method ( ctx, dot_access, func, None , None ) ) ;
@@ -83,6 +86,7 @@ pub(crate) fn complete_undotted_self(
8386 } ,
8487 |acc, field, ty| acc. add_tuple_field ( ctx, Some ( hir:: known:: SELF_PARAM ) , field, & ty) ,
8588 true ,
89+ false ,
8690 ) ;
8791 complete_methods ( ctx, & ty, |func| {
8892 acc. add_method (
@@ -106,12 +110,14 @@ fn complete_fields(
106110 mut named_field : impl FnMut ( & mut Completions , hir:: Field , hir:: Type ) ,
107111 mut tuple_index : impl FnMut ( & mut Completions , usize , hir:: Type ) ,
108112 is_field_access : bool ,
113+ is_method_acess_with_parens : bool ,
109114) {
110115 let mut seen_names = FxHashSet :: default ( ) ;
111116 for receiver in receiver. autoderef ( ctx. db ) {
112117 for ( field, ty) in receiver. fields ( ctx. db ) {
113118 if seen_names. insert ( field. name ( ctx. db ) )
114- && ( is_field_access || ty. is_fn ( ) || ty. is_closure ( ) )
119+ && ( is_field_access
120+ || ( is_method_acess_with_parens && ( ty. is_fn ( ) || ty. is_closure ( ) ) ) )
115121 {
116122 named_field ( acc, field, ty) ;
117123 }
@@ -120,7 +126,8 @@ fn complete_fields(
120126 // Tuples are always the last type in a deref chain, so just check if the name is
121127 // already seen without inserting into the hashset.
122128 if !seen_names. contains ( & hir:: Name :: new_tuple_field ( i) )
123- && ( is_field_access || ty. is_fn ( ) || ty. is_closure ( ) )
129+ && ( is_field_access
130+ || ( is_method_acess_with_parens && ( ty. is_fn ( ) || ty. is_closure ( ) ) ) )
124131 {
125132 // Tuple fields are always public (tuple struct fields are handled above).
126133 tuple_index ( acc, i, ty) ;
@@ -1236,4 +1243,24 @@ fn foo() {
12361243"# ,
12371244 )
12381245 }
1246+
1247+ #[ test]
1248+ fn test_fn_field_dot_access_method_has_parens_false ( ) {
1249+ check (
1250+ r#"
1251+ struct Foo { baz: fn() }
1252+ impl Foo {
1253+ fn bar<T>(self, t: T): T { t }
1254+ }
1255+
1256+ fn baz() {
1257+ let foo = Foo{ baz: || {} };
1258+ foo.ba$0::<>;
1259+ }
1260+ "# ,
1261+ expect ! [ [ r#"
1262+ me bar(…) fn(self, T)
1263+ "# ] ] ,
1264+ ) ;
1265+ }
12391266}
0 commit comments