aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src/code_model_impl/function.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir/src/code_model_impl/function.rs')
-rw-r--r--crates/ra_hir/src/code_model_impl/function.rs23
1 files changed, 7 insertions, 16 deletions
diff --git a/crates/ra_hir/src/code_model_impl/function.rs b/crates/ra_hir/src/code_model_impl/function.rs
index c68c6bfbf..e0dd4d629 100644
--- a/crates/ra_hir/src/code_model_impl/function.rs
+++ b/crates/ra_hir/src/code_model_impl/function.rs
@@ -2,41 +2,32 @@ mod scope;
2 2
3use std::sync::Arc; 3use std::sync::Arc;
4 4
5use ra_syntax::{TreeArc, ast::{self, NameOwner}}; 5use ra_syntax::ast::{self, NameOwner};
6 6
7use crate::{ 7use crate::{
8 DefId, HirDatabase, Name, AsName, Function, FnSignature, Module, 8 HirDatabase, Name, AsName, Function, FnSignature,
9 type_ref::{TypeRef, Mutability}, 9 type_ref::{TypeRef, Mutability},
10 expr::Body, 10 expr::Body,
11 impl_block::ImplBlock, 11 impl_block::ImplBlock,
12 code_model_impl::def_id_to_ast,
13}; 12};
14 13
15pub use self::scope::{FnScopes, ScopesWithSyntaxMapping, ScopeEntryWithSyntax}; 14pub use self::scope::{FnScopes, ScopesWithSyntaxMapping, ScopeEntryWithSyntax};
16 15
17impl Function { 16impl Function {
18 pub(crate) fn new(def_id: DefId) -> Function {
19 Function { def_id }
20 }
21
22 pub(crate) fn body(&self, db: &impl HirDatabase) -> Arc<Body> { 17 pub(crate) fn body(&self, db: &impl HirDatabase) -> Arc<Body> {
23 db.body_hir(self.def_id) 18 db.body_hir(*self)
24 }
25
26 pub(crate) fn module(&self, db: &impl HirDatabase) -> Module {
27 self.def_id.module(db)
28 } 19 }
29 20
30 /// The containing impl block, if this is a method. 21 /// The containing impl block, if this is a method.
31 pub(crate) fn impl_block(&self, db: &impl HirDatabase) -> Option<ImplBlock> { 22 pub(crate) fn impl_block(&self, db: &impl HirDatabase) -> Option<ImplBlock> {
32 self.def_id.impl_block(db) 23 let module_impls = db.impls_in_module(self.module(db));
24 ImplBlock::containing(module_impls, (*self).into())
33 } 25 }
34} 26}
35 27
36impl FnSignature { 28impl FnSignature {
37 pub(crate) fn fn_signature_query(db: &impl HirDatabase, def_id: DefId) -> Arc<FnSignature> { 29 pub(crate) fn fn_signature_query(db: &impl HirDatabase, func: Function) -> Arc<FnSignature> {
38 // FIXME: we're using def_id_to_ast here to avoid returning Cancelable... this is a bit hacky 30 let (_, node) = func.source(db);
39 let node: TreeArc<ast::FnDef> = def_id_to_ast(db, def_id).1;
40 let name = node 31 let name = node
41 .name() 32 .name()
42 .map(|n| n.as_name()) 33 .map(|n| n.as_name())