diff options
Diffstat (limited to 'crates/ra_hir/src/code_model_impl/konst.rs')
-rw-r--r-- | crates/ra_hir/src/code_model_impl/konst.rs | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/crates/ra_hir/src/code_model_impl/konst.rs b/crates/ra_hir/src/code_model_impl/konst.rs new file mode 100644 index 000000000..ecf4c8122 --- /dev/null +++ b/crates/ra_hir/src/code_model_impl/konst.rs | |||
@@ -0,0 +1,37 @@ | |||
1 | use std::sync::Arc; | ||
2 | |||
3 | use ra_syntax::ast::{self, NameOwner}; | ||
4 | |||
5 | use crate::{ | ||
6 | Name, AsName, Const, ConstSignature, Static, | ||
7 | type_ref::{TypeRef}, | ||
8 | PersistentHirDatabase, | ||
9 | }; | ||
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 | |||
21 | impl ConstSignature { | ||
22 | pub(crate) fn const_signature_query( | ||
23 | db: &impl PersistentHirDatabase, | ||
24 | konst: Const, | ||
25 | ) -> Arc<ConstSignature> { | ||
26 | let (_, node) = konst.source(db); | ||
27 | const_signature_for(&*node, node.type_ref()) | ||
28 | } | ||
29 | |||
30 | pub(crate) fn static_signature_query( | ||
31 | db: &impl PersistentHirDatabase, | ||
32 | konst: Static, | ||
33 | ) -> Arc<ConstSignature> { | ||
34 | let (_, node) = konst.source(db); | ||
35 | const_signature_for(&*node, node.type_ref()) | ||
36 | } | ||
37 | } | ||