Files
rust/crates/ra_hir/src/code_model_impl/konst.rs

38 lines
1.0 KiB
Rust
Raw Normal View History

2019-02-25 09:27:47 +02:00
use std::sync::Arc;
use ra_syntax::ast::{self, NameOwner};
2019-02-25 09:27:47 +02:00
use crate::{
2019-02-25 10:21:01 +02:00
Name, AsName, Const, ConstSignature, Static,
2019-02-25 09:27:47 +02:00
type_ref::{TypeRef},
PersistentHirDatabase,
};
fn const_signature_for<N: NameOwner>(
node: &N,
type_ref: Option<&ast::TypeRef>,
) -> Arc<ConstSignature> {
let name = node.name().map(|n| n.as_name()).unwrap_or_else(Name::missing);
let type_ref = TypeRef::from_ast_opt(type_ref);
let sig = ConstSignature { name, type_ref };
Arc::new(sig)
}
2019-02-25 09:27:47 +02:00
impl ConstSignature {
pub(crate) fn const_signature_query(
db: &impl PersistentHirDatabase,
konst: Const,
) -> Arc<ConstSignature> {
let (_, node) = konst.source(db);
const_signature_for(&*node, node.type_ref())
2019-02-25 09:27:47 +02:00
}
2019-02-25 10:21:01 +02:00
pub(crate) fn static_signature_query(
db: &impl PersistentHirDatabase,
konst: Static,
) -> Arc<ConstSignature> {
let (_, node) = konst.source(db);
const_signature_for(&*node, node.type_ref())
2019-02-25 10:21:01 +02:00
}
2019-02-25 09:27:47 +02:00
}