aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src/code_model_impl/konst.rs
blob: db4e5ce5cd146a99f826b63b9626ab7bddaa867c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
use std::sync::Arc;

use ra_syntax::ast::{NameOwner, TypeAscriptionOwner};

use crate::{
    Name, AsName, Const, ConstSignature, Static,
    type_ref::{TypeRef},
    DefDatabase,
};

fn const_signature_for<N: NameOwner + TypeAscriptionOwner>(node: &N) -> Arc<ConstSignature> {
    let name = node.name().map(|n| n.as_name()).unwrap_or_else(Name::missing);
    let type_ref = TypeRef::from_ast_opt(node.ascribed_type());
    let sig = ConstSignature { name, type_ref };
    Arc::new(sig)
}

impl ConstSignature {
    pub(crate) fn const_signature_query(
        db: &impl DefDatabase,
        konst: Const,
    ) -> Arc<ConstSignature> {
        let (_, node) = konst.source(db);
        const_signature_for(&*node)
    }

    pub(crate) fn static_signature_query(
        db: &impl DefDatabase,
        konst: Static,
    ) -> Arc<ConstSignature> {
        let (_, node) = konst.source(db);
        const_signature_for(&*node)
    }
}