diff options
Diffstat (limited to 'crates/ra_hir/src/code_model_impl/function.rs')
-rw-r--r-- | crates/ra_hir/src/code_model_impl/function.rs | 50 |
1 files changed, 0 insertions, 50 deletions
diff --git a/crates/ra_hir/src/code_model_impl/function.rs b/crates/ra_hir/src/code_model_impl/function.rs deleted file mode 100644 index f8bd0f784..000000000 --- a/crates/ra_hir/src/code_model_impl/function.rs +++ /dev/null | |||
@@ -1,50 +0,0 @@ | |||
1 | use std::sync::Arc; | ||
2 | |||
3 | use ra_syntax::ast::{self, NameOwner, TypeAscriptionOwner}; | ||
4 | |||
5 | use crate::{ | ||
6 | Name, AsName, Function, FnSignature, | ||
7 | type_ref::{TypeRef, Mutability}, | ||
8 | DefDatabase, | ||
9 | }; | ||
10 | |||
11 | impl FnSignature { | ||
12 | pub(crate) fn fn_signature_query(db: &impl DefDatabase, func: Function) -> Arc<FnSignature> { | ||
13 | let (_, node) = func.source(db); | ||
14 | let name = node.name().map(|n| n.as_name()).unwrap_or_else(Name::missing); | ||
15 | let mut params = Vec::new(); | ||
16 | let mut has_self_param = false; | ||
17 | if let Some(param_list) = node.param_list() { | ||
18 | if let Some(self_param) = param_list.self_param() { | ||
19 | let self_type = if let Some(type_ref) = self_param.ascribed_type() { | ||
20 | TypeRef::from_ast(type_ref) | ||
21 | } else { | ||
22 | let self_type = TypeRef::Path(Name::self_type().into()); | ||
23 | match self_param.kind() { | ||
24 | ast::SelfParamKind::Owned => self_type, | ||
25 | ast::SelfParamKind::Ref => { | ||
26 | TypeRef::Reference(Box::new(self_type), Mutability::Shared) | ||
27 | } | ||
28 | ast::SelfParamKind::MutRef => { | ||
29 | TypeRef::Reference(Box::new(self_type), Mutability::Mut) | ||
30 | } | ||
31 | } | ||
32 | }; | ||
33 | params.push(self_type); | ||
34 | has_self_param = true; | ||
35 | } | ||
36 | for param in param_list.params() { | ||
37 | let type_ref = TypeRef::from_ast_opt(param.ascribed_type()); | ||
38 | params.push(type_ref); | ||
39 | } | ||
40 | } | ||
41 | let ret_type = if let Some(type_ref) = node.ret_type().and_then(|rt| rt.type_ref()) { | ||
42 | TypeRef::from_ast(type_ref) | ||
43 | } else { | ||
44 | TypeRef::unit() | ||
45 | }; | ||
46 | |||
47 | let sig = FnSignature { name, params, ret_type, has_self_param }; | ||
48 | Arc::new(sig) | ||
49 | } | ||
50 | } | ||