aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src/function.rs
diff options
context:
space:
mode:
authorbors[bot] <bors[bot]@users.noreply.github.com>2018-12-27 21:08:59 +0000
committerbors[bot] <bors[bot]@users.noreply.github.com>2018-12-27 21:08:59 +0000
commite80021cbd0bcfea82f3b855e13a409c73b563673 (patch)
treea10ff2ac8882d9b0373bc5449a44e40696538a45 /crates/ra_hir/src/function.rs
parentefb63a7666cc9532d97fa7e0da14b540ae8bd5df (diff)
parentbc833216d7190d7a270ed2d831abc134fab91cfb (diff)
Merge #348
348: cleanups r=matklad a=matklad Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ra_hir/src/function.rs')
-rw-r--r--crates/ra_hir/src/function.rs23
1 files changed, 11 insertions, 12 deletions
diff --git a/crates/ra_hir/src/function.rs b/crates/ra_hir/src/function.rs
index d4159cee2..5a44132fc 100644
--- a/crates/ra_hir/src/function.rs
+++ b/crates/ra_hir/src/function.rs
@@ -11,43 +11,42 @@ use ra_syntax::{
11 ast::{self, AstNode, DocCommentsOwner, NameOwner}, 11 ast::{self, AstNode, DocCommentsOwner, NameOwner},
12}; 12};
13 13
14use crate::{ DefId, HirDatabase, ty::InferenceResult, Module }; 14use crate::{DefId, DefKind, HirDatabase, ty::InferenceResult, Module};
15 15
16pub use self::scope::FnScopes; 16pub use self::scope::FnScopes;
17 17
18#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
19pub struct FnId(pub(crate) DefId);
20
21#[derive(Debug)] 18#[derive(Debug)]
22pub struct Function { 19pub struct Function {
23 pub(crate) fn_id: FnId, 20 def_id: DefId,
24} 21}
25 22
26impl Function { 23impl Function {
27 pub(crate) fn new(def_id: DefId) -> Function { 24 pub(crate) fn new(def_id: DefId) -> Function {
28 let fn_id = FnId(def_id); 25 Function { def_id }
29 Function { fn_id }
30 } 26 }
31 27
32 pub fn syntax(&self, db: &impl HirDatabase) -> ast::FnDefNode { 28 pub fn syntax(&self, db: &impl HirDatabase) -> ast::FnDefNode {
33 db.fn_syntax(self.fn_id) 29 let def_loc = self.def_id.loc(db);
30 assert!(def_loc.kind == DefKind::Function);
31 let syntax = db.file_item(def_loc.source_item_id);
32 ast::FnDef::cast(syntax.borrowed()).unwrap().owned()
34 } 33 }
35 34
36 pub fn scopes(&self, db: &impl HirDatabase) -> Arc<FnScopes> { 35 pub fn scopes(&self, db: &impl HirDatabase) -> Arc<FnScopes> {
37 db.fn_scopes(self.fn_id) 36 db.fn_scopes(self.def_id)
38 } 37 }
39 38
40 pub fn signature_info(&self, db: &impl HirDatabase) -> Option<FnSignatureInfo> { 39 pub fn signature_info(&self, db: &impl HirDatabase) -> Option<FnSignatureInfo> {
41 let syntax = db.fn_syntax(self.fn_id); 40 let syntax = self.syntax(db);
42 FnSignatureInfo::new(syntax.borrowed()) 41 FnSignatureInfo::new(syntax.borrowed())
43 } 42 }
44 43
45 pub fn infer(&self, db: &impl HirDatabase) -> Cancelable<Arc<InferenceResult>> { 44 pub fn infer(&self, db: &impl HirDatabase) -> Cancelable<Arc<InferenceResult>> {
46 db.infer(self.fn_id) 45 db.infer(self.def_id)
47 } 46 }
48 47
49 pub fn module(&self, db: &impl HirDatabase) -> Cancelable<Module> { 48 pub fn module(&self, db: &impl HirDatabase) -> Cancelable<Module> {
50 self.fn_id.0.module(db) 49 self.def_id.module(db)
51 } 50 }
52} 51}
53 52