@@ -173,20 +173,25 @@ fn compute_associated_fn(
173
173
return None ;
174
174
}
175
175
176
+ let has_args = !func. assoc_fn_params ( db) . is_empty ( ) ;
176
177
let ret_type = func. ret_type ( db) ;
177
178
let ret_unit_type = ret_type. is_unit ( ) ;
178
- let self_ty = match func_kind {
179
+ let self_type = match func_kind {
179
180
FuncKind :: Function ( PathCompletionCtx {
180
181
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 ( ) ) ,
182
183
_ => 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 | {
186
187
let ret_ty = ret_type. display ( db) . to_string ( ) ;
187
- let ret_self_wrapped = ret_ty. contains ( & format ! ( "<{self_ty}>" ) ) ;
188
188
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)
190
195
} )
191
196
. unwrap_or_else ( || ( false , false ) ) ;
192
197
@@ -195,22 +200,22 @@ fn compute_associated_fn(
195
200
&& ctx. completion . expected_type . as_ref ( ) == Some ( & ret_type)
196
201
{
197
202
// 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
199
204
CompletionRelevanceAssociatedFnType :: ReturnsExpectedType
200
205
} else if ret_type. display ( db) . to_string ( ) . ends_with ( "Builder" ) {
201
206
// -> [..]Builder
202
207
CompletionRelevanceAssociatedFnType :: Builder
203
208
} else if returns_self_wrapped {
204
- // fn() -> Result<A>
209
+ // fn([..] ) -> Result<A>
205
210
CompletionRelevanceAssociatedFnType :: Constructor
206
211
} else if returns_self {
207
- // fn() -> A
212
+ // fn([..] ) -> A
208
213
CompletionRelevanceAssociatedFnType :: DirectConstructor
209
214
} else {
210
215
CompletionRelevanceAssociatedFnType :: Other
211
216
} ;
212
217
213
- Some ( CompletionRelevanceAssociatedFn { ty, has_args : !func . assoc_fn_params ( db ) . is_empty ( ) } )
218
+ Some ( CompletionRelevanceAssociatedFn { ty, has_args } )
214
219
}
215
220
216
221
pub ( super ) fn add_call_parens < ' b > (
0 commit comments