Skip to content

Commit 54d053c

Browse files
committed
minor
1 parent d8b0379 commit 54d053c

File tree

2 files changed

+17
-7
lines changed

2 files changed

+17
-7
lines changed

crates/ra_hir/src/function/mod.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ pub struct Function {
2727
}
2828

2929
impl Function {
30+
pub(crate) fn new(def_id: DefId) -> Function {
31+
let fn_id = FnId(def_id);
32+
Function { fn_id }
33+
}
34+
3035
pub fn guess_from_source(
3136
db: &impl HirDatabase,
3237
file_id: FileId,
@@ -42,8 +47,7 @@ impl Function {
4247
module_id: module.module_id,
4348
source_item_id,
4449
};
45-
let fn_id = FnId(def_loc.id(db));
46-
Ok(Some(Function { fn_id }))
50+
Ok(Some(Function::new(def_loc.id(db))))
4751
}
4852

4953
pub fn guess_for_name_ref(

crates/ra_hir/src/lib.rs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ pub use self::{
4141

4242
pub use self::function::FnSignatureInfo;
4343

44+
/// Def's are a core concept of hir. A `Def` is an Item (function, module, etc)
45+
/// in a specific module.
4446
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
4547
pub struct DefId(u32);
4648
ra_db::impl_numeric_id!(DefId);
@@ -61,13 +63,13 @@ pub struct DefLoc {
6163
}
6264

6365
impl DefId {
64-
pub fn loc(self, db: &impl AsRef<LocationIntener<DefLoc, DefId>>) -> DefLoc {
66+
pub(crate) fn loc(self, db: &impl AsRef<LocationIntener<DefLoc, DefId>>) -> DefLoc {
6567
db.as_ref().id2loc(self)
6668
}
6769
}
6870

6971
impl DefLoc {
70-
pub fn id(&self, db: &impl AsRef<LocationIntener<DefLoc, DefId>>) -> DefId {
72+
pub(crate) fn id(&self, db: &impl AsRef<LocationIntener<DefLoc, DefId>>) -> DefId {
7173
db.as_ref().loc2id(&self)
7274
}
7375
}
@@ -83,10 +85,14 @@ impl DefId {
8385
let loc = self.loc(db);
8486
let res = match loc.kind {
8587
DefKind::Module => {
86-
let descr = Module::new(db, loc.source_root_id, loc.module_id)?;
87-
Def::Module(descr)
88+
let module = Module::new(db, loc.source_root_id, loc.module_id)?;
89+
Def::Module(module)
8890
}
89-
DefKind::Item | DefKind::Function => Def::Item,
91+
DefKind::Function => {
92+
let function = Function::new(self);
93+
Def::Function(function)
94+
}
95+
DefKind::Item => Def::Item,
9096
};
9197
Ok(res)
9298
}

0 commit comments

Comments
 (0)