@@ -27,6 +27,8 @@ pub(crate) fn complete_dot(
27
27
}
28
28
29
29
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 } ) ;
30
32
31
33
complete_fields (
32
34
acc,
@@ -35,6 +37,7 @@ pub(crate) fn complete_dot(
35
37
|acc, field, ty| acc. add_field ( ctx, dot_access, None , field, & ty) ,
36
38
|acc, field, ty| acc. add_tuple_field ( ctx, None , field, & ty) ,
37
39
is_field_access,
40
+ is_method_acces_with_parens,
38
41
) ;
39
42
40
43
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(
83
86
} ,
84
87
|acc, field, ty| acc. add_tuple_field ( ctx, Some ( hir:: known:: SELF_PARAM ) , field, & ty) ,
85
88
true ,
89
+ false ,
86
90
) ;
87
91
complete_methods ( ctx, & ty, |func| {
88
92
acc. add_method (
@@ -106,12 +110,14 @@ fn complete_fields(
106
110
mut named_field : impl FnMut ( & mut Completions , hir:: Field , hir:: Type ) ,
107
111
mut tuple_index : impl FnMut ( & mut Completions , usize , hir:: Type ) ,
108
112
is_field_access : bool ,
113
+ is_method_acess_with_parens : bool ,
109
114
) {
110
115
let mut seen_names = FxHashSet :: default ( ) ;
111
116
for receiver in receiver. autoderef ( ctx. db ) {
112
117
for ( field, ty) in receiver. fields ( ctx. db ) {
113
118
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 ( ) ) ) )
115
121
{
116
122
named_field ( acc, field, ty) ;
117
123
}
@@ -120,7 +126,8 @@ fn complete_fields(
120
126
// Tuples are always the last type in a deref chain, so just check if the name is
121
127
// already seen without inserting into the hashset.
122
128
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 ( ) ) ) )
124
131
{
125
132
// Tuple fields are always public (tuple struct fields are handled above).
126
133
tuple_index ( acc, i, ty) ;
@@ -1236,4 +1243,24 @@ fn foo() {
1236
1243
"# ,
1237
1244
)
1238
1245
}
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
+ }
1239
1266
}
0 commit comments