@@ -186,6 +186,22 @@ impl ModuleDef {
186186
187187 module. visibility_of ( db, self )
188188 }
189+
190+ pub fn name ( self , db : & dyn HirDatabase ) -> Option < Name > {
191+ match self {
192+ ModuleDef :: Adt ( it) => Some ( it. name ( db) ) ,
193+ ModuleDef :: Trait ( it) => Some ( it. name ( db) ) ,
194+ ModuleDef :: Function ( it) => Some ( it. name ( db) ) ,
195+ ModuleDef :: EnumVariant ( it) => Some ( it. name ( db) ) ,
196+ ModuleDef :: TypeAlias ( it) => Some ( it. name ( db) ) ,
197+
198+ ModuleDef :: Module ( it) => it. name ( db) ,
199+ ModuleDef :: Const ( it) => it. name ( db) ,
200+ ModuleDef :: Static ( it) => it. name ( db) ,
201+
202+ ModuleDef :: BuiltinType ( it) => Some ( it. as_name ( ) ) ,
203+ }
204+ }
189205}
190206
191207pub use hir_def:: {
@@ -1382,8 +1398,8 @@ impl Type {
13821398 }
13831399
13841400 /// Returns a flattened list of all ADTs and Traits mentioned in the type
1385- pub fn flattened_type_items ( & self , db : & dyn HirDatabase ) -> Vec < AdtOrTrait > {
1386- fn push_new_item ( item : AdtOrTrait , acc : & mut Vec < AdtOrTrait > ) {
1401+ pub fn flattened_type_items ( & self , db : & dyn HirDatabase ) -> Vec < ModuleDef > {
1402+ fn push_new_item ( item : ModuleDef , acc : & mut Vec < ModuleDef > ) {
13871403 if !acc. contains ( & item) {
13881404 acc. push ( item) ;
13891405 }
@@ -1392,7 +1408,7 @@ impl Type {
13921408 fn push_bounds (
13931409 db : & dyn HirDatabase ,
13941410 predicates : & [ GenericPredicate ] ,
1395- acc : & mut Vec < AdtOrTrait > ,
1411+ acc : & mut Vec < ModuleDef > ,
13961412 ) {
13971413 for p in predicates. iter ( ) {
13981414 match p {
@@ -1407,13 +1423,13 @@ impl Type {
14071423 }
14081424
14091425 // TypeWalk::walk does not preserve items order!
1410- fn walk_substs ( db : & dyn HirDatabase , substs : & Substs , acc : & mut Vec < AdtOrTrait > ) {
1426+ fn walk_substs ( db : & dyn HirDatabase , substs : & Substs , acc : & mut Vec < ModuleDef > ) {
14111427 for ty in substs. iter ( ) {
14121428 walk_type ( db, ty, acc) ;
14131429 }
14141430 }
14151431
1416- fn walk_type ( db : & dyn HirDatabase , ty : & Ty , acc : & mut Vec < AdtOrTrait > ) {
1432+ fn walk_type ( db : & dyn HirDatabase , ty : & Ty , acc : & mut Vec < ModuleDef > ) {
14171433 match ty. strip_references ( ) {
14181434 Ty :: Apply ( ApplicationTy { ctor, parameters, .. } ) => {
14191435 match ctor {
@@ -1468,7 +1484,7 @@ impl Type {
14681484 }
14691485 }
14701486
1471- let mut res: Vec < AdtOrTrait > = Vec :: new ( ) ; // not a Set to preserve the order
1487+ let mut res: Vec < ModuleDef > = Vec :: new ( ) ; // not a Set to preserve the order
14721488 walk_type ( db, & self . ty . value , & mut res) ;
14731489 res
14741490 }
@@ -1580,26 +1596,3 @@ pub trait HasVisibility {
15801596 vis. is_visible_from ( db. upcast ( ) , module. id )
15811597 }
15821598}
1583-
1584- #[ derive( Clone , Copy , Debug , PartialEq , Eq , Hash ) ]
1585- pub enum AdtOrTrait {
1586- Adt ( Adt ) ,
1587- Trait ( Trait ) ,
1588- }
1589- impl_froms ! ( AdtOrTrait : Adt , Trait ) ;
1590-
1591- impl AdtOrTrait {
1592- pub fn module ( self , db : & dyn HirDatabase ) -> Module {
1593- match self {
1594- AdtOrTrait :: Adt ( adt) => adt. module ( db) ,
1595- AdtOrTrait :: Trait ( trait_) => trait_. module ( db) ,
1596- }
1597- }
1598-
1599- pub fn name ( self , db : & dyn HirDatabase ) -> Name {
1600- match self {
1601- AdtOrTrait :: Adt ( adt) => adt. name ( db) ,
1602- AdtOrTrait :: Trait ( trait_) => trait_. name ( db) ,
1603- }
1604- }
1605- }
0 commit comments