@@ -25,9 +25,7 @@ pub(crate) fn complete_dot(
2525 _ => return ,
2626 } ;
2727
28- let is_field_access = matches ! ( dot_access. kind, DotAccessKind :: Field { .. } ) ;
29- let is_method_access_with_parens =
30- matches ! ( dot_access. kind, DotAccessKind :: Method { has_parens: true } ) ;
28+ let has_parens = matches ! ( dot_access. kind, DotAccessKind :: Method ) ;
3129 let traits_in_scope = ctx. traits_in_scope ( ) ;
3230
3331 // Suggest .await syntax for types that implement Future trait
@@ -48,7 +46,7 @@ pub(crate) fn complete_dot(
4846 DotAccessKind :: Field { receiver_is_ambiguous_float_literal : _ } => {
4947 DotAccessKind :: Field { receiver_is_ambiguous_float_literal : false }
5048 }
51- it @ DotAccessKind :: Method { .. } => * it,
49+ it @ DotAccessKind :: Method => * it,
5250 } ;
5351 let dot_access = DotAccess {
5452 receiver : dot_access. receiver . clone ( ) ,
@@ -67,8 +65,7 @@ pub(crate) fn complete_dot(
6765 acc. add_field ( ctx, & dot_access, Some ( await_str. clone ( ) ) , field, & ty)
6866 } ,
6967 |acc, field, ty| acc. add_tuple_field ( ctx, Some ( await_str. clone ( ) ) , field, & ty) ,
70- is_field_access,
71- is_method_access_with_parens,
68+ has_parens,
7269 ) ;
7370 complete_methods ( ctx, & future_output, & traits_in_scope, |func| {
7471 acc. add_method ( ctx, & dot_access, func, Some ( await_str. clone ( ) ) , None )
@@ -82,8 +79,7 @@ pub(crate) fn complete_dot(
8279 receiver_ty,
8380 |acc, field, ty| acc. add_field ( ctx, dot_access, None , field, & ty) ,
8481 |acc, field, ty| acc. add_tuple_field ( ctx, None , field, & ty) ,
85- is_field_access,
86- is_method_access_with_parens,
82+ has_parens,
8783 ) ;
8884 complete_methods ( ctx, receiver_ty, & traits_in_scope, |func| {
8985 acc. add_method ( ctx, dot_access, func, None , None )
@@ -112,7 +108,7 @@ pub(crate) fn complete_dot(
112108 DotAccessKind :: Field { receiver_is_ambiguous_float_literal : _ } => {
113109 DotAccessKind :: Field { receiver_is_ambiguous_float_literal : false }
114110 }
115- it @ DotAccessKind :: Method { .. } => * it,
111+ it @ DotAccessKind :: Method => * it,
116112 } ;
117113 let dot_access = DotAccess {
118114 receiver : dot_access. receiver . clone ( ) ,
@@ -173,7 +169,6 @@ pub(crate) fn complete_undotted_self(
173169 )
174170 } ,
175171 |acc, field, ty| acc. add_tuple_field ( ctx, Some ( SmolStr :: new_static ( "self" ) ) , field, & ty) ,
176- true ,
177172 false ,
178173 ) ;
179174 complete_methods ( ctx, & ty, & ctx. traits_in_scope ( ) , |func| {
@@ -182,7 +177,7 @@ pub(crate) fn complete_undotted_self(
182177 & DotAccess {
183178 receiver : None ,
184179 receiver_ty : None ,
185- kind : DotAccessKind :: Method { has_parens : false } ,
180+ kind : DotAccessKind :: Field { receiver_is_ambiguous_float_literal : false } ,
186181 ctx : DotAccessExprCtx {
187182 in_block_expr : expr_ctx. in_block_expr ,
188183 in_breakable : expr_ctx. in_breakable ,
@@ -201,15 +196,13 @@ fn complete_fields(
201196 receiver : & hir:: Type < ' _ > ,
202197 mut named_field : impl FnMut ( & mut Completions , hir:: Field , hir:: Type < ' _ > ) ,
203198 mut tuple_index : impl FnMut ( & mut Completions , usize , hir:: Type < ' _ > ) ,
204- is_field_access : bool ,
205- is_method_access_with_parens : bool ,
199+ has_parens : bool ,
206200) {
207201 let mut seen_names = FxHashSet :: default ( ) ;
208202 for receiver in receiver. autoderef ( ctx. db ) {
209203 for ( field, ty) in receiver. fields ( ctx. db ) {
210204 if seen_names. insert ( field. name ( ctx. db ) )
211- && ( is_field_access
212- || ( is_method_access_with_parens && ( ty. is_fn ( ) || ty. is_closure ( ) ) ) )
205+ && ( !has_parens || ty. is_fn ( ) || ty. is_closure ( ) )
213206 {
214207 named_field ( acc, field, ty) ;
215208 }
@@ -218,8 +211,7 @@ fn complete_fields(
218211 // Tuples are always the last type in a deref chain, so just check if the name is
219212 // already seen without inserting into the hashset.
220213 if !seen_names. contains ( & hir:: Name :: new_tuple_field ( i) )
221- && ( is_field_access
222- || ( is_method_access_with_parens && ( ty. is_fn ( ) || ty. is_closure ( ) ) ) )
214+ && ( !has_parens || ty. is_fn ( ) || ty. is_closure ( ) )
223215 {
224216 // Tuple fields are always public (tuple struct fields are handled above).
225217 tuple_index ( acc, i, ty) ;
@@ -1364,18 +1356,71 @@ fn foo() {
13641356 r#"
13651357struct Foo { baz: fn() }
13661358impl Foo {
1367- fn bar<T>(self, t: T): T { t }
1359+ fn bar<T>(self, t: T) -> T { t }
13681360}
13691361
13701362fn baz() {
13711363 let foo = Foo{ baz: || {} };
1372- foo.ba$0::<> ;
1364+ foo.ba$0;
13731365}
13741366"# ,
13751367 expect ! [ [ r#"
1376- me bar(…) fn(self, T)
1368+ fd baz fn()
1369+ me bar(…) fn(self, T) -> T
13771370 "# ] ] ,
13781371 ) ;
1372+
1373+ check_edit (
1374+ "baz" ,
1375+ r#"
1376+ struct Foo { baz: fn() }
1377+ impl Foo {
1378+ fn bar<T>(self, t: T) -> T { t }
1379+ }
1380+
1381+ fn baz() {
1382+ let foo = Foo{ baz: || {} };
1383+ foo.ba$0;
1384+ }
1385+ "# ,
1386+ r#"
1387+ struct Foo { baz: fn() }
1388+ impl Foo {
1389+ fn bar<T>(self, t: T) -> T { t }
1390+ }
1391+
1392+ fn baz() {
1393+ let foo = Foo{ baz: || {} };
1394+ (foo.baz)();
1395+ }
1396+ "# ,
1397+ ) ;
1398+
1399+ check_edit (
1400+ "bar" ,
1401+ r#"
1402+ struct Foo { baz: fn() }
1403+ impl Foo {
1404+ fn bar<T>(self, t: T) -> T { t }
1405+ }
1406+
1407+ fn baz() {
1408+ let foo = Foo{ baz: || {} };
1409+ foo.ba$0;
1410+ }
1411+ "# ,
1412+ r#"
1413+ struct Foo { baz: fn() }
1414+ impl Foo {
1415+ fn bar<T>(self, t: T) -> T { t }
1416+ }
1417+
1418+ fn baz() {
1419+ let foo = Foo{ baz: || {} };
1420+ foo.bar(${1:t})$0;
1421+ }
1422+ "# ,
1423+ ) ;
13791424 }
13801425
13811426 #[ test]
0 commit comments