diff options
author | Ville Penttinen <[email protected]> | 2019-02-25 08:29:56 +0000 |
---|---|---|
committer | Ville Penttinen <[email protected]> | 2019-02-25 08:55:39 +0000 |
commit | cff9a7dfadc6069bbc7b49c3ceb8497c78d426ab (patch) | |
tree | cdf89bf7002a9d38afd856fef09d7673a26ed983 /crates | |
parent | 29f93a79069cf929fbc6d4efa194a0ab18bb1f45 (diff) |
Move ConstSignature creation to a single method
Diffstat (limited to 'crates')
-rw-r--r-- | crates/ra_hir/src/code_model_impl/konst.rs | 30 |
1 files changed, 13 insertions, 17 deletions
diff --git a/crates/ra_hir/src/code_model_impl/konst.rs b/crates/ra_hir/src/code_model_impl/konst.rs index d7722ccc2..ecf4c8122 100644 --- a/crates/ra_hir/src/code_model_impl/konst.rs +++ b/crates/ra_hir/src/code_model_impl/konst.rs | |||
@@ -1,6 +1,6 @@ | |||
1 | use std::sync::Arc; | 1 | use std::sync::Arc; |
2 | 2 | ||
3 | use ra_syntax::ast::{NameOwner}; | 3 | use ra_syntax::ast::{self, NameOwner}; |
4 | 4 | ||
5 | use crate::{ | 5 | use crate::{ |
6 | Name, AsName, Const, ConstSignature, Static, | 6 | Name, AsName, Const, ConstSignature, Static, |
@@ -8,20 +8,23 @@ use crate::{ | |||
8 | PersistentHirDatabase, | 8 | PersistentHirDatabase, |
9 | }; | 9 | }; |
10 | 10 | ||
11 | fn const_signature_for<N: NameOwner>( | ||
12 | node: &N, | ||
13 | type_ref: Option<&ast::TypeRef>, | ||
14 | ) -> Arc<ConstSignature> { | ||
15 | let name = node.name().map(|n| n.as_name()).unwrap_or_else(Name::missing); | ||
16 | let type_ref = TypeRef::from_ast_opt(type_ref); | ||
17 | let sig = ConstSignature { name, type_ref }; | ||
18 | Arc::new(sig) | ||
19 | } | ||
20 | |||
11 | impl ConstSignature { | 21 | impl ConstSignature { |
12 | pub(crate) fn const_signature_query( | 22 | pub(crate) fn const_signature_query( |
13 | db: &impl PersistentHirDatabase, | 23 | db: &impl PersistentHirDatabase, |
14 | konst: Const, | 24 | konst: Const, |
15 | ) -> Arc<ConstSignature> { | 25 | ) -> Arc<ConstSignature> { |
16 | let (_, node) = konst.source(db); | 26 | let (_, node) = konst.source(db); |
17 | 27 | const_signature_for(&*node, node.type_ref()) | |
18 | let name = node.name().map(|n| n.as_name()).unwrap_or_else(Name::missing); | ||
19 | |||
20 | let type_ref = TypeRef::from_ast_opt(node.type_ref()); | ||
21 | |||
22 | let sig = ConstSignature { name, type_ref }; | ||
23 | |||
24 | Arc::new(sig) | ||
25 | } | 28 | } |
26 | 29 | ||
27 | pub(crate) fn static_signature_query( | 30 | pub(crate) fn static_signature_query( |
@@ -29,13 +32,6 @@ impl ConstSignature { | |||
29 | konst: Static, | 32 | konst: Static, |
30 | ) -> Arc<ConstSignature> { | 33 | ) -> Arc<ConstSignature> { |
31 | let (_, node) = konst.source(db); | 34 | let (_, node) = konst.source(db); |
32 | 35 | const_signature_for(&*node, node.type_ref()) | |
33 | let name = node.name().map(|n| n.as_name()).unwrap_or_else(Name::missing); | ||
34 | |||
35 | let type_ref = TypeRef::from_ast_opt(node.type_ref()); | ||
36 | |||
37 | let sig = ConstSignature { name, type_ref }; | ||
38 | |||
39 | Arc::new(sig) | ||
40 | } | 36 | } |
41 | } | 37 | } |