From 54d053c881514b024ba399ce2edc678e3f710ab7 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 4 Dec 2018 23:52:14 +0300 Subject: minor --- crates/ra_hir/src/function/mod.rs | 8 ++++++-- crates/ra_hir/src/lib.rs | 16 +++++++++++----- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/crates/ra_hir/src/function/mod.rs b/crates/ra_hir/src/function/mod.rs index a6757601e..e00bca6e3 100644 --- a/crates/ra_hir/src/function/mod.rs +++ b/crates/ra_hir/src/function/mod.rs @@ -27,6 +27,11 @@ pub struct Function { } impl Function { + pub(crate) fn new(def_id: DefId) -> Function { + let fn_id = FnId(def_id); + Function { fn_id } + } + pub fn guess_from_source( db: &impl HirDatabase, file_id: FileId, @@ -42,8 +47,7 @@ impl Function { module_id: module.module_id, source_item_id, }; - let fn_id = FnId(def_loc.id(db)); - Ok(Some(Function { fn_id })) + Ok(Some(Function::new(def_loc.id(db)))) } pub fn guess_for_name_ref( diff --git a/crates/ra_hir/src/lib.rs b/crates/ra_hir/src/lib.rs index dbcc5e46d..9168dad3b 100644 --- a/crates/ra_hir/src/lib.rs +++ b/crates/ra_hir/src/lib.rs @@ -41,6 +41,8 @@ pub use self::{ pub use self::function::FnSignatureInfo; +/// Def's are a core concept of hir. A `Def` is an Item (function, module, etc) +/// in a specific module. #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] pub struct DefId(u32); ra_db::impl_numeric_id!(DefId); @@ -61,13 +63,13 @@ pub struct DefLoc { } impl DefId { - pub fn loc(self, db: &impl AsRef>) -> DefLoc { + pub(crate) fn loc(self, db: &impl AsRef>) -> DefLoc { db.as_ref().id2loc(self) } } impl DefLoc { - pub fn id(&self, db: &impl AsRef>) -> DefId { + pub(crate) fn id(&self, db: &impl AsRef>) -> DefId { db.as_ref().loc2id(&self) } } @@ -83,10 +85,14 @@ impl DefId { let loc = self.loc(db); let res = match loc.kind { DefKind::Module => { - let descr = Module::new(db, loc.source_root_id, loc.module_id)?; - Def::Module(descr) + let module = Module::new(db, loc.source_root_id, loc.module_id)?; + Def::Module(module) } - DefKind::Item | DefKind::Function => Def::Item, + DefKind::Function => { + let function = Function::new(self); + Def::Function(function) + } + DefKind::Item => Def::Item, }; Ok(res) } -- cgit v1.2.3