@@ -183,39 +183,41 @@ impl ImportAssets {
183
183
}
184
184
185
185
fn applicable_defs < ' a > (
186
- & self ,
186
+ & ' a self ,
187
187
sema : & ' a Semantics < RootDatabase > ,
188
188
prefixed : Option < hir:: PrefixKind > ,
189
- unfiltered_imports : Box < dyn Iterator < Item = Either < ModuleDef , MacroDef > > + ' a > ,
189
+ unfiltered_defs : impl Iterator < Item = Either < ModuleDef , MacroDef > > + ' a ,
190
190
) -> Box < dyn Iterator < Item = ( ModPath , ItemInNs ) > + ' a > {
191
191
let current_crate = self . module_with_candidate . krate ( ) ;
192
192
let db = sema. db ;
193
193
194
194
match & self . import_candidate {
195
- ImportCandidate :: Path ( path_candidate) => path_applicable_defs (
195
+ ImportCandidate :: Path ( path_candidate) => Box :: new ( path_applicable_defs (
196
196
sema,
197
197
path_candidate,
198
- unfiltered_imports,
199
- self . module_with_candidate ,
200
- prefixed,
201
- ) ,
202
- ImportCandidate :: TraitAssocItem ( trait_candidate) => trait_applicable_defs (
203
- db,
204
- current_crate,
205
- trait_candidate,
206
- true ,
207
- unfiltered_imports,
208
- self . module_with_candidate ,
209
- prefixed,
198
+ unfiltered_defs
199
+ . into_iter ( )
200
+ . map ( |def| def. either ( ItemInNs :: from, ItemInNs :: from) )
201
+ . filter_map ( move |item_to_search| {
202
+ get_mod_path ( db, item_to_search, & self . module_with_candidate , prefixed)
203
+ . zip ( Some ( item_to_search) )
204
+ } ) ,
205
+ ) ) ,
206
+ ImportCandidate :: TraitAssocItem ( trait_candidate) => Box :: new (
207
+ trait_applicable_defs ( db, current_crate, trait_candidate, true , unfiltered_defs)
208
+ . into_iter ( )
209
+ . filter_map ( move |item_to_search| {
210
+ get_mod_path ( db, item_to_search, & self . module_with_candidate , prefixed)
211
+ . zip ( Some ( item_to_search) )
212
+ } ) ,
210
213
) ,
211
- ImportCandidate :: TraitMethod ( trait_candidate) => trait_applicable_defs (
212
- db,
213
- current_crate,
214
- trait_candidate,
215
- false ,
216
- unfiltered_imports,
217
- self . module_with_candidate ,
218
- prefixed,
214
+ ImportCandidate :: TraitMethod ( trait_candidate) => Box :: new (
215
+ trait_applicable_defs ( db, current_crate, trait_candidate, false , unfiltered_defs)
216
+ . into_iter ( )
217
+ . filter_map ( move |item_to_search| {
218
+ get_mod_path ( db, item_to_search, & self . module_with_candidate , prefixed)
219
+ . zip ( Some ( item_to_search) )
220
+ } ) ,
219
221
) ,
220
222
}
221
223
}
@@ -224,22 +226,12 @@ impl ImportAssets {
224
226
fn path_applicable_defs < ' a > (
225
227
sema : & ' a Semantics < RootDatabase > ,
226
228
path_candidate : & PathImportCandidate ,
227
- unfiltered_defs : Box < dyn Iterator < Item = Either < ModuleDef , MacroDef > > + ' a > ,
228
- module_with_candidate : Module ,
229
- prefixed : Option < hir:: PrefixKind > ,
230
- ) -> Box < dyn Iterator < Item = ( ModPath , ItemInNs ) > + ' a > {
231
- let applicable_defs = unfiltered_defs
232
- . map ( |candidate| candidate. either ( ItemInNs :: from, ItemInNs :: from) )
233
- . filter_map ( move |item_to_search| {
234
- get_mod_path ( sema. db , item_to_search, & module_with_candidate, prefixed)
235
- . zip ( Some ( item_to_search) )
236
- } ) ;
237
-
229
+ unfiltered_defs : impl Iterator < Item = ( ModPath , ItemInNs ) > + ' a ,
230
+ ) -> impl Iterator < Item = ( ModPath , ItemInNs ) > + ' a {
238
231
let unresolved_qualifier = match & path_candidate. unresolved_qualifier {
239
232
Some ( qualifier) => qualifier,
240
233
None => {
241
- // TODO kb too many boxes tossed around
242
- return Box :: new ( applicable_defs) ;
234
+ return unfiltered_defs;
243
235
}
244
236
} ;
245
237
@@ -252,7 +244,7 @@ fn path_applicable_defs<'a>(
252
244
// first segment is already unresolved, need to turn it into ModuleDef somehow
253
245
}
254
246
255
- return Box :: new ( applicable_defs ) ;
247
+ return unfiltered_defs ;
256
248
}
257
249
258
250
fn resolve_qualifier_start (
@@ -269,10 +261,8 @@ fn trait_applicable_defs<'a>(
269
261
current_crate : Crate ,
270
262
trait_candidate : & TraitImportCandidate ,
271
263
trait_assoc_item : bool ,
272
- unfiltered_defs : Box < dyn Iterator < Item = Either < ModuleDef , MacroDef > > + ' a > ,
273
- module_with_candidate : Module ,
274
- prefixed : Option < hir:: PrefixKind > ,
275
- ) -> Box < dyn Iterator < Item = ( ModPath , ItemInNs ) > + ' a > {
264
+ unfiltered_defs : impl Iterator < Item = Either < ModuleDef , MacroDef > > + ' a ,
265
+ ) -> FxHashSet < ItemInNs > {
276
266
let mut required_assoc_items = FxHashSet :: default ( ) ;
277
267
278
268
let trait_candidates = unfiltered_defs
@@ -287,7 +277,7 @@ fn trait_applicable_defs<'a>(
287
277
} )
288
278
. collect ( ) ;
289
279
290
- let mut applicable_defs = FxHashSet :: default ( ) ;
280
+ let mut applicable_traits = FxHashSet :: default ( ) ;
291
281
292
282
if trait_assoc_item {
293
283
trait_candidate. receiver_ty . iterate_path_candidates (
@@ -302,7 +292,8 @@ fn trait_applicable_defs<'a>(
302
292
return None ;
303
293
}
304
294
}
305
- applicable_defs. insert ( assoc_to_module_def ( assoc) ) ;
295
+ applicable_traits
296
+ . insert ( ItemInNs :: from ( ModuleDef :: from ( assoc. containing_trait ( db) ?) ) ) ;
306
297
}
307
298
None :: < ( ) >
308
299
} ,
@@ -316,25 +307,15 @@ fn trait_applicable_defs<'a>(
316
307
|_, function| {
317
308
let assoc = function. as_assoc_item ( db) ?;
318
309
if required_assoc_items. contains ( & assoc) {
319
- applicable_defs. insert ( assoc_to_module_def ( assoc) ) ;
310
+ applicable_traits
311
+ . insert ( ItemInNs :: from ( ModuleDef :: from ( assoc. containing_trait ( db) ?) ) ) ;
320
312
}
321
313
None :: < ( ) >
322
314
} ,
323
315
)
324
316
} ;
325
317
326
- Box :: new (
327
- applicable_defs
328
- . into_iter ( )
329
- . filter_map ( move |candidate| {
330
- let canidate_trait = candidate. as_assoc_item ( db) ?. containing_trait ( db) ?;
331
- Some ( ItemInNs :: from ( ModuleDef :: from ( canidate_trait) ) )
332
- } )
333
- . filter_map ( move |item_to_search| {
334
- get_mod_path ( db, item_to_search, & module_with_candidate, prefixed)
335
- . zip ( Some ( item_to_search) )
336
- } ) ,
337
- )
318
+ applicable_traits
338
319
}
339
320
340
321
fn get_mod_path (
@@ -350,14 +331,6 @@ fn get_mod_path(
350
331
}
351
332
}
352
333
353
- fn assoc_to_module_def ( assoc : AssocItem ) -> ModuleDef {
354
- match assoc {
355
- AssocItem :: Function ( f) => f. into ( ) ,
356
- AssocItem :: Const ( c) => c. into ( ) ,
357
- AssocItem :: TypeAlias ( t) => t. into ( ) ,
358
- }
359
- }
360
-
361
334
impl ImportCandidate {
362
335
fn for_method_call (
363
336
sema : & Semantics < RootDatabase > ,
0 commit comments