@@ -6,7 +6,9 @@ mod tests;
6
6
use std:: { iter, ops:: Not } ;
7
7
8
8
use either:: Either ;
9
- use hir:: { db:: DefDatabase , GenericSubstitution , HasCrate , HasSource , LangItem , Semantics } ;
9
+ use hir:: {
10
+ db:: DefDatabase , GenericDef , GenericSubstitution , HasCrate , HasSource , LangItem , Semantics ,
11
+ } ;
10
12
use ide_db:: {
11
13
defs:: { Definition , IdentClass , NameRefClass , OperatorClass } ,
12
14
famous_defs:: FamousDefs ,
@@ -548,40 +550,29 @@ fn goto_type_action_for_def(
548
550
} ) ;
549
551
}
550
552
551
- if let Definition :: GenericParam ( hir:: GenericParam :: TypeParam ( it) ) = def {
552
- let krate = it. module ( db) . krate ( ) ;
553
- let sized_trait =
554
- db. lang_item ( krate. into ( ) , LangItem :: Sized ) . and_then ( |lang_item| lang_item. as_trait ( ) ) ;
553
+ if let Ok ( generic_def) = GenericDef :: try_from ( def) {
554
+ generic_def. type_or_const_params ( db) . into_iter ( ) . for_each ( |it| {
555
+ walk_and_push_ty ( db, & it. ty ( db) , & mut push_new_def) ;
556
+ } ) ;
557
+ }
555
558
556
- it. trait_bounds ( db)
557
- . into_iter ( )
558
- . filter ( |& it| Some ( it. into ( ) ) != sized_trait)
559
- . for_each ( |it| push_new_def ( it. into ( ) ) ) ;
560
- } else if let Definition :: Function ( function) = def {
561
- walk_and_push_ty ( db, & function. ret_type ( db) , & mut push_new_def) ;
562
-
563
- let krate = function. module ( db) . krate ( ) ;
564
- let sized_trait =
565
- db. lang_item ( krate. into ( ) , LangItem :: Sized ) . and_then ( |lang_item| lang_item. as_trait ( ) ) ;
566
- for param in function. params_without_self ( db) {
567
- if let Some ( type_param) = param. ty ( ) . as_type_param ( db) {
568
- type_param
569
- . trait_bounds ( db)
570
- . into_iter ( )
571
- . filter ( |& it| Some ( it. into ( ) ) != sized_trait)
572
- . for_each ( |it| push_new_def ( it. into ( ) ) ) ;
573
- } else {
559
+ let ty = match def {
560
+ Definition :: Local ( it) => Some ( it. ty ( db) ) ,
561
+ Definition :: Field ( field) => Some ( field. ty ( db) ) ,
562
+ Definition :: TupleField ( field) => Some ( field. ty ( db) ) ,
563
+ Definition :: Const ( it) => Some ( it. ty ( db) ) ,
564
+ Definition :: Static ( it) => Some ( it. ty ( db) ) ,
565
+ Definition :: Function ( func) => {
566
+ for param in func. assoc_fn_params ( db) {
574
567
walk_and_push_ty ( db, param. ty ( ) , & mut push_new_def) ;
575
568
}
569
+ Some ( func. ret_type ( db) )
576
570
}
577
- } else {
578
- let ty = match def {
579
- Definition :: Local ( it) => it. ty ( db) ,
580
- Definition :: GenericParam ( hir:: GenericParam :: ConstParam ( it) ) => it. ty ( db) ,
581
- Definition :: Field ( field) => field. ty ( db) ,
582
- _ => return HoverAction :: goto_type_from_targets ( db, targets, edition) ,
583
- } ;
584
-
571
+ Definition :: GenericParam ( hir:: GenericParam :: ConstParam ( it) ) => Some ( it. ty ( db) ) ,
572
+ Definition :: GenericParam ( hir:: GenericParam :: TypeParam ( it) ) => Some ( it. ty ( db) ) ,
573
+ _ => None ,
574
+ } ;
575
+ if let Some ( ty) = ty {
585
576
walk_and_push_ty ( db, & ty, & mut push_new_def) ;
586
577
}
587
578
@@ -608,6 +599,14 @@ fn walk_and_push_ty(
608
599
traits. for_each ( |it| push_new_def ( it. into ( ) ) ) ;
609
600
} else if let Some ( trait_) = t. as_associated_type_parent_trait ( db) {
610
601
push_new_def ( trait_. into ( ) ) ;
602
+ } else if let Some ( tp) = t. as_type_param ( db) {
603
+ let sized_trait = db
604
+ . lang_item ( t. krate ( db) . into ( ) , LangItem :: Sized )
605
+ . and_then ( |lang_item| lang_item. as_trait ( ) ) ;
606
+ tp. trait_bounds ( db)
607
+ . into_iter ( )
608
+ . filter ( |& it| Some ( it. into ( ) ) != sized_trait)
609
+ . for_each ( |it| push_new_def ( it. into ( ) ) ) ;
611
610
}
612
611
} ) ;
613
612
}
0 commit comments