@@ -108,7 +108,6 @@ pub use {
108108 attr:: { Attr , Attrs , AttrsWithOwner , Documentation } ,
109109 find_path:: PrefixKind ,
110110 import_map,
111- item_scope:: ItemInNs , // FIXME: don't re-export ItemInNs, as it uses raw ids.
112111 nameres:: ModuleSource ,
113112 path:: { ModPath , PathKind } ,
114113 type_ref:: { Mutability , TypeRef } ,
@@ -194,9 +193,11 @@ impl Crate {
194193 query : import_map:: Query ,
195194 ) -> impl Iterator < Item = Either < ModuleDef , MacroDef > > {
196195 let _p = profile:: span ( "query_external_importables" ) ;
197- import_map:: search_dependencies ( db, self . into ( ) , query) . into_iter ( ) . map ( |item| match item {
198- ItemInNs :: Types ( mod_id) | ItemInNs :: Values ( mod_id) => Either :: Left ( mod_id. into ( ) ) ,
199- ItemInNs :: Macros ( mac_id) => Either :: Right ( mac_id. into ( ) ) ,
196+ import_map:: search_dependencies ( db, self . into ( ) , query) . into_iter ( ) . map ( |item| {
197+ match ItemInNs :: from ( item) {
198+ ItemInNs :: Types ( mod_id) | ItemInNs :: Values ( mod_id) => Either :: Left ( mod_id) ,
199+ ItemInNs :: Macros ( mac_id) => Either :: Right ( mac_id) ,
200+ }
200201 } )
201202 }
202203
@@ -656,7 +657,7 @@ impl Module {
656657 /// Finds a path that can be used to refer to the given item from within
657658 /// this module, if possible.
658659 pub fn find_use_path ( self , db : & dyn DefDatabase , item : impl Into < ItemInNs > ) -> Option < ModPath > {
659- hir_def:: find_path:: find_path ( db, item. into ( ) , self . into ( ) )
660+ hir_def:: find_path:: find_path ( db, item. into ( ) . into ( ) , self . into ( ) )
660661 }
661662
662663 /// Finds a path that can be used to refer to the given item from within
@@ -667,7 +668,7 @@ impl Module {
667668 item : impl Into < ItemInNs > ,
668669 prefix_kind : PrefixKind ,
669670 ) -> Option < ModPath > {
670- hir_def:: find_path:: find_path_prefixed ( db, item. into ( ) , self . into ( ) , prefix_kind)
671+ hir_def:: find_path:: find_path_prefixed ( db, item. into ( ) . into ( ) , self . into ( ) , prefix_kind)
671672 }
672673}
673674
@@ -1567,6 +1568,39 @@ impl MacroDef {
15671568 }
15681569}
15691570
1571+ #[ derive( Clone , Copy , PartialEq , Eq , Debug , Hash ) ]
1572+ pub enum ItemInNs {
1573+ Types ( ModuleDef ) ,
1574+ Values ( ModuleDef ) ,
1575+ Macros ( MacroDef ) ,
1576+ }
1577+
1578+ impl From < MacroDef > for ItemInNs {
1579+ fn from ( it : MacroDef ) -> Self {
1580+ Self :: Macros ( it)
1581+ }
1582+ }
1583+
1584+ impl From < ModuleDef > for ItemInNs {
1585+ fn from ( module_def : ModuleDef ) -> Self {
1586+ match module_def {
1587+ ModuleDef :: Static ( _) | ModuleDef :: Const ( _) | ModuleDef :: Function ( _) => {
1588+ ItemInNs :: Values ( module_def)
1589+ }
1590+ _ => ItemInNs :: Types ( module_def) ,
1591+ }
1592+ }
1593+ }
1594+
1595+ impl ItemInNs {
1596+ pub fn as_module_def ( self ) -> Option < ModuleDef > {
1597+ match self {
1598+ ItemInNs :: Types ( id) | ItemInNs :: Values ( id) => Some ( id) ,
1599+ ItemInNs :: Macros ( _) => None ,
1600+ }
1601+ }
1602+ }
1603+
15701604/// Invariant: `inner.as_assoc_item(db).is_some()`
15711605/// We do not actively enforce this invariant.
15721606#[ derive( Debug , Copy , Clone , PartialEq , Eq , Hash ) ]
0 commit comments