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