@@ -2517,18 +2517,35 @@ impl Type {
2517
2517
krate : Crate ,
2518
2518
mut callback : impl FnMut ( AssocItem ) -> Option < T > ,
2519
2519
) -> Option < T > {
2520
- for krate in method_resolution:: def_crates ( db, & self . ty , krate. id ) ? {
2520
+ let mut slot = None ;
2521
+ self . iterate_assoc_items_dyn ( db, krate, & mut |assoc_item_id| {
2522
+ slot = callback ( assoc_item_id. into ( ) ) ;
2523
+ slot. is_some ( )
2524
+ } ) ;
2525
+ slot
2526
+ }
2527
+
2528
+ fn iterate_assoc_items_dyn (
2529
+ self ,
2530
+ db : & dyn HirDatabase ,
2531
+ krate : Crate ,
2532
+ callback : & mut dyn FnMut ( AssocItemId ) -> bool ,
2533
+ ) {
2534
+ let def_crates = match method_resolution:: def_crates ( db, & self . ty , krate. id ) {
2535
+ Some ( it) => it,
2536
+ None => return ,
2537
+ } ;
2538
+ for krate in def_crates {
2521
2539
let impls = db. inherent_impls_in_crate ( krate) ;
2522
2540
2523
2541
for impl_def in impls. for_self_ty ( & self . ty ) {
2524
2542
for & item in db. impl_data ( * impl_def) . items . iter ( ) {
2525
- if let Some ( result ) = callback ( item. into ( ) ) {
2526
- return Some ( result ) ;
2543
+ if callback ( item) {
2544
+ return ;
2527
2545
}
2528
2546
}
2529
2547
}
2530
2548
}
2531
- None
2532
2549
}
2533
2550
2534
2551
pub fn type_arguments ( & self ) -> impl Iterator < Item = Type > + ' _ {
@@ -2547,9 +2564,34 @@ impl Type {
2547
2564
krate : Crate ,
2548
2565
traits_in_scope : & FxHashSet < TraitId > ,
2549
2566
name : Option < & Name > ,
2550
- mut callback : impl FnMut ( & Ty , Function ) -> Option < T > ,
2567
+ mut callback : impl FnMut ( Type , Function ) -> Option < T > ,
2551
2568
) -> Option < T > {
2552
2569
let _p = profile:: span ( "iterate_method_candidates" ) ;
2570
+ let mut slot = None ;
2571
+ self . iterate_method_candidates_dyn (
2572
+ db,
2573
+ krate,
2574
+ traits_in_scope,
2575
+ name,
2576
+ & mut |ty, assoc_item_id| match assoc_item_id {
2577
+ AssocItemId :: FunctionId ( it) => {
2578
+ slot = callback ( self . derived ( ty. clone ( ) ) , it. into ( ) ) ;
2579
+ slot. is_some ( )
2580
+ }
2581
+ AssocItemId :: ConstId ( _) | AssocItemId :: TypeAliasId ( _) => false ,
2582
+ } ,
2583
+ ) ;
2584
+ slot
2585
+ }
2586
+
2587
+ fn iterate_method_candidates_dyn (
2588
+ & self ,
2589
+ db : & dyn HirDatabase ,
2590
+ krate : Crate ,
2591
+ traits_in_scope : & FxHashSet < TraitId > ,
2592
+ name : Option < & Name > ,
2593
+ callback : & mut dyn FnMut ( & Ty , AssocItemId ) -> bool ,
2594
+ ) {
2553
2595
// There should be no inference vars in types passed here
2554
2596
// FIXME check that?
2555
2597
// FIXME replace Unknown by bound vars here
@@ -2559,7 +2601,7 @@ impl Type {
2559
2601
let env = self . env . clone ( ) ;
2560
2602
let krate = krate. id ;
2561
2603
2562
- method_resolution:: iterate_method_candidates (
2604
+ method_resolution:: iterate_method_candidates_dyn (
2563
2605
& canonical,
2564
2606
db,
2565
2607
env,
@@ -2568,11 +2610,8 @@ impl Type {
2568
2610
None ,
2569
2611
name,
2570
2612
method_resolution:: LookupMode :: MethodCall ,
2571
- |ty, it| match it {
2572
- AssocItemId :: FunctionId ( f) => callback ( ty, f. into ( ) ) ,
2573
- _ => None ,
2574
- } ,
2575
- )
2613
+ callback,
2614
+ ) ;
2576
2615
}
2577
2616
2578
2617
pub fn iterate_path_candidates < T > (
@@ -2581,15 +2620,37 @@ impl Type {
2581
2620
krate : Crate ,
2582
2621
traits_in_scope : & FxHashSet < TraitId > ,
2583
2622
name : Option < & Name > ,
2584
- mut callback : impl FnMut ( & Ty , AssocItem ) -> Option < T > ,
2623
+ mut callback : impl FnMut ( Type , AssocItem ) -> Option < T > ,
2585
2624
) -> Option < T > {
2586
2625
let _p = profile:: span ( "iterate_path_candidates" ) ;
2626
+ let mut slot = None ;
2627
+ self . iterate_path_candidates_dyn (
2628
+ db,
2629
+ krate,
2630
+ traits_in_scope,
2631
+ name,
2632
+ & mut |ty, assoc_item_id| {
2633
+ slot = callback ( self . derived ( ty. clone ( ) ) , assoc_item_id. into ( ) ) ;
2634
+ slot. is_some ( )
2635
+ } ,
2636
+ ) ;
2637
+ slot
2638
+ }
2639
+
2640
+ fn iterate_path_candidates_dyn (
2641
+ & self ,
2642
+ db : & dyn HirDatabase ,
2643
+ krate : Crate ,
2644
+ traits_in_scope : & FxHashSet < TraitId > ,
2645
+ name : Option < & Name > ,
2646
+ callback : & mut dyn FnMut ( & Ty , AssocItemId ) -> bool ,
2647
+ ) {
2587
2648
let canonical = hir_ty:: replace_errors_with_variables ( & self . ty ) ;
2588
2649
2589
2650
let env = self . env . clone ( ) ;
2590
2651
let krate = krate. id ;
2591
2652
2592
- method_resolution:: iterate_method_candidates (
2653
+ method_resolution:: iterate_method_candidates_dyn (
2593
2654
& canonical,
2594
2655
db,
2595
2656
env,
@@ -2598,8 +2659,8 @@ impl Type {
2598
2659
None ,
2599
2660
name,
2600
2661
method_resolution:: LookupMode :: Path ,
2601
- |ty , it| callback ( ty , it . into ( ) ) ,
2602
- )
2662
+ callback,
2663
+ ) ;
2603
2664
}
2604
2665
2605
2666
pub fn as_adt ( & self ) -> Option < Adt > {
0 commit comments