Files
rust/crates/ra_hir/src/code_model_impl/konst.rs
Ville Penttinen 52054e1140 Use TypeAscriptionOwner
This replaces places where we would use node + node.type_ref() with things that
have an ascribed type, with using the TypeAscriptionOwner as the trait bound so
we can simply pass the node.
2019-02-26 11:47:13 +02:00

35 lines
1000 B
Rust

use std::sync::Arc;
use ra_syntax::ast::{NameOwner, TypeAscriptionOwner};
use crate::{
Name, AsName, Const, ConstSignature, Static,
type_ref::{TypeRef},
PersistentHirDatabase,
};
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 PersistentHirDatabase,
konst: Const,
) -> Arc<ConstSignature> {
let (_, node) = konst.source(db);
const_signature_for(&*node)
}
pub(crate) fn static_signature_query(
db: &impl PersistentHirDatabase,
konst: Static,
) -> Arc<ConstSignature> {
let (_, node) = konst.source(db);
const_signature_for(&*node)
}
}