aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir/src')
-rw-r--r--crates/ra_hir/src/code_model.rs31
1 files changed, 19 insertions, 12 deletions
diff --git a/crates/ra_hir/src/code_model.rs b/crates/ra_hir/src/code_model.rs
index e91abf6f5..146e7820e 100644
--- a/crates/ra_hir/src/code_model.rs
+++ b/crates/ra_hir/src/code_model.rs
@@ -139,6 +139,17 @@ impl ModuleDef {
139 } 139 }
140} 140}
141 141
142impl From<ModuleDef> for ItemInNs {
143 fn from(module_def: ModuleDef) -> Self {
144 match module_def {
145 ModuleDef::Static(_) | ModuleDef::Const(_) | ModuleDef::Function(_) => {
146 ItemInNs::Values(module_def.into())
147 }
148 _ => ItemInNs::Types(module_def.into()),
149 }
150 }
151}
152
142pub use hir_def::{ 153pub use hir_def::{
143 attr::Attrs, item_scope::ItemInNs, visibility::Visibility, AssocItemId, AssocItemLoc, 154 attr::Attrs, item_scope::ItemInNs, visibility::Visibility, AssocItemId, AssocItemLoc,
144}; 155};
@@ -275,19 +286,9 @@ impl Module {
275 pub fn find_use_path( 286 pub fn find_use_path(
276 self, 287 self,
277 db: &dyn HirDatabase, 288 db: &dyn HirDatabase,
278 item: ModuleDef, 289 item: ItemInNs,
279 ) -> Option<hir_def::path::ModPath> { 290 ) -> Option<hir_def::path::ModPath> {
280 // FIXME expose namespace choice 291 hir_def::find_path::find_path(db.upcast(), item, self.into())
281 hir_def::find_path::find_path(db.upcast(), determine_item_namespace(item), self.into())
282 }
283}
284
285fn determine_item_namespace(module_def: ModuleDef) -> ItemInNs {
286 match module_def {
287 ModuleDef::Static(_) | ModuleDef::Const(_) | ModuleDef::Function(_) => {
288 ItemInNs::Values(module_def.into())
289 }
290 _ => ItemInNs::Types(module_def.into()),
291 } 292 }
292} 293}
293 294
@@ -759,6 +760,12 @@ impl MacroDef {
759 } 760 }
760} 761}
761 762
763impl From<MacroDef> for ItemInNs {
764 fn from(macro_def: MacroDef) -> Self {
765 ItemInNs::Macros(macro_def.into())
766 }
767}
768
762/// Invariant: `inner.as_assoc_item(db).is_some()` 769/// Invariant: `inner.as_assoc_item(db).is_some()`
763/// We do not actively enforce this invariant. 770/// We do not actively enforce this invariant.
764#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] 771#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]