From 944f28fe5bf2b8e4316cc67bf5f824333fc4f180 Mon Sep 17 00:00:00 2001 From: Kirill Bulatov Date: Mon, 23 Mar 2020 13:34:56 +0200 Subject: Use more generic public api --- crates/ra_hir/src/code_model.rs | 21 ++------------------- crates/ra_hir/src/from_id.rs | 21 +++++++++++++++++++-- 2 files changed, 21 insertions(+), 21 deletions(-) (limited to 'crates/ra_hir/src') diff --git a/crates/ra_hir/src/code_model.rs b/crates/ra_hir/src/code_model.rs index 9e4aa6022..c5cfd875f 100644 --- a/crates/ra_hir/src/code_model.rs +++ b/crates/ra_hir/src/code_model.rs @@ -143,17 +143,6 @@ impl ModuleDef { } } -impl From for ItemInNs { - fn from(module_def: ModuleDef) -> Self { - match module_def { - ModuleDef::Static(_) | ModuleDef::Const(_) | ModuleDef::Function(_) => { - ItemInNs::Values(module_def.into()) - } - _ => ItemInNs::Types(module_def.into()), - } - } -} - pub use hir_def::{ attr::Attrs, item_scope::ItemInNs, visibility::Visibility, AssocItemId, AssocItemLoc, }; @@ -290,9 +279,9 @@ impl Module { pub fn find_use_path( self, db: &dyn DefDatabase, - item: ItemInNs, + item: impl Into, ) -> Option { - hir_def::find_path::find_path(db, item, self.into()) + hir_def::find_path::find_path(db, item.into(), self.into()) } } @@ -764,12 +753,6 @@ impl MacroDef { } } -impl From for ItemInNs { - fn from(macro_def: MacroDef) -> Self { - ItemInNs::Macros(macro_def.into()) - } -} - /// Invariant: `inner.as_assoc_item(db).is_some()` /// We do not actively enforce this invariant. #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] diff --git a/crates/ra_hir/src/from_id.rs b/crates/ra_hir/src/from_id.rs index c179b13c6..62fb52e72 100644 --- a/crates/ra_hir/src/from_id.rs +++ b/crates/ra_hir/src/from_id.rs @@ -9,8 +9,8 @@ use hir_def::{ }; use crate::{ - Adt, AssocItem, AttrDef, DefWithBody, EnumVariant, GenericDef, Local, ModuleDef, StructField, - VariantDef, + code_model::ItemInNs, Adt, AssocItem, AttrDef, DefWithBody, EnumVariant, GenericDef, Local, + MacroDef, ModuleDef, StructField, VariantDef, }; macro_rules! from_id { @@ -228,3 +228,20 @@ impl From<(DefWithBodyId, PatId)> for Local { Local { parent, pat_id } } } + +impl From for ItemInNs { + fn from(macro_def: MacroDef) -> Self { + ItemInNs::Macros(macro_def.into()) + } +} + +impl From for ItemInNs { + fn from(module_def: ModuleDef) -> Self { + match module_def { + ModuleDef::Static(_) | ModuleDef::Const(_) | ModuleDef::Function(_) => { + ItemInNs::Values(module_def.into()) + } + _ => ItemInNs::Types(module_def.into()), + } + } +} -- cgit v1.2.3