@@ -173,20 +173,25 @@ fn compute_associated_fn(
173173 return None ;
174174 }
175175
176+ let has_args = !func. assoc_fn_params ( db) . is_empty ( ) ;
176177 let ret_type = func. ret_type ( db) ;
177178 let ret_unit_type = ret_type. is_unit ( ) ;
178- let self_ty = match func_kind {
179+ let self_type = match func_kind {
179180 FuncKind :: Function ( PathCompletionCtx {
180181 qualified : Qualified :: With { path, .. } , ..
181- } ) => path. segment ( ) . map ( |s| s . to_string ( ) ) ,
182+ } ) => path. segment ( ) . and_then ( |ps| ps . name_ref ( ) ) . map ( |n| n . to_string ( ) ) ,
182183 _ => None ,
183- } ;
184- let ( returns_self, returns_self_wrapped) = self_ty
185- . map ( |self_ty | {
184+ } ; // self type without any generic args
185+ let ( returns_self, returns_self_wrapped) = self_type
186+ . map ( |self_type | {
186187 let ret_ty = ret_type. display ( db) . to_string ( ) ;
187- let ret_self_wrapped = ret_ty. contains ( & format ! ( "<{self_ty}>" ) ) ;
188188
189- ( ret_ty == self_ty || ret_self_wrapped, ret_self_wrapped)
189+ // the second checks are needed when Self has generic args
190+ let ret_self_only = ret_ty == self_type || ret_ty. starts_with ( & format ! ( "{self_type}<" ) ) ;
191+ let ret_self_wrapped = ret_ty. ends_with ( & format ! ( "<{self_type}>" ) )
192+ || ret_ty. contains ( & format ! ( "<{self_type}<" ) ) ;
193+
194+ ( ret_self_only || ret_self_wrapped, ret_self_wrapped)
190195 } )
191196 . unwrap_or_else ( || ( false , false ) ) ;
192197
@@ -195,22 +200,22 @@ fn compute_associated_fn(
195200 && ctx. completion . expected_type . as_ref ( ) == Some ( & ret_type)
196201 {
197202 // impl Foo { fn baz(&self) -> u32 { 0 } }
198- // let _: u32 = foo.$0; // baz is preffered as it returns expected u32
203+ // let _: u32 = foo.$0; // baz is preferred as it returns expected u32
199204 CompletionRelevanceAssociatedFnType :: ReturnsExpectedType
200205 } else if ret_type. display ( db) . to_string ( ) . ends_with ( "Builder" ) {
201206 // -> [..]Builder
202207 CompletionRelevanceAssociatedFnType :: Builder
203208 } else if returns_self_wrapped {
204- // fn() -> Result<A>
209+ // fn([..] ) -> Result<A>
205210 CompletionRelevanceAssociatedFnType :: Constructor
206211 } else if returns_self {
207- // fn() -> A
212+ // fn([..] ) -> A
208213 CompletionRelevanceAssociatedFnType :: DirectConstructor
209214 } else {
210215 CompletionRelevanceAssociatedFnType :: Other
211216 } ;
212217
213- Some ( CompletionRelevanceAssociatedFn { ty, has_args : !func . assoc_fn_params ( db ) . is_empty ( ) } )
218+ Some ( CompletionRelevanceAssociatedFn { ty, has_args } )
214219}
215220
216221pub ( super ) fn add_call_parens < ' b > (
0 commit comments