@@ -169,20 +169,25 @@ fn compute_associated_fn(
169169 return None ;
170170 }
171171
172+ let has_args = !func. assoc_fn_params ( db) . is_empty ( ) ;
172173 let ret_type = func. ret_type ( db) ;
173174 let ret_unit_type = ret_type. is_unit ( ) ;
174- let self_ty = match func_kind {
175+ let self_type = match func_kind {
175176 FuncKind :: Function ( PathCompletionCtx {
176177 qualified : Qualified :: With { path, .. } , ..
177- } ) => path. segment ( ) . map ( |s| s . to_string ( ) ) ,
178+ } ) => path. segment ( ) . and_then ( |ps| ps . name_ref ( ) ) . map ( |n| n . to_string ( ) ) ,
178179 _ => None ,
179- } ;
180- let ( returns_self, returns_self_wrapped) = self_ty
181- . map ( |self_ty | {
180+ } ; // self type without any generic args
181+ let ( returns_self, returns_self_wrapped) = self_type
182+ . map ( |self_type | {
182183 let ret_ty = ret_type. display ( db) . to_string ( ) ;
183- let ret_self_wrapped = ret_ty. contains ( & format ! ( "<{self_ty}>" ) ) ;
184184
185- ( ret_ty == self_ty || ret_self_wrapped, ret_self_wrapped)
185+ // the second checks are needed when Self has generic args
186+ let ret_self_only = ret_ty == self_type || ret_ty. starts_with ( & format ! ( "{self_type}<" ) ) ;
187+ let ret_self_wrapped = ret_ty. ends_with ( & format ! ( "<{self_type}>" ) )
188+ || ret_ty. contains ( & format ! ( "<{self_type}<" ) ) ;
189+
190+ ( ret_self_only || ret_self_wrapped, ret_self_wrapped)
186191 } )
187192 . unwrap_or_else ( || ( false , false ) ) ;
188193
@@ -191,22 +196,22 @@ fn compute_associated_fn(
191196 && ctx. completion . expected_type . as_ref ( ) == Some ( & ret_type)
192197 {
193198 // impl Foo { fn baz(&self) -> u32 { 0 } }
194- // let _: u32 = foo.$0; // baz is preffered as it returns expected u32
199+ // let _: u32 = foo.$0; // baz is preferred as it returns expected u32
195200 CompletionRelevanceAssociatedFnType :: ReturnsExpectedType
196201 } else if ret_type. display ( db) . to_string ( ) . ends_with ( "Builder" ) {
197202 // -> [..]Builder
198203 CompletionRelevanceAssociatedFnType :: Builder
199204 } else if returns_self_wrapped {
200- // fn() -> Result<A>
205+ // fn([..] ) -> Result<A>
201206 CompletionRelevanceAssociatedFnType :: Constructor
202207 } else if returns_self {
203- // fn() -> A
208+ // fn([..] ) -> A
204209 CompletionRelevanceAssociatedFnType :: DirectConstructor
205210 } else {
206211 CompletionRelevanceAssociatedFnType :: Other
207212 } ;
208213
209- Some ( CompletionRelevanceAssociatedFn { ty, has_args : !func . assoc_fn_params ( db ) . is_empty ( ) } )
214+ Some ( CompletionRelevanceAssociatedFn { ty, has_args } )
210215}
211216
212217pub ( super ) fn add_call_parens < ' b > (
0 commit comments