diff options
author | bors[bot] <bors[bot]@users.noreply.github.com> | 2019-02-25 12:03:57 +0000 |
---|---|---|
committer | bors[bot] <bors[bot]@users.noreply.github.com> | 2019-02-25 12:03:57 +0000 |
commit | 7c9acf2f834c582d9cad4f7d0679a0697c591432 (patch) | |
tree | 5829e5a0e4567c532a5d430ed9406a8cd072f5ca /crates/ra_hir/src/code_model_impl | |
parent | 4f67df904252c5fbbf3b892bb2e8405778bc904a (diff) | |
parent | cff9a7dfadc6069bbc7b49c3ceb8497c78d426ab (diff) |
Merge #897
897: Add basic const/static type inference r=flodiebold a=vipentti
This adds basic const/static type inference discussed in #887.
Currently the inference does not work for const/static declared inside a block. In addition the inference does not work inside the bodies of const/static.
Co-authored-by: Ville Penttinen <[email protected]>
Diffstat (limited to 'crates/ra_hir/src/code_model_impl')
-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 | } | ||